Skip to content

Verify auth-store write atomicity under per-request room grant reload (Low) #538

Closed

Description

@irzhywau

Severity: Low (availability; fails closed)

Found in the security review of #536.

Current behavior

Since #536, every room-session use re-reads and parses the auth state: validate_session_authority → RoomSessionAuthorization::validate → load_active_session_grant (room_service.rs / auth.rs). Grant mutation goes through store_session_grant / renew_session_grant / revoke_session_grant.

If grant writes are not atomic (temp file + rename), a poll racing a concurrent grant write can read a partial state. The fail-closed mapping then rejects the request and logs the person out spuriously.

Not yet verified whether the auth.rs grant writes are atomic.

Fix

  • Confirm (or make) grant writes atomic.
  • If needed, add a short-TTL read cache keyed by session_id that is invalidated on revoke; a cache must not delay revocation beyond a bounded, seconds-scale window.

Done means

  • A test asserts a read during a concurrent grant write never yields an unparseable state.
  • If a cache is added, revocation still takes effect within a bounded window (seconds, not minutes).

Activity

  1. andersalm commented on Nov 8, 2026

    @andersalm
    Contributor

    Verified on develop 30b166b (Cursor lane, Grok 4.7; report /private/tmp/cursor-runs/check-538.report.md). No product fault reproduced.

    • Every grant writer (store, renew, revoke) goes through mutate_auth_state (process mutex plus auth-state.json.lock) and save_auth_state → write_secret_bytes_atomic: new temp file (create_new, 0600), full write, fsync, same-directory rename, parent directory fsync (auth.rs:4669-4690, 4641-4644). The destination is never truncated in place.
    • The per-request reader (RoomSessionAuthorization::validate → load_active_session_grant) reads whole files only, detects an inode change during the read and retries (auth.rs:441-467, 4703-4713), and its cache is keyed by the content hash and dropped before and after each save (auth.rs:527-540, 4858, 4865). A missing file is "session not found"; a revoked session is "not active"; both grant no room access.
    • A concurrent test (4 reader threads on load_active_session_grant, a writer renewing, revoking and storing again, 100 loads inside each published phase) finished 14,222 loads: 204 stable loads saw the active grant, 100 saw the revoked session, zero parse errors, zero foreign session ids, zero active grants after revoke. Full cargo test -p elastos-server --tests, behaviour suite and source gate pass with it.

    The test (branch fix/538-auth-store-atomicity, 4d3de4234, local) fails if a write becomes in-place, if the cache stops checking content, or if a reload returns a grant after revoke. It goes to a cross-family review before the queue; if the review finds it timing-sensitive it will be dropped and this issue closed on the evidence above.

  2. andersalm commented on Nov 8, 2026

    @andersalm
    Contributor

    Closing on the evidence in my previous comment: writes are atomic (temp, fsync, rename), the reader detects a concurrent change and its cache is keyed by content, and a revoked or missing grant gives no room access. The 240-line concurrent test is dropped: a cross-family review (Codex, GPT) found a scheduling flaw that can fail correct code (readers can finish their quota before the writer runs), unbounded waits, and that the existing room_session_bound_checks_all_use_paths (room_service.rs) already proves the user-visible behaviour, revocation through room reads, writes and attachments. No product change.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions