Skip to content

ui-server: profile, push-subscribe and storage-notice writes check login expiry against a time stamped before the writer wait #4176

Closed

Description

@schlessera

Context

Found while auditing ui-server for #4169. It is the same bug class as #4169 and the second review finding on #4168: an authority check inside a write-worker procedure compares a login's expiry against a time the caller stamped before it waited for the writer. Any time spent queued behind other writes falls outside the check, so a login that expires while the request waits still passes. Revocation is unaffected in each case, because it is read from the row inside the transaction.

Three sites, observed from the code only (no reproduction run yet):

  1. Session worker-profile writes. save and bind stamp Date.now() on the app side and submit it to the writer (submit("save", …), packages/ui-server/src/ws/session-profiles.ts:93; write(sessionId, { bind: … }, "bind", …), packages/ui-server/src/ws/session-profiles.ts:111). Inside the transaction, saveProfile and bindDraftProfile call authorizeProfile(db, principalId, now) with that stamp (bindDraftProfile, packages/ui-server/src/ws/session-profile-writes.ts:32-34; saveProfile, packages/ui-server/src/ws/session-profile-writes.ts:56-59).
  2. Push subscription binding. subscribe stamps Date.now() (subscribe, packages/ui-server/src/activity/push-sender.ts:213) and the worker's INSERT … SELECT … WHERE expires_at > ? checks the target login against it (subscribe, packages/ui-server/src/activity/push-writes.ts:21-28). A login that expired while queued can still bind a device.
  3. Storage notice dispatch. deliverStorage calls notices.begin(sub.endpoint, at ?? Date.now()) (deliverStorage, packages/ui-server/src/activity/push-sender.ts:307-316), and the worker's begin decides the recipient with owner(sub.principal_id, now) against that stamp (begin, packages/ui-server/src/storage/notify-writes.ts:41-58).

#4169 fixed the reference-grant case by reading the clock at the check inside the writer transaction and keeping the stamp for recorded timestamps and retention.

Scope

At each of the three sites, check principal usability against the clock read at the check inside the writer transaction. Keep the stamped time wherever it records a timestamp (updated_at, created_at, receipt times), drives retention or cleanup, or orders time (the storage notifier's reversed-clock guard and its eligibility windows).

Out of scope

Reference grants (#4169), chat deletion (#4168), safety reviews (they already read the clock inside their transaction), checks run synchronously before any await (route guards, authGuard), and any change to profile, push or storage-notice semantics.

Acceptance criteria

  • At each of the three sites, a login that is usable when the request is stamped but expires before the writer runs is refused (profile writes: SessionProfileError 401; subscribe: returns false and binds nothing; storage notice: begin returns null and records no attempt). Each is proven by a real-SQLite test that holds the writer and fails before the change.
  • Recorded timestamps and retention still use the stamped time, proven by the same tests or by existing ones.

Verification

Run each failing-first held-writer test. A mutation back to the stamp must fail it. packages/ui-server/tests/reference-grants.test.ts ("reference grant creation behind a held writer") shows the held-writer pattern.

Contract impact

None: no shape changes. A request that previously succeeded on an expired login is now refused.

Activity

  1. added
    type: fix
    area: ui-server
    security
    priority: p2
    agent-ready
    on Nov 17, 2026
  2. added this to the 0.45.0 milestone on Nov 17, 2026
  3. schlessera commented on Nov 17, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-11-17): priority: p2, in 0.45.0.

  4. self-assigned this
    on Nov 17, 2026
  5. schlessera commented on Nov 17, 2026

    @schlessera
    OwnerAuthor

    Claimed for implementation. Claim token: claim-7bdbda1a. Branch: fix/4176-writer-clock-expiry.

    collisions: closure-only overlaps with open ui-server PRs (incl. #4177, same bug class); no path collisions

  6. schlessera commented on Nov 17, 2026

    @schlessera
    OwnerAuthor

    Merged in #4181 as 1cd5fd474 through the integration lease (orchestrator merge queue for 0.45.0). Candidate confirmation passed on the exact head; the squash's own main run carries the post-merge heavy categories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: ui-serverpriority: p2securitytype: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions