Public: anyone can read this; the crew can change it.

Quarantine untrusted repositories until a Sentinel security review passes #16709

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Repositories that come from outside now start quarantined: no app deploy (production or preview), no check, and no builder run until a review passes or the owner overrides it. tsc is clean and bun test test/quarantine.test.ts plus 18 related suites pass, including the guest, migrate and doorless tests.

Notes

opened this

Repositories that come from outside now start quarantined: no app deploy (production or preview), no check, and no builder run until a review passes or the owner overrides it. tsc is clean and bun test test/quarantine.test.ts plus 18 related suites pass, including the guest, migrate and doorless tests. I did not run the full suite or the sharded fast tier. Of the 4,453 test files, scripts/fast.ts named 3,775 for this diff, so I picked the covering files by hand and left the rest to the forge's check.

What changed

  • Review state: each quarantined repository gets a repo_review row (migration 20261130090000-repo-review). Its state is pending, passed, failed or override, with the findings, who and when. A repository with no row is not quarantined, so repos a member creates are unaffected.
  • What starts quarantined: repositories migrated from outside (actions/migrate.ts), mirrored from outside (origins/mirror.ts), and a guest's contribution fork (forkRepo in core/repos.ts).
  • What is refused:
    • Deploys: requestDeploy and mayRun, so wakes are covered too.
    • Checks: request, in checks/request.ts.
    • Builder runs: queueAgentRun.
  • The review: reviewRepo walks the default branch and runs nothing it reads. core/review_scan.ts blocks on install hooks, committed or oversized binaries, obfuscated or dynamic code, and text addressed to an AI. It only notes CI files and network calls.
  • What passes: a review with no blocking finding passes and lifts all three refusals. A failed review keeps the quarantine and records what it found.
  • Override: overrideQuarantine lets the repository's owner through, recorded with who and when. Everyone else gets not_found.
  • Reach: a terminal screen, "Security review", appears in the palette for the owner of a repository that has a review row. r runs the review and o overrides after a confirm. The how-to is docs/features/quarantine.md.
  • Tests: test/quarantine.test.ts covers deploy, check and builder refusal and the lift by a passed review. It also covers a failed review, the owner-only override, the scanner, and a guest fork versus a plain fork.

Left out

  • Review trigger: the review runs only when someone asks for it. It is not queued automatically after a migration.
  • Review reader: it is a deterministic scanner, not an AI pass. Sentinel does not read the code itself.
  • Outside pulls: these keep the existing approval gate in core/pull_trust.ts. I did not add a second quarantine there.
  • Non-member forks: only a guest's contribution fork is quarantined. Quarantining every fork by a non-writer would break "make it yours".
  • No web page or HTTP/MCP door: the screen above is the only door. The forge's both-doors rule was satisfied by the terminal screen plus the how-to.

Try it

  • Run bun test test/quarantine.test.ts.
  • Migrate a repository, open it in the terminal, choose "Security review", press r, then o if the review fails.

The gate prints "one implementation?" similarity notes on the new screen, the quarantine functions and the test helper. I judged them different enough to keep and did not merge them with the lookalikes it named.

Closes #3969

13 earlier comments
commented

Repositories that come from outside now start quarantined: no app deploy (production or preview), no check, and no builder run until a review passes or the owner overrides it. tsc is clean and bun test test/quarantine.test.ts plus 18 related suites pass, including the guest, migrate and doorless tests. I did not run the full suite or the sharded fast tier. Of the 4,453 test files, scripts/fast.ts named 3,775 for this diff, so I picked the covering files by hand and left the rest to the forge's check.

What changed

  • Review state: each quarantined repository gets a repo_review row (migration 20261130090000-repo-review). Its state is pending, passed, failed or override, with the findings, who and when. A repository with no row is not quarantined, so repos a member creates are unaffected.
  • What starts quarantined: repositories migrated from outside (actions/migrate.ts), mirrored from outside (origins/mirror.ts), and a guest's contribution fork (forkRepo in core/repos.ts).
  • What is refused:
    • Deploys: requestDeploy and mayRun, so wakes are covered too.
    • Checks: request, in checks/request.ts.
    • Builder runs: queueAgentRun.
  • The review: reviewRepo walks the default branch and runs nothing it reads. core/review_scan.ts blocks on install hooks, committed or oversized binaries, obfuscated or dynamic code, and text addressed to an AI. It only notes CI files and network calls.
  • What passes: a review with no blocking finding passes and lifts all three refusals. A failed review keeps the quarantine and records what it found.
  • Override: overrideQuarantine lets the repository's owner through, recorded with who and when. Everyone else gets not_found.
  • Reach: a terminal screen, "Security review", appears in the palette for the owner of a repository that has a review row. r runs the review and o overrides after a confirm. The how-to is docs/features/quarantine.md.
  • Tests: test/quarantine.test.ts covers deploy, check and builder refusal and the lift by a passed review. It also covers a failed review, the owner-only override, the scanner, and a guest fork versus a plain fork.

Left out

  • Review trigger: the review runs only when someone asks for it. It is not queued automatically after a migration.
  • Review reader: it is a deterministic scanner, not an AI pass. Sentinel does not read the code itself.
  • Outside pulls: these keep the existing approval gate in core/pull_trust.ts. I did not add a second quarantine there.
  • Non-member forks: only a guest's contribution fork is quarantined. Quarantining every fork by a non-writer would break "make it yours".
  • No web page or HTTP/MCP door: the screen above is the only door. The forge's both-doors rule was satisfied by the terminal screen plus the how-to.

Try it

  • Run bun test test/quarantine.test.ts.
  • Migrate a repository, open it in the terminal, choose "Security review", press r, then o if the review fails.

The gate prints "one implementation?" similarity notes on the new screen, the quarantine functions and the test helper. I judged them different enough to keep and did not merge them with the lookalikes it named.

commented

This push fixes the two failing tests from the check. Both came from the quarantine work adding things the forge's coverage tests didn't know about yet.

  • Account purge: I added repo_review.by to COVERED in src/core/account_purge.ts as FORMER. That column holds either sentinel or the id of the admin who overrode a review. When that admin's account is removed, the row stays as history and names the placeholder.
  • Event audience: I classified repo.reviewed and repo.review_overridden in src/core/event_audience.ts, next to repo.forked. I put them in that group because it's the repository-lifecycle group and seemed the closest fit. I didn't check which audience that group gives them, so confirm it's the one you want for review events.

test/account-purge.test.ts, test/event-audience-coverage.test.ts and test/quarantine.test.ts pass locally (21 tests). bun x tsc --noEmit printed nothing, and bun scripts/gate.ts --fix changed no files. The gate printed one comment-length note about src/core/repos.ts (not a file I changed) and some "one implementation?" similarity hints on the quarantine files. I did not run the full suite; the forge's check does that on this push.

commented

This round fixes all seven of juniper's points. The quarantine now fails closed, a pass is tied to a commit, the review needs an owner, and the repository page can run it. The new and touched tests pass locally, and bun x tsc --noEmit is clean. I did not run the full suite or the design-lint check after the last edits, so the forge's check will be the first full run. bun scripts/design-lint.ts passed earlier, before I moved the card into the app page.

  • Fails closed (1): readTree now returns what it could not read. An unlistable directory, an unopenable file, or a tree past 2000 files each becomes an unread finding with severity block. The new reviewTree puts those findings first.
  • A pass is for a commit (2): repo_review now stores the reviewed oid. A push to the default branch of a repository whose review passed sets it back to pending straight away. The forge then reads the new tip itself (reviewAfterPush, registered in createApp before the deploy and check listeners). If the branch moves while the review is reading, nothing is recorded.
    • I left an owner's override alone, since it was a person's decision. A failed review stays failed and is read again on the next push.
  • Review needs an owner (3): reviewRepo(app, actor, repo) now takes an actor and returns not_found unless that actor owns the repository, as overrideQuarantine does. A repository with no review row returns not_quarantined, and reviewOf is read once, without the !.
  • Page door and automatic review (4): a "Security review" card shows on the repository home and on the app page while the repository is held. It shows the state and the findings, and the owner gets Run and Override buttons (POST /:owner/:name/review and /review/override, behind adminForm, then the action's own check). Migrate and mirror no longer need a manual trigger: their import emits a push event, which starts the review.
  • Atomic (5): createRepo takes quarantine?: string and writes the row in the same transaction as the repo. Migrate, mirror and a guest's fork all use it.
  • Tests (6): the new files are quarantine-doors, quarantine-mirror and quarantine-migrate. I checked that the mirror test fails when its quarantine: line is removed. I did not do that check for migrate.
    • Fail-closed: a cap of 2 files and an unlistable oid each yield a block finding.
    • Re-review: a postinstall hook pushed after a pass brings the quarantine back immediately, and the new tip then fails its review.
    • Override and actor: an override survives a later push, and a stranger or nobody is refused.
    • Wake guard: runtime.mayRun is checked on its own.
    • Page: owner, stranger and foreign-origin POSTs.
    • Terminal: the palette entry and the r key.
    • Intake: migrate and mirror are held the instant they return, then lifted if clean and kept if hooked.
  • Tidy (7): the stray blank first line in checks/request.ts is gone. As you said, the two new event kinds stay in READER_KINDS.

Not done: there is no periodic re-review of a repository that never receives a push. I also did not add a review block for the page; the "review" JSON steps the task asks for are below.

[
  {"go": "/<owner>/<name> (a migrated or mirrored repository, signed in as its owner)", "look": "the Security review card above the code", "expect": "'Waiting for its security review…' or 'The security review found something…', the findings listed as path, kind and severity, and Run the review and Override buttons"},
  {"go": "press Run the review", "look": "the flash and the card", "expect": "a clean tree passes and the card disappears; a package.json with a postinstall hook fails and lists an install-hook finding"},
  {"go": "the same page signed in as someone else", "look": "the card", "expect": "the state is shown, with no buttons"}
]
commented

<!-- look-pages 2438fd88336f --> Look pages for 2438fd8, from the gate:

  • look pages (inferred): this pull changes src/web/pages/repo.ts, src/web/pages/review.ts, src/web/studio/app.ts; the forge pictures /settings/crew (src/web/pages/repo.ts), /settings/crew?help (src/web/pages/repo.ts), /settings/captain (src/web/pages/repo.ts) and 4 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

This push fixes the two gate failures from the last check. I haven't seen the forge's check verdict on it yet.

  • Test casts: test/quarantine-doors.test.ts no longer uses as never for the key presses. A small press(key) helper builds a real KeyEvent, so the types now check.
  • Missing "Replaces" line: the new commit carries Replaces: nothing, test-only fix of the as-never casts. That satisfies the rule about src/web/pages/review.ts, and bun scripts/gate.ts no longer reports any rule failure.
  • What I ran: bun x tsc --noEmit is clean and bun test test/quarantine-doors.test.ts passes (7 tests). I didn't run the other test files.
  • Left alone: the "one implementation?" similarity notes are advisory, so I didn't touch them. The over-long comment line in src/core/repos.ts is left for the nightly rewrap.
  • Review block: this pull changes pages, and I didn't add one in this fix.
commented

This feedback is the gate's inferred look-pages list, so I changed nothing and pushed nothing.

The pull changes src/web/pages/repo.ts, src/web/pages/review.ts and src/web/studio/app.ts. The forge will picture /settings/crew, /settings/crew?help, /settings/captain and four more pages whose routes import them. That list is the right one for this change, because the quarantine banner, the review page and the owner override sit on the repo pages. A Looks: or No look: line is only needed to override the inference, and I don't want to.

The earlier "Replaces" gate failure is fixed in commit 70ccb643c.

I can't see the pictures from the sandbox. Please check the quarantined-repo state and the review page when they render.

commented

<!-- look-pages 70ccb643c522 --> Look pages for 70ccb64, from the gate:

  • look pages (inferred): this pull changes src/web/pages/repo.ts, src/web/pages/review.ts, src/web/studio/app.ts; the forge pictures /settings/crew (src/web/pages/repo.ts), /settings/crew?help (src/web/pages/repo.ts), /settings/captain (src/web/pages/repo.ts) and 4 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

I raised the app page's SQL budget from 51 to 52 and pushed. I haven't seen the forge's verdict on it yet. The other failure, "the screen shows the share, the budgets that refused and the agent refused", I did not fix.

  • Page budget: the quarantine card added one repo_review read to the repository page (/:owner/:name), so a warm load went from 51 to 52 statements. I raised the limit in src/perf/page_budgets/app.ts and updated its comment. I did this rather than hunt for a statement to merge. If you want the page held at 51, the card's read would have to be folded into an existing query instead.
  • tui-crawlers test: it lives in test/tui-crawlers.test.ts and passes when I run it alone, together with test/page-budget.test.ts. I didn't find a link between it and this pull, so I left it as it is. If it fails again on the next check, I'll look further.
  • Checks: bun x tsc --noEmit is clean and bun scripts/gate.ts --fix reported no rule failures.
commented

<!-- look-pages 3122ad1b6c9a --> Look pages for 3122ad1, from the gate:

  • look pages (inferred): this pull changes src/web/pages/repo.ts, src/web/pages/review.ts, src/web/studio/app.ts; the forge pictures /settings/crew (src/web/pages/repo.ts), /settings/crew?help (src/web/pages/repo.ts), /settings/captain (src/web/pages/repo.ts) and 4 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

This is the same look-pages notice as before, now for commit 3122ad1, and it asks for nothing new. I changed nothing and pushed nothing.

The inferred pages are the right ones. The pull still touches src/web/pages/repo.ts, src/web/pages/review.ts and src/web/studio/app.ts, and the forge pictures the pages whose routes import them. I'm not overriding that with a Looks: or No look: line.

The pictures should show the quarantine card on a repo home page. The card says the repo is waiting for its review, and its owner gets "Run the review" and "Override" buttons. Please check them when they render.

commented

A repository migrated or mirrored from outside, forked by a guest, or forked from a quarantined repository is now quarantined until a read-only security review passes. Until then nothing of it runs: no deploy, no check, no crew run.

Holding

  • When a repository is created, migrated, mirrored or forked by a guest, its repo_review row is written in the same transaction as the repository row.
  • A plain fork of a pending or failed repository copies that repository's state, reason and findings (inheritQuarantine in src/core/quarantine.ts, called from forkRepo). A fork of a passed or overridden repository is not held.
  • A push to the default branch of a passed repository holds it again, and the forge reads the new commit by itself. An owner's override stands across later pushes.

The review (src/core/review_scan.ts)

  • It never runs anything it reads, and it fails closed: an unreadable directory or file, or a tree over 2000 files, is a blocking unread finding.
  • These fail it:
    • install hooks in package.json
    • committed binaries
    • obfuscated code
    • text addressed to an AI
    • child_process, Bun.spawn, Bun.$
    • import() or require() of a computed name
    • forge.json app or check commands that fetch, decode or pipe to a shell, or a forge.json that does not parse
  • These are recorded as notes and pass: CI files, network calls, environment reads, bunfig.toml (preloads named), .npmrc, Dockerfile, Makefile.
  • docs/features/quarantine.md says the review is a heuristic. It catches the plain shapes of hostile code, not a determined author.

Where people see it

  • The repository page shows a card while the repository is held, including when it is empty. The card gives the state and the findings. Run the review and Override show only to the owner (ownsRepo, the same check the actions use), so a site admin who isn't the owner sees no buttons.
  • In the terminal, the palette's Security review runs (r) or overrides (o).
  • Both POSTs need same-origin admin scope and then pass the action's own owner check.
  • Each repository's quarantine state comes with the repository load in src/core/repos.ts (one LEFT JOIN repo_review), so an unheld repository's page costs no extra statement and the app page stays within its 51-statement budget. Every gate still asks isQuarantined live.

Not done

  • The scan reads text patterns and does no deeper analysis.
  • Outside pulls keep their existing head-approval gate (src/core/pull_trust.ts).

Tests

  • New: test/review-scan.test.ts covers each new scan rule. test/quarantine.test.ts covers fork inheritance and fails without the forkRepo change. test/quarantine-doors.test.ts covers the site admin who isn't the owner.
  • bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts are clean.
  • scripts/fast.ts named 3787 files because repos.ts reaches almost everything, so I ran 185 files instead: every test that forks, scans or reviews, plus the migration, contribution and page-budget tests. 1332 pass and 1 fails: test/mcp/forks.test.ts "the private fork's owner sees it, with its parent named". It also fails without this round's changes, it expects a fork's "following" words that this pull doesn't touch, and I did not check it on main.
[
  {"go": "/preview-admin/sample", "look": "the repository page while it waits for review", "expect": "a 'Security review' card saying it waits, with 'Run the review' and 'Override' for the owner and no repeated explanation under them"},
  {"go": "/preview-admin/sample", "look": "the same page as a site admin who is not the owner, or as a stranger", "expect": "the card's state and findings, and no buttons"},
  {"go": "/preview-admin/sample", "look": "after 'Run the review' on a tree with a postinstall hook or Bun.spawn", "expect": "the card says the review found something and lists each finding by path, kind and severity"},
  {"go": "/preview-admin/sample", "look": "after 'Override'", "expect": "the card is gone", "ask": "Is it clear enough, before pressing it, that Override lets the code run?"}
]

🤖 Generated with Claude Code

commented

<!-- look-pages 2e0421c7657f --> Look pages for 2e0421c, from the gate:

  • look pages (named): this pull changes src/web/pages/repo.ts, src/web/pages/review.ts, src/web/studio/app.ts; a commit names /preview-admin/sample
commented

Untrusted repositories are now held for review until someone approves them (#3969).

  • What gets held: a new repository marked for quarantine, a fork made by a guest, and any fork of a repository that is already held.
  • Fails closed: a held repository runs nothing, and a pass is tied to the exact commit that was reviewed.
  • Who reviews: only the owner can pass a repository, and the review buttons show for the owner alone.
  • What the review blocks: commands that start processes, and commands that download something and pipe it into a shell.
  • App page: the page refuses to run a held repository and makes one check for quarantine. There is also an automatic review.
  • API: the repository object has a new quarantined boolean. It is listed in src/core/repo_fields.ts with the owner's fields, so people who can write the repository see it and readers don't. The list and single-repository shapes in the API contract are built from these field lists. Without the entry, test/repo-fields.test.ts failed on an unlisted key.

Before pushing, the type check was clean and test/repo-fields.test.ts plus the contract tests passed (124 of 124). scripts/fast.ts named 3,787 of the test files for this branch, nearly the whole suite. That run did not finish inside the sandbox's 10-minute limit, so the forge's check is the full run. The gate printed advisory notes about duplicate-looking tests and stopped its duplicate scan after 8 seconds; neither blocks the push. Its run also tried to reach forge.test and two localhost addresses, which the sandbox refused.

To try it: fork a repository as a guest, and the new repository's API object has quarantined: true for its owner but no such field for a reader.

🤖 Generated with Claude Code

commented

<!-- look-pages 85ef2cd877c5 --> Look pages for 85ef2cd, from the gate:

  • look pages (named): this pull changes src/web/pages/repo.ts, src/web/pages/review.ts, src/web/studio/app.ts; a commit names /preview-admin/sample
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs