[grade=B] fix(auth): reuse valid session for cross-host SSO
CI / Test & Lint (push) Canceled after 0s
CI / Security audit (push) Canceled after 0s

This commit is contained in:
Hermes
2026-08-22 04:06:27 -07:00
parent 499fcc2742
commit d313b1e872
6 changed files with 221 additions and 84 deletions
+15 -1
View File
@@ -203,8 +203,22 @@ module.exports = function(deps) {
}
}, 'auth-app-token'));
// A browser that already has a valid status.sami session must not be asked
// for TOTP again just because it opened another private-TLD service host.
// Mint a fresh one-time token that the target host can exchange for its own
// host-only cookie. This route is intentionally session-protected both by
// the global middleware and here (defence in depth).
router.get('/auth/sso-handoff', (req, res) => {
res.setHeader('Cache-Control', 'no-store');
if (!session.isValid(req)) {
return errorResponse(res, 401, 'Session expired or invalid');
}
ok(res, { ssoToken: session.createHandoffToken() });
});
// Cross-subdomain SSO handoff: exchanges a short-lived single-use token
// (minted by /totp/verify) for a HOST-ONLY session cookie on whichever
// (minted by /totp/verify or /auth/sso-handoff) for a HOST-ONLY session
// cookie on whichever
// *.sami origin calls this. Needed because Domain=.sami cookies are
// silently rejected by real browsers (.sami is an unregistered TLD, so
// browsers treat "sami" as the effective public suffix and refuse to set