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

Show 6 earlier items

7 earlier comments
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