Skip to content

fix: detect OSV batch result count mismatch to prevent silent false negatives - #1070

Merged
sonukapoor merged 4 commits into
mainfrom
bugfix/issue-987-osv-batch-positional-pairing
Sep 3, 2026
Merged

fix: detect OSV batch result count mismatch to prevent silent false negatives#1070
sonukapoor merged 4 commits into
mainfrom
bugfix/issue-987-osv-batch-positional-pairing

Conversation

@sonukapoor

Copy link
Copy Markdown
Collaborator

When the OSV /v1/querybatch API returns fewer results than packages queried, the old code silently produced zero vulnIds for the unmatched packages - a false negative with no error or warning. The positional results.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 using row.package/row.version (already attached by queryBatch from 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.ts with 6 cases: happy path, missing vulns field, shorter results, longer results, missing results field, non-2xx response.

Closes #987

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
sonukapoor force-pushed the bugfix/issue-987-osv-batch-positional-pairing branch from c79f793 to 61cc374 Compare September 3, 2026 12:25
@sonukapoor
sonukapoor merged commit a49e2d7 into main Sep 3, 2026
6 checks passed
@sonukapoor
sonukapoor deleted the bugfix/issue-987-osv-batch-positional-pairing branch September 3, 2026 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OSV batch results are paired to query packages by array position, not identity

1 participant