mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
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>
This commit is contained in:
1 parent
b6786f7ac8
commit
9e5dedfc20
1 file changed
+39
-22
@@ -250,25 +250,33 @@ export function createOIDCRouter(
|
||||
// only that identifier goes in the cookie. id_tokens can be large and
|
||||
// storing one directly in the cookie inflates response headers enough
|
||||
// to exceed reverse proxy buffers, resulting in a 502 on sign-in.
|
||||
// This is best-effort: a Redis failure must not block sign-in, the
|
||||
// logout simply falls back to omitting the `id_token_hint`.
|
||||
if (endpoints.logoutURL && params.id_token) {
|
||||
const sessionId = crypto.randomBytes(16).toString("hex");
|
||||
await Redis.defaultClient.set(
|
||||
RedisPrefixHelper.getLogoutTokenKey(sessionId),
|
||||
params.id_token,
|
||||
"EX",
|
||||
OIDC_LOGOUT_TOKEN_TTL_SECONDS
|
||||
);
|
||||
context.cookies.set(OIDC_SESSION_COOKIE, sessionId, {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: env.isProduction,
|
||||
path: OIDC_LOGOUT_PATH,
|
||||
domain: getCookieDomain(
|
||||
context.request.hostname,
|
||||
env.isCloudHosted
|
||||
),
|
||||
expires: addSeconds(new Date(), OIDC_LOGOUT_TOKEN_TTL_SECONDS),
|
||||
});
|
||||
try {
|
||||
const sessionId = crypto.randomBytes(16).toString("hex");
|
||||
await Redis.defaultClient.set(
|
||||
RedisPrefixHelper.getLogoutTokenKey(sessionId),
|
||||
params.id_token,
|
||||
"EX",
|
||||
OIDC_LOGOUT_TOKEN_TTL_SECONDS
|
||||
);
|
||||
context.cookies.set(OIDC_SESSION_COOKIE, sessionId, {
|
||||
httpOnly: true,
|
||||
sameSite: "lax",
|
||||
secure: env.isProduction,
|
||||
path: OIDC_LOGOUT_PATH,
|
||||
domain: getCookieDomain(
|
||||
context.request.hostname,
|
||||
env.isCloudHosted
|
||||
),
|
||||
expires: addSeconds(new Date(), OIDC_LOGOUT_TOKEN_TTL_SECONDS),
|
||||
});
|
||||
} catch (err) {
|
||||
Logger.warn("Failed to persist OIDC logout token hint", {
|
||||
error: toError(err).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return done(null, result.user, { ...result, client });
|
||||
@@ -290,11 +298,20 @@ export function createOIDCRouter(
|
||||
// https://openid.net/specs/openid-connect-rpinitiated-1_0.html
|
||||
router.get(`${config.id}.logout`, async (ctx: Context) => {
|
||||
const sessionId = ctx.cookies.get(OIDC_SESSION_COOKIE);
|
||||
const idToken = sessionId
|
||||
? await Redis.defaultClient.getdel(
|
||||
// Best-effort: a Redis failure falls back to omitting the `id_token_hint`
|
||||
// rather than blocking logout.
|
||||
let idToken: string | null = null;
|
||||
if (sessionId) {
|
||||
try {
|
||||
idToken = await Redis.defaultClient.getdel(
|
||||
RedisPrefixHelper.getLogoutTokenKey(sessionId)
|
||||
)
|
||||
: null;
|
||||
);
|
||||
} catch (err) {
|
||||
Logger.warn("Failed to read OIDC logout token hint", {
|
||||
error: toError(err).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Always discard our session identifier, regardless of where we redirect.
|
||||
ctx.cookies.set(OIDC_SESSION_COOKIE, "", {
|
||||
|
||||
Reference in new issue
Block a user