fix(review): raise the patch-less secret-scan cap from 512KB to 4MB#8605
Merged
Conversation
Live diagnosis on the self-hosted ORB box: metagraphed's secret_leak gate false-positive rate climbed from 38% to 56% over 6 hours, holding mergeable PRs. Root cause wasn't a pattern-match false positive -- it was the fail-closed "content exceeded the scan cap" block on regenerated OpenAPI/JSON-schema artifacts. metagraphed's openapi.json is ~1.9MB and api-components.schema.json ~514KB, both well past the old 512,000-char cap; three recent PRs (#8106, #8095, #8005) were all held for this reason and all merged anyway once manually verified clean. The underlying fetcher (grounding-wire.ts's makeGithubFileFetcher) already requests the raw+json media type specifically to bypass GitHub's Contents API ~1MB base64-JSON envelope ceiling, so the real limit was always this local constant, not GitHub's. Raising it only expands scan coverage -- more content becomes fetchable-and-scannable instead of being marked incomplete-and-blocked -- so this can't weaken detection on anything the old cap already caught. 4MB gives headroom above the largest observed real case (loopover's own openapi.json is already at 525KB, past the old cap too). Fetch count/concurrency stay capped separately, unaffected.
Contributor
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8605 +/- ##
==========================================
- Coverage 92.54% 91.98% -0.56%
==========================================
Files 796 796
Lines 79690 79690
Branches 24066 24066
==========================================
- Hits 73749 73304 -445
- Misses 4803 5311 +508
+ Partials 1138 1075 -63
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Live-diagnosed on the self-hosted ORB box (edge-nl-01) while doing a routine health check across all 3 reviewed repos.
metagraphed'ssecret_leakgate false-positive rate climbed from 38% to 56% over 6 hours per the box's ownops_anomalyself-diagnostic, holding mergeable PRs.Root cause was not a pattern-match false positive (I initially suspected
bittensor_key'shotkey:/coldkey:regex, butsafety.ts'ssecretLeakFindingandcontent-lane/security-scan.tsboth already correctly exclude it from hard-blocking viaHARD_SECRET_KINDS). The actual trigger, confirmed from the live PR review comment text, was the fail-closed "content exceeded the scan cap" path insrc/queue/patchless-secret-scan.ts:metagraphed/public/metagraph/openapi.json: ~1.9MBmetagraphed/schemas/api-components.schema.json: ~514KBBoth exceed the old 512,000-char
SECRET_SCAN_PATCH_FALLBACK_MAX_CHARScap. Three recent metagraphed PRs (#8106, #8095, #8005 — all regenerating these files as part of an OpenAPI/GraphQL codegen epic) were held for this reason and all merged anyway once manually verified clean (100% false-positive on the recent sample).Why raising the cap is safe
The underlying fetcher (
grounding-wire.ts'smakeGithubFileFetcher) already requests theapplication/vnd.github.raw+jsonmedia type specifically to bypass GitHub's Contents API ~1MB base64-JSON envelope ceiling — so the real limit here was always this local constant, not something GitHub imposes. Raising it only expands scan coverage (more content becomes fetchable-and-scannable instead of being marked incomplete-and-blocked); it can't weaken detection on anything the old cap already caught. Fetch count (SECRET_SCAN_PATCH_FALLBACK_MAX_FETCHES=100) and concurrency (SECRET_SCAN_PATCH_FALLBACK_MAX_CONCURRENT=4) stay capped separately, unaffected.4MB gives real headroom above the largest observed case. Worth noting:
loopover's ownapps/loopover-ui/public/openapi.jsonis already 525KB — past the old cap too, so this wasn't metagraphed-specific, just first noticed there because its API surface is largest.Changes
SECRET_SCAN_PATCH_FALLBACK_MAX_CHARS:512_000→4_000_000, with an updated doc comment explaining the raw+json bypass and the reasoning above.test/unit/patchless-secret-scan.test.ts: replaced 6 hardcoded512_000/512_001boundary literals with references to the exported constant, so the tests track the real cap instead of drifting from it (this file's own hardcoded fixtures are exactly what silently broke when I bumped the constant — 5 tests failed until fixed).Test plan
npm run typecheck— cleantest/unit/patchless-secret-scan.test.ts— 54/54 passingtest/unit/secrets-scan.test.ts— 67/67 passing (adjacent scanner, unaffected)