Files
paperlessmanager/paperless-backend/src/auth/api-keys.controller.ts
T
bjoernpoettkerandClaude Opus 5.5 bb8bf3714f fix(security): API-Keys nur für Admins, Mailversand ohne Datei-/URL-Zugriff
- ApiKeysController verlangt MANAGE_SETTINGS. Bisher konnte jeder
  OIDC-Benutzer einen API-Key erzeugen, der im PermissionsGuard jede
  Rechteprüfung umgeht (Rechteausweitung zum Admin).
- MailService setzt disableFileAccess/disableUrlAccess für jede Mail.
- send-email im Posteingang prüft den Body streng auf Strings/Zahlen.
  Bisher liest nodemailer bei html: { path: '/proc/self/environ' }
  beliebige Serverdateien ein und verschickt sie.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 10:46:43 +01:00

40 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
Controller,
Get,
Post,
Delete,
Body,
Param,
UseGuards,
} from '@nestjs/common';
import { ApiKeysService } from './api-keys.service';
import { JwtAuthGuard } from './jwt-auth.guard';
import { RequirePermissions } from './permissions.decorator';
import { Permission } from './permissions.enum';
@Controller('api/api-keys')
@UseGuards(JwtAuthGuard)
// Ein API-Key umgeht im PermissionsGuard jede Rechteprüfung – Anlegen und
// Verwalten darf daher nur, wer ohnehin alle Einstellungen verwalten darf.
@RequirePermissions(Permission.MANAGE_SETTINGS)
export class ApiKeysController {
constructor(private readonly apiKeysService: ApiKeysService) {}
@Post()
async create(@Body() body: { name: string; expiresDays?: number }) {
// Note: The plainKey is only returned here once.
return this.apiKeysService.createApiKey(body.name, body.expiresDays);
}
@Get()
async findAll() {
// Note: This returns hashed keys and prefixes, not the plain keys.
return this.apiKeysService.listKeys();
}
@Delete(':id')
async remove(@Param('id') id: string) {
return this.apiKeysService.deleteKey(id);
}
}