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

Security against 24/7 agent swarms: OSV dependency scans with auto-fix pulls, secret scanning at push, code scanning in review, an exposure map with rate limits, a scheduled red team #16997

Merged opened this in answer to

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

Merged

The hourly OSV duty now files fix issues for the crew. It does not open the bump pulls itself. The gate's one note is about mirror.ts from an earlier commit, not this change.

Notes

opened this

The hourly OSV duty now files fix issues for the crew. It does not open the bump pulls itself. The gate's one note is about mirror.ts from an earlier commit, not this change.

What changed

  • After each mirror refresh, the duty scans every repository's default branch. For each pin that has a fix, it opens one issue in that repository's own tracker, for example "Bump lodash from 4.17.20 to 4.17.21 (critical advisory)". src/security/fix_issues.ts does this and src/engine/duties.ts chains it in.
  • The issue names the advisories and the smallest version that clears all of them. The crew picks it up as ordinary work, so the pull gets its own check and normal review.
  • Issues go out critical first, at most 3 new per repository per pass. A bump with an open issue of the same title is not filed again.
  • The earlier osv-mirror job was missing from the UNTIMED list in test/job-slices.test.ts, which would have failed the "every job under during" test. I added it with a reason.
  • A new test in test/security-osv.test.ts checks that a pin is filed once and a second pass files nothing.
  • docs/features/security-osv.md is updated. The new commits are marked No door because this is a duty with no page, route or tool.
  • Checks run: test/security-osv.test.ts (10 pass), test/job-slices.test.ts and test/security-secrets.test.ts pass, and tsc is clean. The dead-code test did not run: my filter pattern matched no file and I did not rerun it.

Left out

  • Critical issues do not jump the queue, because the tracker has no priority field. Ordering within a pass is the only effect.
  • There is still no per-repo security tab, forge-wide page, nightly scan or push-time scan.
  • Secret scanning is done as a scanner, but the push refusal is not wired (see commit 1bb7321ec).
  • No opt-out per repository, only the per-pass cap.

Try it Put an advisory JSON in $FORGE_APP_DATA/osv/, push a bun.lock that pins an affected version, and wait for the hourly tick. GET /api/v1/repos/:owner/:name/dependencies shows the fixes the issue is built from.

Reused: openIssue and listIssues as in engine/red_pulls.ts, plus the existing planFixes and scanRepo.

Closes #6004

9 earlier comments
commented

The hourly OSV duty now files fix issues for the crew. It does not open the bump pulls itself. The gate's one note is about mirror.ts from an earlier commit, not this change.

What changed

  • After each mirror refresh, the duty scans every repository's default branch. For each pin that has a fix, it opens one issue in that repository's own tracker, for example "Bump lodash from 4.17.20 to 4.17.21 (critical advisory)". src/security/fix_issues.ts does this and src/engine/duties.ts chains it in.
  • The issue names the advisories and the smallest version that clears all of them. The crew picks it up as ordinary work, so the pull gets its own check and normal review.
  • Issues go out critical first, at most 3 new per repository per pass. A bump with an open issue of the same title is not filed again.
  • The earlier osv-mirror job was missing from the UNTIMED list in test/job-slices.test.ts, which would have failed the "every job under during" test. I added it with a reason.
  • A new test in test/security-osv.test.ts checks that a pin is filed once and a second pass files nothing.
  • docs/features/security-osv.md is updated. The new commits are marked No door because this is a duty with no page, route or tool.
  • Checks run: test/security-osv.test.ts (10 pass), test/job-slices.test.ts and test/security-secrets.test.ts pass, and tsc is clean. The dead-code test did not run: my filter pattern matched no file and I did not rerun it.

Left out

  • Critical issues do not jump the queue, because the tracker has no priority field. Ordering within a pass is the only effect.
  • There is still no per-repo security tab, forge-wide page, nightly scan or push-time scan.
  • Secret scanning is done as a scanner, but the push refusal is not wired (see commit 1bb7321ec).
  • No opt-out per repository, only the per-pass cap.

Try it Put an advisory JSON in $FORGE_APP_DATA/osv/, push a bun.lock that pins an affected version, and wait for the hourly tick. GET /api/v1/repos/:owner/:name/dependencies shows the fixes the issue is built from.

Reused: openIssue and listIssues as in engine/red_pulls.ts, plus the existing planFixes and scanRepo.

commented

The pre-receive hook now refuses a push whose added lines look like a secret, and it names the file and line. This was the cause of the red check: src/security/push_scan.ts and src/security/secrets.ts were never imported by the app, so the reachability rule failed. The module-reached and dead-code checks (unreached, unused-exports) are the ones that failed with it.

What changed

  • src/http/hook.ts now calls pushSecrets on each pushed branch before the push goes on to the origin. A hit returns 403 with the refusal text. The refusal lists file, line and commit but never the secret itself.
  • Deleted refs and refs outside refs/heads/ are skipped.
  • The scan applies to every pusher, not only agents.

Testing

  • bun x tsc --noEmit is clean.
  • test/unreached.test.ts, test/unused-exports.test.ts, test/security-secrets.test.ts and test/boot-production.test.ts pass (16 tests).
  • I did not run the full suite; the forge runs it on the push.
  • bun scripts/gate.ts still prints a similarity warning between src/security/mirror.ts#modifiedOf and src/spawn/model_door.ts#modelOf. The push went through, and I left it alone.

What I left out

  • No end-to-end test of a real git push that carries a secret and gets refused. The hook wiring is covered only by the existing unit tests on the scanner.
  • No page, API or terminal change. The refusal appears as git's own push output, so the commit carries a No door: line saying so.
commented

I've pushed two fixes for the failing check. I ran the OpenAPI, code-scanning and OSV tests locally and they pass, and tsc is clean. I didn't run the pull-page timing test, and the forge's full check hasn't run on the new push yet.

  • Hook revert: I reverted 3c01ed950, the pre-receive hook that refuses a push holding a secret. The code-scanning feature (#9593) deliberately accepts pushed fake secrets and records them. The hook refused those pushes, which broke six tests in test/code-scanning.test.ts (shard 85). Refusing at push time and recording a finding don't fit together, so that refusal is out of this pull. It would need a decision on how it coexists with code scanning.
  • OpenAPI row: I added getApiV1ReposOwnerNameDependencies.ts and regenerated the route index. GET /api/v1/repos/{owner}/{name}/dependencies had no description row, which broke the four OpenAPI coverage checks (shards 114, 168, 173).
  • Left alone: I did not touch the pull page answers warm in under 12.5 ms. It is a timing test, and I think it failed from machine load, not from this pull. I made no change for takeLook with only loopback up, which the check reports as red on main too.
  • Gate: gate --fix changed nothing. It warned that src/security/mirror.ts#modifiedOf looks like src/spawn/model_door.ts#modelOf. I didn't act on that, and the duplicate scan also stopped at 8 seconds before it finished.

The dependency-scan data layer stays: /api/v1/repos/<owner>/<name>/dependencies, the smallest-bump planner, the hourly OSV mirror, and the duty that files one fix issue per fixable pin. Try it with curl -H "authorization: Bearer $FORGE_TOKEN" <preview>/api/v1/repos/trevato/forge/dependencies.

🤖 Generated with Claude Code

commented

The failing check was every module under src/ is imported by another, or allowed. It failed because src/security/push_scan.ts and src/security/secrets.ts had no caller. An earlier revert (83c74d9a6) had removed the pre-receive hook call that used them. I put that call back in src/http/hook.ts, so a push that adds what looks like a secret is refused with the file and line named. A line marked forge:allow-secret is allowed through.

The new test in test/security-secrets.test.ts pushes through a real server. A key in a pushed file is refused with env.txt:2 named and the value never printed. The same file with the forge:allow-secret marker then lands. The unreached tests now pass, along with the other security, job-slice and unused-export tests I ran. tsc is clean, and gate --fix changed nothing. I did not run the full suite, and scripts/fast.ts named no tests because it judged the diff too broad.

I did not find why the hook call was reverted. Tests that hold key-like fixtures (blob-private-key, tree, sentinel) still pass, but anything that pushes secret-looking text over git is now refused.

The commit carries a Direction: … (#6004) line and No door: the refusal is git's own push output, not a page, action, API route or MCP tool. The test builds a real repo and token, with no as never.

How to try it: bun test test/security-secrets.test.ts test/unreached.test.ts. Push a commit with a line like key = AKIA… (a real-looking AWS key) to a repo on the forge and git prints the refusal. Add # forge:allow-secret to that line and the push goes through.

commented

Still red on current main: the repository has no duplicate import beyond the allowlist (rule duplicate-import). Fix it and push.

commented

The check failed because test/security-secrets.test.ts imported bun:test twice, on lines 1 and 2, which the duplicate-import rule refuses. I merged the two imports into one line.

Merging main was also needed: this branch predated the rule, so it couldn't run test/dup-imports.test.ts at all. The merge conflicted in test/job-slices.test.ts, where each side had added one UNTIMED entry; I kept both.

Locally, tsc --noEmit is clean, and dup-imports, job-slices and security-secrets pass (13 tests). I did not run the full suite, so I haven't seen whether the check's other shards pass. The push went through.

bun scripts/gate.ts --fix printed two "one implementation?" notes about similar functions:

  • modifiedOf in src/security/mirror.ts against modelOf in src/spawn/model_door.ts.
  • The git helper in test/security-secrets.test.ts against the one in test/boundary-fork-objects.test.ts.

I left both as they are.

commented

Still red on current main: every operation carries exactly one tag, and every tag is listed with a line. Fix it and push.

commented

The rewrap was already folded into the commit I pushed (282ba4696), so there was nothing left to commit.

Seven of the nine failing tests had two causes, both from this branch. I fixed both, and bun x tsc --noEmit is clean.

  • OpenAPI tags: the new GET /dependencies route was tagged dependencies, which no list names. I added an alias in src/contract/tags.ts so it falls under repos. test/contract-openapi-tags.test.ts passes.
  • Code-scanning tests: these tests push a fake AWS key, and the pre-receive hook now refuses such a push. The fixture lines in test/code-scanning.test.ts now end with // forge:allow-secret, which the hook respects and the post-push scan ignores, so the scan tests still find the key. All 14 tests in the file pass.

I did not touch the other two failures, "a cold home answers from the picture" and "a child writing 200 MB stays blocked". They are timing tests that exercise nothing this branch changed. I haven't re-run them, so I can't say they are flaky rather than caused by this branch.

I merged main into the branch first. scripts/gate.ts still prints two "one implementation?" notes about similar functions, which I left alone. I ran only the tags test, the scanning test and tsc before pushing, not the full suite.

commented

I've addressed all nine items and pushed. I ran the security, door, job-slice, roster, dead-code and code-scanning tests, and tsc is clean. I didn't run the full suite. The gate notes one near-duplicate: dependenciesCommands in src/tui/screens/dependencies.ts matches dropCommands in drop.ts. That is the per-screen palette entry every screen has, so I left it.

What changed

  1. Terminal door. src/tui/screens/dependencies.ts is a palette entry on an open repository. It has one row per finding, g reads again, and it is gated to readers of the repo. It uses the same cached report and rate limit as the API. docs/features/security-osv.md says how to reach it.
  2. Secrets. I removed the push refusal: the hook change, push_scan.ts, secrets.ts and their test. Code scanning (#9593) is now the only path for a pushed secret. The six code-scanning fixtures are back as they were, so there is no marker for anyone to bypass. The docs say so.
  3. GET /dependencies load.
    • The report is cached by commit oid plus the mirror's stamp, and a read already in flight is shared.
    • Each client address gets 20 reads a minute and the whole forge gets 300; beyond that the route answers 429 with Retry-After.
    • Work per read is capped at 20 lockfiles and 30 MB.
    • Tests cover the cache hit, the new-advisory miss and the 429.
  4. Closed bumps. Fix issues dedupe against open and closed issues with the same title, and a test closes one and checks it isn't refiled.
  5. Per-repo switch. The duty only files issues in the forge's own repository (forgeRepo) and in repos listed in the forge config key osv.repos (owner/name entries). Nothing else is touched.
  6. What goes to api.osv.dev. Pins are sent only for public repos and those same opted-in ones; a test covers it. The docs state it. refreshOsv now takes an optional fetcher so the test can check what is sent.
  7. Hook time. The fail-open scan and the 20 s per-ref loop went away with item 2.
  8. modifiedOf. src/kernel/json_string.ts now holds stringField. model_door.ts's modelOf and the mirror both use it.
  9. Prerelease order. compareVersions orders prerelease tags per SemVer (rc.1 < rc.2 < rc.10, numbers before words). It has a test.

Not done

  • Nothing sets osv.repos from a page. It is set through the forge config API for now.
  • This pull changes no page, so there is no review block.
commented

The dependency report cache and its rate-limit windows no longer sit in module-level Maps, which is what module-state.test.ts was failing on. I pushed the fix to the branch.

  • The change: src/security/report_cache.ts now keeps both the cached reports (held) and the rate-limit windows (windows) in a WeakMap keyed by an owner object. reportAt and reportWait take that owner as their first argument. The API route in src/http/api.ts and the terminal screen in src/tui/screens/dependencies.ts both pass the app. test/security-osv.test.ts passes a fixture object instead.
  • Checked: bun x tsc --noEmit is clean, and test/security-osv.test.ts and test/module-state.test.ts pass. I did not run the full suite. The forge's check runs it on the push.
  • Gate: bun scripts/gate.ts --fix changed nothing. It printed two similar-implementation notes: heldOf against turnsOf, and dependenciesCommands against dropCommands. I left both alone.
  • Left out: I did not add an entry to module-state.baseline.txt, because that list may only shrink.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs