Files
Kelx/utils/session-invalidation-warnings.js
T
2026-11-30 16:32:37 +00:00

53 lines
2.7 KiB
JavaScript

"use strict";
// adpanel:session-inventory-error-propagation — ONE home for the
// client-facing sessionInvalidationWarnings that every eviction-surfacing
// response renders from a destroyBrowserSessionsForUser result. The former
// per-route copies passed `sessionInvalidation.errors` through verbatim,
// which silently DROPPED the destroyer's additive `scanIncomplete: true`
// flag whenever the degraded scan happened to produce no error strings —
// the client saw a clean success while the sign-out sweep was unverified.
// The renderer keeps every error string, appends ONE truthful note when the
// inventory was degraded, and never throws on a malformed result (warnings
// are additive context on an already-successful response, never a new
// failure mode).
//
// The two notes are deliberately DIFFERENT because their truths differ:
// - every credential-change writer commits the new session_epoch IN the
// credential's own UPDATE (adpanel:credential-generation), so a session
// the sweep missed fails the binding check on its next use (the ONE
// shared predicate, utils/session-account-binding.js — HTTP session
// middleware, remember restore, login re-proof, Socket.IO handshake and
// the 30s socket liveness "account-binding-stale" verdict);
// - suspension advances the session generation without changing password
// or TOTP material; its own note covers both the suspended state and the
// revoked generation so it stays true after later unsuspension.
// No caller may inline these strings or fork this rendering: the exact
// wording and the single-home rule are pinned by
// tests/credential-reset-eviction-surfacing.test.js.
const CREDENTIAL_SCAN_INCOMPLETE_NOTE =
"the session inventory scan was incomplete; any sessions the sign-out sweep missed are invalidated on their next request because the account's credential generation changed";
const SUSPENSION_SCAN_INCOMPLETE_NOTE =
"the session inventory scan was incomplete; any sessions the sign-out sweep missed are signed out by the suspended state or revoked session generation on their next request";
function renderSessionInvalidationWarnings(sessionInvalidation, options = {}) {
const errors = sessionInvalidation && Array.isArray(sessionInvalidation.errors)
? sessionInvalidation.errors
: [];
const warnings = errors
.map((entry) => String(entry == null ? "" : entry))
.filter((entry) => entry.length > 0);
if (sessionInvalidation && sessionInvalidation.scanIncomplete === true) {
warnings.push(String(options.scanIncompleteNote || CREDENTIAL_SCAN_INCOMPLETE_NOTE));
}
return warnings;
}
module.exports = {
renderSessionInvalidationWarnings,
CREDENTIAL_SCAN_INCOMPLETE_NOTE,
SUSPENSION_SCAN_INCOMPLETE_NOTE,
};