mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
* fix: OIDC 502 on sign-in from oversized id_token cookie (#12986) Storing the full OIDC id_token in the `oidcIdToken` cookie inflated the sign-in response headers enough to exceed reverse proxy buffers, causing a 502 Bad Gateway. Store the id_token server-side in Redis keyed by a short session identifier and keep only that identifier in the cookie, preserving spec-compliant RP-initiated logout via `id_token_hint`. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix: Make OIDC logout token persistence best-effort A Redis failure when storing or reading the logout id_token_hint should not block sign-in or logout; fall back to omitting the hint instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * docs * refactor: Extract portable LogoutTokenStore for provider logout hints Move the cookie-referenced, Redis-backed logout token persistence out of the OIDC router into a provider-agnostic `LogoutTokenStore`. Any auth provider that supports provider-initiated logout can now persist and consume a logout hint via `new LogoutTokenStore(providerId)` without duplicating the cookie/Redis/error handling. The OIDC-specific end-session URL construction stays in the router. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import type { Context } from "koa";
|
|
import Redis from "@server/storage/redis";
|
|
import { LogoutTokenStore } from "./LogoutTokenStore";
|
|
import { RedisPrefixHelper } from "./RedisPrefixHelper";
|
|
|
|
/**
|
|
* Minimal Koa context stub exposing only the cookie jar and hostname the store
|
|
* relies on.
|
|
*/
|
|
function buildContext(cookies: Record<string, string> = {}) {
|
|
const jar = new Map(Object.entries(cookies));
|
|
return {
|
|
request: { hostname: "localhost" },
|
|
cookies: {
|
|
get: (name: string) => jar.get(name),
|
|
set: (name: string, value: string) => {
|
|
if (value) {
|
|
jar.set(name, value);
|
|
} else {
|
|
jar.delete(name);
|
|
}
|
|
},
|
|
},
|
|
} as unknown as Context;
|
|
}
|
|
|
|
describe("LogoutTokenStore", () => {
|
|
const store = new LogoutTokenStore("oidc");
|
|
|
|
it("persists a token behind a session cookie and consumes it once", async () => {
|
|
const signInCtx = buildContext();
|
|
await store.persist(signInCtx, "the-token");
|
|
|
|
const sessionId = signInCtx.cookies.get("oidcSession");
|
|
expect(sessionId).toBeTruthy();
|
|
expect(
|
|
await Redis.defaultClient.get(
|
|
RedisPrefixHelper.getLogoutTokenKey("oidc", sessionId!)
|
|
)
|
|
).toEqual("the-token");
|
|
|
|
const logoutCtx = buildContext({ oidcSession: sessionId! });
|
|
expect(await store.consume(logoutCtx)).toEqual("the-token");
|
|
|
|
// Consuming clears both the cookie and the server-side token.
|
|
expect(logoutCtx.cookies.get("oidcSession")).toBeUndefined();
|
|
expect(
|
|
await Redis.defaultClient.get(
|
|
RedisPrefixHelper.getLogoutTokenKey("oidc", sessionId!)
|
|
)
|
|
).toBeNull();
|
|
});
|
|
|
|
it("returns null when there is no session cookie", async () => {
|
|
expect(await store.consume(buildContext())).toBeNull();
|
|
});
|
|
|
|
it("namespaces the cookie and key by provider", async () => {
|
|
const samlStore = new LogoutTokenStore("saml");
|
|
const ctx = buildContext();
|
|
await samlStore.persist(ctx, "saml-token");
|
|
|
|
const sessionId = ctx.cookies.get("samlSession");
|
|
expect(sessionId).toBeTruthy();
|
|
expect(ctx.cookies.get("oidcSession")).toBeUndefined();
|
|
expect(
|
|
await Redis.defaultClient.get(
|
|
RedisPrefixHelper.getLogoutTokenKey("saml", sessionId!)
|
|
)
|
|
).toEqual("saml-token");
|
|
});
|
|
});
|