Skip to content

ui-server: inbox snapshot restore writes staging by pathname after a one-time link check #3476

Closed

Description

@schlessera

Context

Found while auditing the staging no-follow boundary for #2907. That change moves staging, intake compensation and reconciliation, inbox cleanup and the TTL prune onto descriptors opened without following links (openStagingRoot, packages/ui-server/src/share/staging-fs.ts). The operator restore of an inbox snapshot still writes into the staging directory by pathname, after a one-time link check:

  • The restore checks the staging root and .brain-ui with realpath once (async function stagingRoot, packages/ui-server/src/inbox/snapshot.ts:235). Then it creates directories, removes leftover temporaries and publishes files by joined paths (await mkdir(root, { recursive: true, mode: 0o700 });, packages/ui-server/src/inbox/snapshot.ts:384; await rm(join(path, name));, packages/ui-server/src/inbox/snapshot.ts:397; try { await publish(path, bytes, false); }, packages/ui-server/src/inbox/snapshot.ts:404).
  • Each per-directory check (realpath(path) !== path) is followed by separate pathname system calls. A link swapped in between them is followed. That is the same check-then-act class ui-server: inbox intake reconciliation and staging follow links where cleanup and prune refuse them #2907 closes for intake.

This restore runs from the operator's recovery command, not from an intake route, so it was outside #2907's staging/intake scope.

Scope

Move the restore's staging mutations (directory creation, temporary reaping, file publication and the parent directory sync) onto the descriptor-anchored, no-follow helpers from #2907, or an equivalent O_NOFOLLOW chain. A link that appears on the way, at check time or in between, must refuse the restore rather than be followed. Keep the existing refusal codes (inbox_staging_symlink, inbox_restore_staging_changed).

Out of scope

Acceptance criteria

  • A real-filesystem restore where .brain-ui/inbox, or one restored arrival directory, is swapped for a link while the restore runs refuses with the existing code. The link's target keeps its bytes and gains no new entries.
  • The existing snapshot/restore tests keep their assertions, including resumable restore and the no-clobber publication.
  • Each repaired boundary has a failing-first receipt and a restored-mutation receipt.

Verification

packages/ui-server/tests/inbox-snapshot.test.ts and related restore tests, then bun run check:pr --base origin/main.

Contract impact

None expected: the restore's refusal envelopes stay the same.

Activity

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

    @schlessera
    OwnerAuthor

    Triage 2026-11-03: p1 (same check-then-act link-following class as p0 #2907, reached only from the operator's restore command), milestone 0.45.0. The scope reuses the no-follow helpers that #2907 introduces in PR #3477, so this waits for that merge.

    Blocked by #2907

  4. removed
    blocked
    on Nov 3, 2026
  5. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Blocker #2907 closed: #3477 merged to main as 23dae2625 with the no-follow staging helpers. Removing blocked.

  6. self-assigned this
    on Nov 3, 2026
  7. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claimed (token claim-3476-t3-277f), branch fix/3476-inbox-restore-staging-fs from a272a790b. Collision check on the cited files: no path collisions; only test-closure overlaps (several open PRs whose affected tests include inbox-snapshot.test.ts).

  8. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Draft PR #3500 (head ec2bd96d2): the restore's staging now goes through the #2907 no-follow descriptors, with failing-first and mutation receipts in the PR body. The local preflight passed. Hosted proof, confirmation and merge have not run yet. The assignment stays while the PR is live.

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: p1securitytype: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions