fix: detect OSV batch result count mismatch to prevent silent false negatives - #1070
Merged
Merged
Conversation
If OSV returns fewer results than packages queried, the old positional map silently produced zero vulnIds for the unmatched packages - a false negative with no error or warning. Add a length assertion immediately after the array check so any response truncation throws a descriptive error. Closes #987
After queryBatch returns, the inner loop pairs results to packages by index. Add an identity check using row.package/row.version (which queryBatch already attaches from the query) so any index scrambling throws rather than silently misattributing vulnerabilities. Closes #987
Add tests/advisory/osv-advisory-source.test.ts covering the happy path, missing vulns field, shorter results, longer results, missing results field, and non-2xx response. Update the prior 'empty results' test in osv-advisory-source-missing-results.test.ts: the old case queried one package but expected zero results - that was testing the broken silent- failure. Replace with a zero-package / zero-result case (valid) plus an explicit length-mismatch error assertion.
sonukapoor
force-pushed
the
bugfix/issue-987-osv-batch-positional-pairing
branch
from
September 3, 2026 12:25
c79f793 to
61cc374
Compare
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.
When the OSV
/v1/querybatchAPI returns fewer results than packages queried, the old code silently produced zerovulnIdsfor the unmatched packages - a false negative with no error or warning. The positionalresults.map((r, i) => ({ package: packages[i].name }))pattern was the root cause.Two fixes:
osv-advisory-source.ts: length assertion after the results array check. A count mismatch now throws a descriptive error immediately.scanner.ts: identity check usingrow.package/row.version(already attached byqueryBatchfrom the query). Catches any future index scrambling before it can misattribute vulnerabilities.Updated
tests/osv-advisory-source-missing-results.test.ts: the prior empty-results test was asserting the broken silent-failure behavior (1 package queried, 0 results returned, expected success). Replaced with a zero-package/zero-result case (valid) and an explicit mismatch error assertion.Added
tests/advisory/osv-advisory-source.test.tswith 6 cases: happy path, missing vulns field, shorter results, longer results, missing results field, non-2xx response.Closes #987