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:
fabi
2026-07-13 21:19:51 +02:00
parent c647ddfa6b
commit 811c724685
6 changed files with 157 additions and 16 deletions

View File

@@ -15,6 +15,12 @@ export interface EventState {
export const eventState = writable<EventState>({ uploadsLocked: false, galleryReleased: false });
// Monotonic sequence bumped by every synchronous state transition (markClosed/markOpened).
// `refreshEventState` captures it before its async fetch and only applies the result if no
// newer transition happened meanwhile — so a slow `/me/context` reflecting a pre-reopen
// snapshot can't clobber a subsequent `event-opened` with stale `locked=true`.
let stateSeq = 0;
/** True when uploads are closed for any reason (event locked or gallery released). */
export function uploadsClosed(s: EventState): boolean {
return s.uploadsLocked || s.galleryReleased;
@@ -22,8 +28,12 @@ export function uploadsClosed(s: EventState): boolean {
/** Refresh from the server. Non-fatal on failure — the next SSE event reconciles. */
export async function refreshEventState(): Promise<void> {
const seq = stateSeq;
try {
const ctx = await api.get<MeContextDto>('/me/context');
// A close/reopen landed while this was in flight — its result is now authoritative;
// don't overwrite it with our possibly-stale snapshot.
if (seq !== stateSeq) return;
eventState.set({
uploadsLocked: ctx.uploads_locked,
galleryReleased: ctx.gallery_released
@@ -35,10 +45,12 @@ export async function refreshEventState(): Promise<void> {
/** Apply an `event-closed` SSE event (uploads just locked). */
export function markClosed(): void {
stateSeq++;
eventState.update((s) => ({ ...s, uploadsLocked: true }));
}
/** Apply an `event-opened` SSE event (uploads reopened → release also cleared). */
export function markOpened(): void {
stateSeq++;
eventState.set({ uploadsLocked: false, galleryReleased: false });
}