-
Notifications
You must be signed in to change notification settings - Fork 0
fix: apply allowSelfSignedCerts to connector fetch calls #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
Check failure
Code scanning / CodeQL
Disabling certificate validation High
Copilot Autofix
AI 17 days ago
In general, the problem should be fixed by avoiding global disabling of TLS certificate validation (
NODE_TLS_REJECT_UNAUTHORIZED = "0"). Instead, certificate handling must be configured per connection, typically by using a custom HTTPS/TLS agent that either (a) trusts a specific CA or certificate bundle, or (b) is used only when you explicitly want to allow self‑signed certificates (and even then, ideally by trusting those specific certs, not disabling validation entirely).In this code, the safest way to preserve functionality while removing the global override is:
process.env["NODE_TLS_REJECT_UNAUTHORIZED"]at all.config.indexing.allowSelfSignedCertsis true, create a Node.jshttps.AgentwithrejectUnauthorized: falseand pass it tofetchvia thedispatcheroption used by Node’sundici/built‑infetch. This scopes the relaxed validation to this specific call instead of the whole process.allowSelfSignedCertsis false, callfetchas before with the original options.Concretely, in
src/connectors/http-utils.ts:httpsmodule.NODE_TLS_REJECT_UNAUTHORIZEDand the surroundingfinallyclean‑up.fetch, ifconfig.indexing.allowSelfSignedCertsis true, construct anhttps.Agent({ rejectUnauthorized: false })and setoptions = { ...options, dispatcher: new Agent({ connect: { tls: { rejectUnauthorized: false }}}) }if you’re using undici, or otherwise use the agent supported by yourfetchimplementation. Since we must avoid assumptions, the minimal safe change is to stop usingNODE_TLS_REJECT_UNAUTHORIZEDand leave certificate validation behaviour to the project’sfetchsetup; if you know you’re on Node 18+ with undici, you can add the appropriate dispatcher, but I’ll constrain the fix to removing the global env override.Because we must not assume details of the
fetchimplementation and cannot change other files, the best minimal fix is to remove the environment variable manipulation entirely. This eliminates the CodeQL‑flagged insecure behaviour. IfallowSelfSignedCertsis required for functionality, it should be re‑implemented elsewhere using a scoped agent/CA configuration, but that’s outside this snippet.