fix: apply ca-cert to main scan path via cert-aware fetch#840
Merged
Conversation
sonukapoor
force-pushed
the
bugfix/issue-839-ca-cert-fetch
branch
from
July 18, 2026 13:05
3dbbf5d to
1d1aba7
Compare
…-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.
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.
Fixes #839.
--ca-certwas only applied by settingNODE_EXTRA_CA_CERTSat runtime, which may not affect undici's already-initialized TLS context in Node.js 18+. On the advisory sync path (advisories sync), the download hitsstorage.googleapis.com, which corporate proxies typically do not intercept - so sync worked. The main scan path hitsapi.osv.devdirectly, which proxies do intercept, causing certificate errors that were not recoverable with the env var approach alone.What changed:
createCertAwareFetch(caCertPath)tosrc/utils/network.ts- builds afetch-compatible wrapper usingnode:httpswith a customAgentcarrying the corporate CA cert, appended to the system root bundle (tls.rootCertificates) so existing trusted CAs are not replacedfetchImplparameter toOsvAdvisorySourceso the cert-aware fetch can be injected at the advisory source levelfetchImplthroughcreateAdvisorySourceinscanner.ts,scanPackages,handleMultiFolderScan, and thescanProjecthelper inindex.tsso every scan network call uses the cert-aware fetch when--ca-certis configuredNODE_EXTRA_CA_CERTSassignment is kept as a belt-and-suspenders fallback for any other code pathsThe Agent is initialized lazily on the first request, so the cert file is not read until after
validateOptionshas already verified the path exists and is readable.Closes #839