fix: add download size limit for OSV database archives#2743
Open
JasonOA888 wants to merge 1 commit intogoogle:mainfrom
Open
fix: add download size limit for OSV database archives#2743JasonOA888 wants to merge 1 commit intogoogle:mainfrom
JasonOA888 wants to merge 1 commit intogoogle:mainfrom
Conversation
io.Copy on the HTTP response body was unbounded, meaning a compromised or malfunctioning CDN could serve an arbitrarily large file and exhaust disk space. Wrap with io.LimitReader capped at 1GB (the largest OSV database zip is ~350MB as of 2025-04). Signed-off-by: Jason L <jason@outland.art>
Author
|
The CI failures on all three platforms (ubuntu, macos, windows) appear to be caused by The failing tests ( This looks like a flaky CI run due to external service unavailability. Happy to rebase or push an empty commit to retrigger CI if needed. |
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
The HTTP response body from OSV database archive downloads was read with
io.Copywithout any size limit. A compromised or malfunctioning CDN endpoint could serve an arbitrarily large response, causing disk exhaustion on the scanning machine.Fix
Wrap
resp.Bodywithio.LimitReadercapped at 1GB:1GB provides ample headroom — the largest OSV database zip (
osv-vulnerabilities/OSV) is ~350MB as of April 2025.Why this matters
This is a supply-chain defense measure. The download URL (
ArchiveURL) targets Google Cloud Storage, which is trusted. But if that endpoint were compromised (bucket hijack, DNS poisoning, CDN injection), the scanner would blindly write unlimited data to disk.io.LimitReadermakes the failure mode bounded and deterministic.Testing
Added
TestNewZippedDB_Online_OversizedResponseto verify the LimitReader does not break normal downloads (generating a >1GB payload in a unit test is impractical, so the test confirms the happy path still works with the limit in place).All existing tests in
zip_test.gocontinue to pass as the limit (1GB) far exceeds their test payloads.