harden(modules): Payload-Grenze + Modul-ID-Prüfung nach Sicherheits-Review (v1.5.7)

Unabhängige Security-Review bestätigte: keine Autorisierungs-/Mandanten-Lücken
(Tenant-Isolation via getProjectWithTenantCheck, VIEWER-Schreibsperre, keine
Injection). Zwei Härtungspunkte umgesetzt:

- module_items data-Payload auf 20 KB pro Zeile begrenzt (POST+PUT) → kein
  DB-Bloat/DoS durch beliebig grosse JSON-Objekte
- moduleId-Länge auf 64 Zeichen begrenzt (verhindert pathologische Keys)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Pepe Ziberi
2026-07-22 19:55:01 +02:00
parent e02ea21c93
commit a4d0a10794
3 changed files with 14 additions and 2 deletions

View File

@@ -25,9 +25,15 @@ export async function PUT(
const body = await request.json()
const patch = body && typeof body.data === 'object' && body.data !== null ? body.data : {}
const merged = { ...(existing.data || {}), ...patch }
// Payload-Härtung: Zeilengrösse begrenzen (DB-Bloat/DoS vermeiden)
if (JSON.stringify(merged).length > 20000) {
return NextResponse.json({ error: 'Eintrag zu gross' }, { status: 413 })
}
const item = await (prisma as any).moduleItem.update({
where: { id: itemId },
data: { data: { ...(existing.data || {}), ...patch } },
data: { data: merged },
})
return NextResponse.json(item)
} catch (error) {

View File

@@ -38,11 +38,17 @@ export async function POST(
if (!user) return NextResponse.json({ error: 'Nicht autorisiert' }, { status: 401 })
if (user.role === 'VIEWER') return NextResponse.json({ error: 'Keine Berechtigung' }, { status: 403 })
if (moduleId.length > 64) return NextResponse.json({ error: 'Ungültige Modul-ID' }, { status: 400 })
const project = await getProjectWithTenantCheck(id, user)
if (!project) return NextResponse.json({ error: 'Projekt nicht gefunden' }, { status: 404 })
const body = await request.json()
const data = body && typeof body.data === 'object' && body.data !== null ? body.data : {}
// Payload-Härtung: eine Tabellenzeile bleibt klein — verhindert DB-Bloat/DoS
if (JSON.stringify(data).length > 20000) {
return NextResponse.json({ error: 'Eintrag zu gross' }, { status: 413 })
}
const count = await (prisma as any).moduleItem.count({ where: { projectId: id, moduleId } })
const item = await (prisma as any).moduleItem.create({