Skip to content

ui-server: reference-grant creation checks login expiry against a time stamped before the writer wait #4169

Closed

Description

@schlessera

Context

Found while answering the independent review of #4168 (refs #4138). It is the same bug class as that review's second finding: an authorization check that compares a login's expiry against a time stamped before an asynchronous wait.

POST /api/auth/principals/:id/reference-grants stamps now: Date.now() when it builds the call (createGrant, packages/ui-server/src/middleware/principals.ts:244-252). It then awaits the write worker. Inside the worker's transaction, createReferenceGrant checks the target and the creating owner with isUsablePrincipal(…, input.now) (isUsablePrincipal(target, input.now), packages/ui-server/src/db/reference-grants.ts:138-139). Any time spent queued behind other writes therefore falls outside the expiry check. A target or creator login that expires while the request waits still passes. Revocation is unaffected, because it is read from the row inside the transaction. Grant revocation takes the same now: Date.now() stamp (principals.ts:281); whether its use of that time is an authority check needs reading.

Observed from the code only: no reproduction has been run. The analogous deletion case was reproduced and fixed in #4168, with a held-writer test in packages/ui-server/tests/chat-lifecycle.test.ts.

Scope

Check principal usability for reference-grant creation (and revocation, if it is an authority check there) against the clock at the check inside the writer transaction. Keep input.now for recorded timestamps and retention.

Out of scope

Other isUsablePrincipal callers (safety reviews already read the clock inside their transaction), grant semantics, limits and retention.

Acceptance criteria

  • A creating owner or target login that is usable when the request is stamped but expires before the writer commits is refused (ReferenceGrantPrincipalError). This is proven by a real-SQLite test that holds the writer and fails before the change.
  • The stamped time still records createdAt and drives retention exactly as before.

Verification

Run the failing-first held-writer test. A mutation back to input.now must fail it.

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-cafb11c7. Branch: fix/4169-grant-expiry-clock.

    Path collision with draft #4002 (reference-grants.ts); closure-only with #3622, #4167, #4168 and others.

  6. schlessera commented on Nov 17, 2026

    @schlessera
    OwnerAuthor

    Merged in #4177 as 18da31bc6 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