Files
outline/plugins/oidc/server/auth/oidc.test.ts
T
Tom MoorandClaude Opus 4.8 b6786f7ac8 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>
2026-07-13 18:29:05 -04:00

66 lines
2.2 KiB
TypeScript

import Redis from "@server/storage/redis";
import { RedisPrefixHelper } from "@server/utils/RedisPrefixHelper";
import { getTestServer } from "@server/test/support";
const server = getTestServer();
describe("oidc", () => {
it("should pass query params along with auth redirect", async () => {
const res = await server.get("/auth/oidc?myParam=someParam", {
redirect: "manual",
});
expect(res.headers.get("location")).not.toBeNull();
const redirectLocation = new URL(res.headers.get("location")!);
expect(res.status).toEqual(302);
expect(redirectLocation.searchParams.get("myParam")).toEqual("someParam");
});
describe("logout", () => {
it("should redirect to the provider with a spec-compliant logout request", async () => {
const res = await server.get("/auth/oidc.logout", {
redirect: "manual",
});
expect(res.status).toEqual(302);
const redirectLocation = new URL(res.headers.get("location")!);
expect(redirectLocation.origin + redirectLocation.pathname).toEqual(
"http://localhost/logout"
);
expect(redirectLocation.searchParams.get("client_id")).toEqual(
"client-id"
);
expect(
redirectLocation.searchParams.get("post_logout_redirect_uri")
).toEqual("http://localhost:3000");
});
it("should include the id_token_hint when present", async () => {
const sessionId = "test-session-id";
await Redis.defaultClient.set(
RedisPrefixHelper.getLogoutTokenKey(sessionId),
"fake-id-token"
);
const res = await server.get("/auth/oidc.logout", {
redirect: "manual",
headers: {
Cookie: `oidcSession=${sessionId}`,
},
});
expect(res.status).toEqual(302);
const redirectLocation = new URL(res.headers.get("location")!);
expect(redirectLocation.searchParams.get("id_token_hint")).toEqual(
"fake-id-token"
);
expect(res.headers.get("set-cookie")).toContain(
"oidcSession=; path=/auth/oidc.logout;"
);
// The token is consumed from the server-side store on logout.
expect(
await Redis.defaultClient.get(
RedisPrefixHelper.getLogoutTokenKey(sessionId)
)
).toBeNull();
});
});
});