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

Pinned dependencies are matched against a local mirror of OSV advisories, and a vulnerable one is a finding #17082

Merged opened this

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

Merged

This adds an hourly duty, osv-mirror (src/maintain/duties/osvmirror.ts), that checks the forge's own pinned packages against OSV.dev advisories.

Notes

opened this

This adds an hourly duty, osv-mirror (src/maintain/duties/osv_mirror.ts), that checks the forge's own pinned packages against OSV.dev advisories. It reads bun.lock / package-lock.json at the forge's root through the lockfile reader (src/maintain/lockfiles.ts) and refreshes a local mirror of the advisories for those packages. It then lists every pinned version an advisory affects on /maintenance, one line each naming the fix: "lodash 4.17.20 is affected by GHSA-35jh-r3h4-6jhm; fixed in 4.17.21".

What to look at

  • src/maintain/osv.ts
    • parseAdvisory checks each advisory before it is used, because advisory data is untrusted. It keeps only the id, the modified time, and each npm package's SEMVER/ECOSYSTEM ranges and exact versions. Every version is parsed and every list has a size limit. A withdrawn or malformed advisory, another ecosystem, or a GIT range is never matched.
    • matchAdvisories is plain data in, plain data out: findings {name, version, id, fixedIn}, worked out with OSV's evaluation (https://ossf.github.io/osv-schema/#evaluation).
    • refreshMirror asks POST /v1/querybatch which advisories each package has (by name), then fetches only new or changed ones with GET /v1/vulns/{id}, at most 300 per run. Everything is written in one transaction at the end, so a failed fetch leaves the old mirror whole. The failure is recorded in the duty's run line and shown on the board ("fetch failed: …; kept the mirror from <time>"). When the forge's gate refuses the host, the message uses the gate's own words.
  • api.osv.dev is added to forge.json egress. It is the only host the duty calls. I didn't add the storage.googleapis.com bulk export: it would mean downloading and unzipping the whole npm dataset.
  • Storage: migration 20261201140000-osv-mirror adds three tables (osv_advisory, osv_mirror, osv_finding) in the forge's database under FORGE_APP_DATA. The migration is pinned.
  • Where the findings show:
    • src/maintenance/findings.ts has dependencyLine, mirrorLine, dependencyFindings and dependencyLines.
    • The web page gets a "Vulnerable dependencies" fold (dependenciesFold). It shows in the needs-you view while anything is affected, and the failure line appears whenever the last refresh failed.
    • The terminal's Maintenance screen ends with the same lines.
    • /maintenance.json gains dependencies.
    • The how-to is docs/features/maintenance-dependencies.md.
  • Reused, not new: parseSemver/compareSemver from src/flows/semver.ts, refusedWords from src/maintain/refused_once.ts, and outboundFetch. compareSemver now orders pre-releases by semver §11, so beta.2 comes before beta.10; before this it compared them as plain text.
  • Changed tests (the old ones weren't wrong; the JSON's shape grew):
    • test/maintenance-json.test.ts now expects dependencies: [] alongside findings.
    • test/maintenance-finding-age.test.ts builds its database by hand, so its seed now creates osv_finding, which findingsJson reads.
  • The lockfile reader's dead-code allow entries are removed, since the duty now calls it.

Not done here: scanning every repository's lockfiles, scanning on push, automatic fix pulls, and per-repo security tabs. Those are the later parts of #6004. Querybatch result paging isn't followed either; a package with more than 1000 advisories would be cut short.

Checks:

  • test/osv.test.ts (12 tests) covers the range match on affected, fixed and unaffected versions, with introduced: 0, last_affected, limit, pre-releases, and two ranges where the lowest fix wins. It also covers the boundary checks, refreshing against a stand-in for api.osv.dev (only changed advisories refetched, a 503, a gate refusal), the duty end to end from a bun.lock, and escaping on the page.
  • bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts pass, as do the maintenance, duty, schema, feature-doc and dead-code suites I ran by name. scripts/fast.ts couldn't name the tests (exit 2, because forge.json changed), so the full suite runs only in the forge's check.
  • The terminal door is the existing Maintenance screen, so there is a No door: line in a commit.
  • The mirrorState function was flagged as similar to sentinelStanding. I kept it separate because the two read different tables for different purposes.
  • No prompt injection found in the issue or the repository.

Try it: open /maintenance on the preview as an admin. After the first hourly run, the osv-mirror row under Duties says how many advisories it fetched and how many pins matched, and any affected pin is listed under Vulnerable dependencies. GET /maintenance.json answers the same findings under dependencies.

[{"go":"/maintenance","look":"Duties fold, osv-mirror row","expect":"after its first run: 'refreshed the OSV mirror from api.osv.dev: N advisories fetched…' and 'matched N pinned versions: M affected', or 'fetch failed: …; kept the mirror from …'"},{"go":"/maintenance","look":"Vulnerable dependencies fold","expect":"absent when nothing is affected and the mirror is current; otherwise one row per pin ending 'fixed in X' or 'no fixed version is published yet'","ask":"Is the needs-you placement right while a pin is affected?"},{"go":"/maintenance.json","look":"the JSON body","expect":"a dependencies array of {name, version, id, fixedIn} beside findings"}]

🤖 Generated with Claude Code

Closes #17047

Show 17 earlier items

7 earlier comments
commented

Pinned npm dependencies from the forge's root bun.lock / package-lock.json are now checked against a local mirror of OSV.dev advisories, and a vulnerable pin shows up as a finding on /maintenance and in its terminal screen (#17047, part of #6004). Each advisory is checked when it arrives (parseAdvisory in src/maintain/osv.ts), and only its id, modified time and npm ranges/versions are kept. The mirror is stored under FORGE_APP_DATA and refreshed every hour, from api.osv.dev only; that host is listed in forge.json egress. If a refresh fails, the old mirror is kept and the run says why, using the gate's own words when the gate refused.

This round fixes both review points in src/maintain/osv.ts:

  • Size cap. The cap on an OSV answer now applies to the bytes actually read. The body goes through the existing byte-counting reader src/spawn/bounded_read.ts, which cancels the stream one chunk past 4,000,000 bytes and ignores content-length. I reused that reader rather than adding another copy. One side effect: a body that breaks off mid-read is reported the same way as an oversized one ("answered more than 4000000 bytes, or broke off").
  • Malformed advisories. An advisory that fails to validate is now remembered in a new table, osv_rejected, with the modified time it was listed with. A new additive migration, 20261201160000-osv-rejected, creates it; it is pinned and the generated migration list is regenerated. The already-pinned osv-mirror migration is unchanged. An unchanged rejected advisory no longer counts as stale, so it can't use up the 300-per-run budget. When it is republished with a new modified time it is fetched again, and if it validates it is stored and removed from osv_rejected. Rejected ids that OSV no longer lists are pruned.
  • Small tightening: an answer whose id differs from the id that was requested is now treated as rejected instead of being stored.

What to look at:

  • New test in test/osv.test.ts: a malformed advisory is fetched once across two refreshes, and again only after its modified time changes.
  • New test in test/osv.test.ts: an endless stream with no content-length is cancelled after a few MiB, the refresh fails, and the mirror is kept.
  • docs/features/maintenance-dependencies.md describes both behaviours.

Verification: bun x tsc --noEmit is clean, and bun scripts/gate.ts --explain reports 0 failing rules. The migration made bun scripts/fast.ts reach too many files to name, so I picked the tests myself: osv, schema-additive, schema-migrations, own-source, data-browser, hollow, abstractions, job-slices, unused-exports, maintenance-duties, maintenance-finding-age and egress-literals. 146 passed, 0 failed. The forge's check runs the rest.

🤖 Generated with Claude Code

commented

<!-- look-pages 7712fdbfa156 --> Look pages for 7712fdb, from the gate:

  • look pages (named): this pull changes src/web/pages/maintenance.ts; a commit names /maintenance
commented

The forge checks pinned dependencies against a local mirror of OSV advisories. Any pinned version an advisory covers shows as a finding, with the fixed version named, on /maintenance, in /maintenance.json under dependencies, and on the terminal's Maintenance screen. An hourly osv-mirror duty refreshes the mirror. The code is in src/maintain/osv.ts and src/maintain/duties/osv_mirror.ts, and the new tables come from migration 20261201140000-osv-mirror. The duty calls only api.osv.dev, which is added to forge.json egress.

What to look at

  • parseAdvisory treats advisory data as untrusted. It keeps only the id, the modified time, and the npm SEMVER/ECOSYSTEM ranges and versions, and sets a size limit on every list. A withdrawn or malformed advisory, another ecosystem, or a GIT range is never matched.
  • matchAdvisories follows OSV's evaluation rules (https://ossf.github.io/osv-schema/#evaluation).
  • refreshMirror fetches only new or changed advisories, at most 300 per run, and writes everything in one transaction at the end. A failed fetch keeps the old mirror and puts a "fetch failed: …; kept the mirror from <time>" line on the board. The size cap on OSV's answer counts bytes as they are read, through the shared byte-counting reader. An advisory that was refused is not fetched again until its modified time changes.
  • compareSemver now orders pre-releases by semver §11, so beta.2 comes before beta.10.
  • The how-to is docs/features/maintenance-dependencies.md.

About the look-pages note on 7712fdb: it only records that the gate takes look pages of /maintenance, the page this pull changes. Commit 5eda26fcf already names that page. Nothing needed changing, so this round has no new commit.

Checked at 7712fdb:

  • bun scripts/gate.ts --explain: 32 rules, 0 fail.
  • bun x tsc --noEmit: clean.
  • bun scripts/design-lint.ts: clean.
  • These tests pass (24): test/unused-exports.test.ts (dead code), test/job-slices.test.ts and test/route-timing-coverage.test.ts (every during job is timed), and test/osv.test.ts.
  • Every commit names #17047.
  • No test file this pull touches uses as never.

Left alone: two "one implementation?" similarity hints from the gate, mirrorState vs sentinelStanding and dependenciesFold vs secretsFold. Each pair reads different data, and merging them would couple unrelated folds.

[{"go":"/maintenance","look":"the Vulnerable dependencies fold","expect":"one line per affected pinned version naming the advisory and the fixed version, or a mirror status line when nothing is affected"},
 {"go":"/maintenance.json","look":"the dependencies key","expect":"findings as {name, version, id, fixedIn} and the mirror's last refresh"}]

🤖 Generated with Claude Code

commented

The forge's own pinned dependencies are now matched against the one OSV mirror main already has in src/security/ (#16997), and the second mirror this pull had added under src/maintain/ is gone. Its module, its osv-mirror duty, its four tables and its two migrations are all deleted, and the generated duty and migration lists match main again. Findings show on /maintenance as the "Vulnerable dependencies" fold, on the terminal's Maintenance screen, and in /maintenance.json as dependencies: [{name, version, id, fixedIn}].

What to look at

  • Matching (src/security/forge_pins.ts): reads bun.lock and package-lock.json at the forge's root and matches them locally against $FORGE_APP_DATA/osv/. The answer is cached until the mirror or a lockfile changes.
  • What is sent to api.osv.dev: nothing new. The hourly refresh still asks only about public and opted-in repositories (optin.ts), and the forge's own repository is always opted in. If FORGE_REPO is unset, the forge's own pins get no advisories mirrored, and the how-to says so.
  • Boundary checks (src/security/osv.ts): toAdvisory now checks every advisory as untrusted data:
    • the id must be safe as a file name;
    • lists are bounded (200 packages, 50 ranges, 100 events, 5,000 versions) and strings are short;
    • each event must have exactly one kind;
    • a withdrawn advisory is not mirrored.
  • Range matching (inRange): follows OSV's evaluation rules, adding last_affected and limit. A range whose versions are not semver is never matched. Where several ranges cover a version, the lowest fix is named.
  • Refresh (src/security/mirror.ts): every answer is read through the shared byte-counting reader, capped at 4,000,000 bytes. The refresh now reports why it failed, in the forge gate's own words when the gate refuses the host.
  • Failure line (src/security/standing.ts): the duty saves each refresh's outcome in $FORGE_APP_DATA/osv-refresh.json, outside osv/ so the mirror's cache key doesn't change. While the last refresh failed, the board shows "OSV refresh failed at …: …; kept the mirror from … (N advisories)".
  • Fold rows: each pin is said once. The label is "lodash 4.17.20" and the value is "affected by GHSA-…; fixed in 4.17.21". The terminal keeps the full sentence.
  • Pre-release order: main's compareVersions already orders pre-releases by semver §11 and has tests for it, so I reverted my separate change to src/flows/semver.ts.
  • Tests: the range and boundary tests moved to test/osv-findings.test.ts, now run against the one mirror. test/security-osv.test.ts also checks that the duty saves its outcome.

Left out

  • An advisory OSV serves malformed is fetched again each hour instead of being remembered. Remembering it needed the deleted osv_rejected table.
  • The two "one implementation?" similarity hints from the gate (dependenciesFold vs secretsFold) are unchanged; the two folds read different data.

Checks run before pushing: bun scripts/gate.ts --explain (0 fail), bun x tsc --noEmit, bun scripts/design-lint.ts, and 57 test files covering the security, maintenance, roster and door rules (412 pass, 0 fail). scripts/fast.ts picked 2,790 files, so I chose these instead.

[{"go":"/maintenance","look":"the Vulnerable dependencies fold","expect":"each row labelled with the package and version, its value 'affected by <id>; fixed in <version>', the pin not repeated; an 'OSV refresh failed … kept the mirror from …' row only after a failed refresh"},
 {"go":"/maintenance.json","look":"the dependencies key","expect":"[{name, version, id, fixedIn}] matched from the one mirror under FORGE_APP_DATA/osv"}]

🤖 Generated with Claude Code

commented

<!-- look-pages 6961f8a5c36b --> Look pages for 6961f8a, from the gate:

  • look pages (named): this pull changes src/web/pages/maintenance.ts; a commit names /maintenance
commented

The forge's own pinned packages are now checked against the forge's single OSV advisory mirror (src/security/). Each pinned version an advisory affects is a finding on /maintenance, in the terminal and in /maintenance.json. A second OSV copy under src/maintain used to exist; this pull removes it, so there is one fetcher and one store.

What to look at

  • Matching (src/security/forge_pins.ts): it reads bun.lock / package-lock.json at the forge's root and matches locally against $FORGE_APP_DATA/osv/. It follows OSV's evaluation rules (https://ossf.github.io/osv-schema/#evaluation), with pre-releases ordered by semver §11. These pins are never sent to api.osv.dev; only the pins of public and opted-in repositories are asked about. Each finding names the lowest fixed version, or says "no fixed version is published yet".
  • Checking advisories (toAdvisory in src/security/osv.ts): advisory data is untrusted, so the id must be safe as a file name, every list has a size limit, and a withdrawn or malformed advisory is skipped. An answer from api.osv.dev is cut off at 4,000,000 bytes, counted as it is read.
  • Failed refresh (src/security/standing.ts): the old mirror is kept and matching runs against it. The board says "OSV refresh failed at <time>: <why>; kept the mirror from <time>", using the gate's own words when the forge's gate refused the host.
  • Both doors agree (the latest commit): one rule, dependencyLevel in src/maintenance/level.ts, decides where the rows sit on the page and in the terminal.
    • While a pin is affected, the rows are under needs-you on both, and the status line counts them ("Needs you: 1 vulnerable dependency").
    • Before this, the page could say "Healthy: nothing needs you" right above the open fold, and the terminal only listed the rows in the for-information view.
  • How-to: docs/features/maintenance-dependencies.md.

Not done

  • The gate's similarity note pairs dependenciesFold with secretsFold. The two folds only look alike because both use the board's shared fold/statusRow pieces, so I didn't merge them.
  • Two comment lines are over 100 columns. --fix left them alone, and the gate says the nightly rewrap on main handles them.

Checks: bun x tsc --noEmit and the gate both pass. I ran by hand the maintenance, OSV, secret-scan, door, unused-export and llms.txt budget tests (219 pass), because scripts/fast.ts said the diff reaches too many files to name them.

[
  {"go": "/maintenance", "look": "the status line and the folds", "expect": "with no pin affected and a current mirror, there is no Vulnerable dependencies fold and the status line says nothing about dependencies"},
  {"go": "/maintenance?level=needs-you", "look": "the Vulnerable dependencies fold, if a pin is affected", "expect": "open, one row per pin labelled 'name version' and reading 'affected by <id>; fixed in <version>', and the status line counts them as 'N vulnerable dependencies'"},
  {"go": "/maintenance?level=fyi", "look": "the fold list", "expect": "the dependencies fold is here only when nothing is affected and the last OSV refresh failed, showing that failure line"},
  {"go": "/maintenance.json", "look": "the dependencies key", "expect": "an array of {name, version, id, fixedIn} next to findings"}
]

🤖 Generated with Claude Code

commented

<!-- look-pages 0069b3215007 --> Look pages for 0069b32, from the gate:

  • look pages (named): this pull changes src/web/pages/maintenance.ts; a commit names /maintenance
commented

The forge's own pinned packages are now checked against the forge's single OSV advisory mirror (src/security/). Each pinned version that an advisory affects becomes a finding on /maintenance, in the terminal and in /maintenance.json. This pull also removes a second OSV mirror under src/maintain, so there is one fetcher and one store.

What to look at

  • Matching (src/security/forge_pins.ts): reads bun.lock / package-lock.json at the forge's root and matches locally against $FORGE_APP_DATA/osv/.
    • It follows OSV's evaluation rules (https://ossf.github.io/osv-schema/#evaluation) and orders pre-releases by semver §11.
    • The forge's own pins are never sent to api.osv.dev. Only the pins of public and opted-in repositories are queried.
    • Each finding names the lowest fixed version, or says "no fixed version is published yet".
  • Checking advisories (toAdvisory in src/security/osv.ts): advisory data is untrusted.
    • The id must be safe to use as a file name, and every list has a size limit.
    • A withdrawn or malformed advisory is skipped.
    • An answer from api.osv.dev is cut off at 4,000,000 bytes, counted as it is read.
  • Failed refresh (src/security/standing.ts): the old mirror is kept and matching runs against it. The board says "OSV refresh failed at <time>: <why>; kept the mirror from <time>". When the forge's gate refused the host, it uses the gate's own words.
  • Both doors agree: one rule, dependencyLevel in src/maintenance/level.ts, decides where the rows sit on the page and in the terminal.
    • While a pin is affected, its rows are under needs-you in both places, and the status line counts them ("Needs you: 1 vulnerable dependency").
    • Before this, the page could say "Healthy: nothing needs you" right above the open fold, and the terminal listed the rows only in the for-information view.
  • How-to: docs/features/maintenance-dependencies.md.

Not done

  • The gate's similarity note pairs dependenciesFold with secretsFold. They only look alike because both use the board's shared fold/statusRow pieces, so they stay separate.
  • Two comment lines are over 100 columns. --fix left them alone; the gate says the nightly rewrap on main handles them.

Checks

  • bun x tsc --noEmit and the gate pass.
  • scripts/fast.ts said the diff reaches too many files to name, so the maintenance, OSV, secret-scan, door, unused-export and llms.txt budget tests were picked by hand: 219 pass.
  • The forge's check passed on 0069b32. Its one red test, test/keymap-terminal.test.ts, is also red on main at 54e86c1, so it doesn't come from this pull.
  • The gate captured /maintenance as a look page. Phone (1.8 screens) and desktop (1.3 screens) have no sideways scroll, and none of the 45 looks overflow, so no new commit was needed.
[
  {"go": "/maintenance", "look": "the status line and the folds", "expect": "with no pin affected and a current mirror, there is no Vulnerable dependencies fold and the status line says nothing about dependencies"},
  {"go": "/maintenance?level=needs-you", "look": "the Vulnerable dependencies fold, if a pin is affected", "expect": "open, one row per pin labelled 'name version' and reading 'affected by <id>; fixed in <version>', and the status line counts them as 'N vulnerable dependencies'"},
  {"go": "/maintenance?level=fyi", "look": "the fold list", "expect": "the dependencies fold is here only when nothing is affected and the last OSV refresh failed, showing that failure line"},
  {"go": "/maintenance.json", "look": "the dependencies key", "expect": "an array of {name, version, id, fixedIn} next to findings"}
]

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs