Skip to content

fix: apply ca-cert to main scan path via cert-aware fetch#840

Merged
sonukapoor merged 6 commits into
mainfrom
bugfix/issue-839-ca-cert-fetch
Jul 18, 2026
Merged

fix: apply ca-cert to main scan path via cert-aware fetch#840
sonukapoor merged 6 commits into
mainfrom
bugfix/issue-839-ca-cert-fetch

Conversation

@sonukapoor

Copy link
Copy Markdown
Collaborator

Fixes #839.

--ca-cert was only applied by setting NODE_EXTRA_CA_CERTS at runtime, which may not affect undici's already-initialized TLS context in Node.js 18+. On the advisory sync path (advisories sync), the download hits storage.googleapis.com, which corporate proxies typically do not intercept - so sync worked. The main scan path hits api.osv.dev directly, which proxies do intercept, causing certificate errors that were not recoverable with the env var approach alone.

What changed:

  • Added createCertAwareFetch(caCertPath) to src/utils/network.ts - builds a fetch-compatible wrapper using node:https with a custom Agent carrying the corporate CA cert, appended to the system root bundle (tls.rootCertificates) so existing trusted CAs are not replaced
  • Added optional fetchImpl parameter to OsvAdvisorySource so the cert-aware fetch can be injected at the advisory source level
  • Threaded fetchImpl through createAdvisorySource in scanner.ts, scanPackages, handleMultiFolderScan, and the scanProject helper in index.ts so every scan network call uses the cert-aware fetch when --ca-cert is configured
  • NODE_EXTRA_CA_CERTS assignment is kept as a belt-and-suspenders fallback for any other code paths

The Agent is initialized lazily on the first request, so the cert file is not read until after validateOptions has already verified the path exists and is readable.

Closes #839

@sonukapoor
sonukapoor force-pushed the bugfix/issue-839-ca-cert-fetch branch from 3dbbf5d to 1d1aba7 Compare July 18, 2026 13:05
sonukapoor and others added 5 commits July 18, 2026 09:07
…-cert is configured

Thread createCertAwareFetch through createAdvisorySource and syncOsvAdvisories so
OSV API calls honour the configured CA certificate. Make the agent creation lazy in
createCertAwareFetch so validateOptions can reject an invalid path before any file
read occurs.
@sonukapoor
sonukapoor merged commit e31b8b5 into main Jul 18, 2026
6 checks passed
@sonukapoor
sonukapoor deleted the bugfix/issue-839-ca-cert-fetch branch July 18, 2026 13:45
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 query failed despite CA certificate being supplied

1 participant