From afd8019a7bce5dd141c24685dacb788e0f9b918e Mon Sep 17 00:00:00 2001 From: Grovy311 Date: Thu, 15 Oct 2026 09:45:59 +0200 Subject: [PATCH] Address security review notes - log only the error name for rejected 4xx requests (JSON.parse messages can quote the request body, e.g. a password) - refuse LB_DATABASE_PATH in production; it is test-only - fix two stale file references in the skill texts Co-Authored-By: Claude Opus 5.5 --- .agents/skills/authz-idor-audit/SKILL.md | 2 +- .agents/skills/codeguard/HERKUNFT.md | 2 +- .claude/skills/authz-idor-audit/SKILL.md | 2 +- .claude/skills/codeguard/HERKUNFT.md | 2 +- src/db/client.ts | 11 ++++++++--- src/server/middleware/error.middleware.ts | 4 +++- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.agents/skills/authz-idor-audit/SKILL.md b/.agents/skills/authz-idor-audit/SKILL.md index ffa1d9f..d04eb05 100644 --- a/.agents/skills/authz-idor-audit/SKILL.md +++ b/.agents/skills/authz-idor-audit/SKILL.md @@ -21,7 +21,7 @@ fremde Objekte“ (IDOR). Dieser Skill macht die Rechte explizit und testbar. ### 1. Routen und Rollen erfassen - Alle Routen auflisten: FastAPI aus `app.openapi()["paths"]` (nicht aus `app.routes`, eingebundene Router fehlen dort je nach Version), Express aus dem Routen-Inventar der - Baseline (`tests/security/routes.ts`) oder per `grep -rn "router\.\(get\|post\|put\|patch\|delete\)"`. + Baseline (`tests/security/route-inventory.ts`) oder per `grep -rn "router\.\(get\|post\|put\|patch\|delete\)"`. - Rollen und Identitätsquelle aus dem Code ermitteln (Session, JWT, Proxy-Header, OIDC-Claims). ### 2. Rollenmatrix aufstellen diff --git a/.agents/skills/codeguard/HERKUNFT.md b/.agents/skills/codeguard/HERKUNFT.md index 3e5551b..49e6b05 100644 --- a/.agents/skills/codeguard/HERKUNFT.md +++ b/.agents/skills/codeguard/HERKUNFT.md @@ -1,4 +1,4 @@ # Herkunft Project CodeGuard v1.5.0, https://github.com/cosai-oasis/project-codeguard -Lizenz: CC BY 4.0 (siehe LICENSE.md). Aktualisieren mit scripts/update-codeguard.ps1, nicht von Hand aendern. +Lizenz: CC BY 4.0 (siehe LICENSE.md). Aktualisieren mit scripts/update-codeguard.ps1 im Repo cj/claude-skills, nicht von Hand aendern. diff --git a/.claude/skills/authz-idor-audit/SKILL.md b/.claude/skills/authz-idor-audit/SKILL.md index ffa1d9f..d04eb05 100644 --- a/.claude/skills/authz-idor-audit/SKILL.md +++ b/.claude/skills/authz-idor-audit/SKILL.md @@ -21,7 +21,7 @@ fremde Objekte“ (IDOR). Dieser Skill macht die Rechte explizit und testbar. ### 1. Routen und Rollen erfassen - Alle Routen auflisten: FastAPI aus `app.openapi()["paths"]` (nicht aus `app.routes`, eingebundene Router fehlen dort je nach Version), Express aus dem Routen-Inventar der - Baseline (`tests/security/routes.ts`) oder per `grep -rn "router\.\(get\|post\|put\|patch\|delete\)"`. + Baseline (`tests/security/route-inventory.ts`) oder per `grep -rn "router\.\(get\|post\|put\|patch\|delete\)"`. - Rollen und Identitätsquelle aus dem Code ermitteln (Session, JWT, Proxy-Header, OIDC-Claims). ### 2. Rollenmatrix aufstellen diff --git a/.claude/skills/codeguard/HERKUNFT.md b/.claude/skills/codeguard/HERKUNFT.md index 3e5551b..49e6b05 100644 --- a/.claude/skills/codeguard/HERKUNFT.md +++ b/.claude/skills/codeguard/HERKUNFT.md @@ -1,4 +1,4 @@ # Herkunft Project CodeGuard v1.5.0, https://github.com/cosai-oasis/project-codeguard -Lizenz: CC BY 4.0 (siehe LICENSE.md). Aktualisieren mit scripts/update-codeguard.ps1, nicht von Hand aendern. +Lizenz: CC BY 4.0 (siehe LICENSE.md). Aktualisieren mit scripts/update-codeguard.ps1 im Repo cj/claude-skills, nicht von Hand aendern. diff --git a/src/db/client.ts b/src/db/client.ts index 95a085a..6bb8d05 100644 --- a/src/db/client.ts +++ b/src/db/client.ts @@ -1,10 +1,15 @@ import path from "node:path"; import { createDatabaseContext } from "./database-context.js"; -// LB_DATABASE_PATH ist nur fuer Tests gedacht (z. B. ":memory:" in tests/security); -// der Betrieb nutzt weiterhin data/leistungsbilanz.db. +// LB_DATABASE_PATH ist nur fuer Tests gedacht (z. B. ":memory:" in tests/security). +// Migrationen, Backup und Schema-Pruefung nutzen fest data/leistungsbilanz.db, deshalb +// ist die Variable in Produktion verboten. +const testDatabasePath = process.env.LB_DATABASE_PATH; +if (testDatabasePath && process.env.NODE_ENV === "production") { + throw new Error("LB_DATABASE_PATH is test-only and must not be set in production."); +} const defaultDatabaseContext = createDatabaseContext( - process.env.LB_DATABASE_PATH || path.resolve("data", "leistungsbilanz.db") + testDatabasePath || path.resolve("data", "leistungsbilanz.db") ); export const db = defaultDatabaseContext.db; diff --git a/src/server/middleware/error.middleware.ts b/src/server/middleware/error.middleware.ts index a586ac6..c31adb8 100644 --- a/src/server/middleware/error.middleware.ts +++ b/src/server/middleware/error.middleware.ts @@ -24,11 +24,13 @@ export function errorMiddleware( ) { const status = clientErrorStatus(error); if (status !== undefined) { + // No error message here: JSON.parse messages can quote parts of the body + // (for example a password from a malformed login request). logger.warn("request rejected", { method: req.method, path: req.originalUrl, status, - ...toErrorMeta(error), + errorName: error instanceof Error ? error.name : typeof error, }); res.status(status).json({ error: "Ungültige Anfrage." }); return;