fix(audit-followup): close regressions/gaps from the persona-audit re-review
Adversarial re-review of the persona-audit commit surfaced two HIGH regressions I'd introduced plus MED/LOW gaps. All fixed: HIGH - Auth privilege escalation: reads are sessionStorage-first, but guest `setAuth` wrote only localStorage — a resident admin token shadowed a new guest login (guest ran as admin on a shared device). setAuth/setAdminAuth now DISPLACE the other store so exactly one identity is resident. Adds unit + e2e regression guards. - Host dashboard: `exportGenerating` used `||`, so a one-half export failure stuck on "wird erstellt…" forever and never showed the re-release hint. Changed to `&&`. MEDIUM - Locked-upload auto-resume was unreliable (`event-opened` has no reconnect replay and SSE is down on non-feed pages) — now also resumes on `feed-delta`, which fires on every SSE reconnect. - Queue-cap eviction could drop a recoverable locked item (parked as `error` with a live blob) — now evicts only `done`/`blocked`. - Host page async-`onMount` leaked SSE handlers if unmounted mid-load — added a `destroyed` guard before registration. LOW - An unparseable 403 body now keeps the blob (reversible) instead of purging it. - `refreshEventState` is sequence-guarded so a late close-refresh can't clobber a reopen. - `/export/status` moved out of the all-or-nothing `reload()` so its failure can't blank the whole host dashboard. Verified: svelte-check 0 errors, 36 frontend unit tests (incl. new displacement guards). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -67,6 +67,12 @@ export function getExpiry(): Date | null {
|
||||
|
||||
export function setAuth(jwt: string, pin: string | null, userId: string, displayName?: string): void {
|
||||
if (!browser) return;
|
||||
// DISPLACE any resident admin session: reads are sessionStorage-first, so a leftover
|
||||
// admin token there would otherwise shadow this guest login and hand the guest admin
|
||||
// rights on a shared device. Clear the sessionStorage identity so exactly one is resident.
|
||||
sessionStorage.removeItem(TOKEN_KEY);
|
||||
sessionStorage.removeItem(USER_ID_KEY);
|
||||
sessionStorage.removeItem(DISPLAY_NAME_KEY);
|
||||
localStorage.setItem(TOKEN_KEY, jwt);
|
||||
if (pin) {
|
||||
localStorage.setItem(PIN_KEY, pin);
|
||||
@@ -85,6 +91,12 @@ export function setAuth(jwt: string, pin: string | null, userId: string, display
|
||||
*/
|
||||
export function setAdminAuth(jwt: string, userId: string, displayName?: string): void {
|
||||
if (!browser) return;
|
||||
// DISPLACE any resident guest session so exactly one identity is resident (symmetric with
|
||||
// setAuth). Keep the guest PIN — it's deliberately preserved for later recovery, and the
|
||||
// admin has none. Reads are sessionStorage-first, so the admin token now wins cleanly.
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
localStorage.removeItem(USER_ID_KEY);
|
||||
localStorage.removeItem(DISPLAY_NAME_KEY);
|
||||
sessionStorage.setItem(TOKEN_KEY, jwt);
|
||||
sessionStorage.setItem(USER_ID_KEY, userId);
|
||||
if (displayName) sessionStorage.setItem(DISPLAY_NAME_KEY, displayName);
|
||||
|
||||
Reference in New Issue
Block a user