Files
Homelab-manager/server/package.json
T
bobbanandClaude Sonnet 5.5 2dac273b1d Harden the login flow: new session at sign-in, signed ID tokens, same-origin requests, headers
From an audit of the Authentik login, run against a fake OIDC provider:

- Session fixation: the session id wasn't changed at sign-in, so one planted beforehand
  (from another page on the domain) became signed in as the victim. It is regenerated now.
- Requests from another origin: SameSite=Lax doesn't stop another app on the same parent
  domain, and a body-less POST (stop a guest, rotate a token) needs no preflight. Every
  POST/PUT/PATCH/DELETE, and GET /auth/logout, is refused when Sec-Fetch-Site (or, for older
  browsers, Origin) says it came from elsewhere. The agent endpoint is exempt: it uses a token.
- ID token signature: openid-client checks a token's claims but, as OIDC allows for a token
  from the token endpoint, not its signature, so the login rested on HTTPS to Authentik
  alone. The signature is now verified against the provider's published keys (jose, now a
  declared dependency).
- SESSION_SECRET: production refuses to start without one (the fallback is in the source
  code) and warns when it is the .env.example placeholder or short.
- Response headers: frame-ancestors 'none', X-Frame-Options, nosniff, Referrer-Policy; the
  framework name is no longer sent.
- A failed sign-in shows a plain page and is audited (session / login_failed, with address
  and reason, no tokens); sign-in is limited to 20 attempts a minute per address so the
  audit log and session store can't be flooded.
- A failed OIDC discovery (provider down at the first sign-in) was remembered until restart;
  it is retried now.

Tests run the real app against the fake provider; switching each fix off in turn makes
the matching tests fail.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-06 23:35:34 +02:00

42 lines
1.1 KiB
JSON

{
"name": "server",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc -p tsconfig.json",
"start": "node dist/index.js",
"test": "tsx --test \"test/**/*.test.ts\"",
"db:generate": "drizzle-kit generate",
"db:migrate": "tsx src/db/migrate.ts"
},
"dependencies": {
"@libsql/client": "^0.14.0",
"dotenv": "^16.4.5",
"drizzle-orm": "^0.45.2",
"express": "^4.21.2",
"express-session": "^1.18.1",
"jose": "^6.2.12",
"mysql2": "^3.24.5",
"node-schedule": "^2.1.1",
"nodemailer": "^6.9.14",
"openid-client": "^6.1.7",
"session-file-store": "^1.5.0",
"xml2js": "^0.6.2",
"zod": "^3.24.1"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/express-session": "^1.18.1",
"@types/node": "^22.10.5",
"@types/node-schedule": "^2.1.7",
"@types/nodemailer": "^6.4.17",
"@types/session-file-store": "^1.2.5",
"@types/xml2js": "^0.4.14",
"drizzle-kit": "^0.31.10",
"tsx": "^4.19.2",
"typescript": "^5.7.3"
}
}