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>
This commit is contained in:
1 parent
73b86d88de
commit
2dac273b1d
12 files changed
+681
-18
No files matched your search
@@ -19,6 +19,31 @@ export const env = {
|
||||
},
|
||||
};
|
||||
|
||||
/** What .env.example ships with. Anyone who read the repository knows it. */
|
||||
export const SESSION_SECRET_PLACEHOLDER = "change-me-to-a-random-64-char-hex-string";
|
||||
|
||||
/**
|
||||
* Whether the session secret is fit to run production with. Missing is fatal (the app would fall back to a value in its own
|
||||
* source code); the placeholder from .env.example or something short is a warning, not a refusal, so an existing install
|
||||
* that has been running with one isn't locked out by an upgrade.
|
||||
*/
|
||||
export function checkSessionSecret(value: string | undefined, nodeEnv: string): { fatal?: string; warning?: string } {
|
||||
if (nodeEnv !== "production") return {};
|
||||
if (!value) {
|
||||
return {
|
||||
fatal:
|
||||
"SESSION_SECRET is not set. Sessions would be signed with a value that is public (it is in the source code). " +
|
||||
"Set it to a long random string, e.g. node -e \"console.log(require('crypto').randomBytes(32).toString('hex'))\" " +
|
||||
"(everyone is signed out when it changes).",
|
||||
};
|
||||
}
|
||||
if (value === SESSION_SECRET_PLACEHOLDER) {
|
||||
return { warning: "SESSION_SECRET is still the placeholder from .env.example, which is public. Replace it with a random value (everyone is signed out when it changes)." };
|
||||
}
|
||||
if (value.length < 32) return { warning: "SESSION_SECRET is shorter than 32 characters. Use a long random value." };
|
||||
return {};
|
||||
}
|
||||
|
||||
export function warnIfAuthNotConfigured() {
|
||||
if (!env.authEnabled) {
|
||||
console.warn(
|
||||
|
||||
Reference in new issue
Block a user