fix(#340): Eliminate HTTPS DNS rebinding TOCTOU gap with pinned agent#341
Merged
radaghastly merged 1 commit intoMar 9, 2026
Conversation
…ed agent Uses https.Agent with a custom lookup function that returns the pre-resolved IP address, eliminating the DNS rebinding window for HTTPS requests while preserving TLS certificate validation via SNI. - assertNotPrivateUrl() now returns a single-use https.Agent for HTTPS - custom-proxy uses fetchWithAgent() wrapper (http.request with agent) - testConnection() uses pinnedRequest() helper with the agent - Node built-in fetch does not support agent option, hence the wrappers Fixes monteslu#340
radaghastly
approved these changes
Mar 9, 2026
Collaborator
radaghastly
left a comment
There was a problem hiding this comment.
LGTM! Clean implementation — https.Agent with custom lookup pins DNS at the connection level while preserving TLS cert validation via SNI. The fetchWithAgent wrapper gives a clean fetch-like interface. Both proxy and testConnection paths covered.
Nice work closing the TOCTOU gap properly. 🔒
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.
Summary
Eliminates the HTTPS DNS rebinding TOCTOU gap identified in #340 (from PR #283 review).
Problem
assertNotPrivateUrl()resolves DNS to validate the IP is not private, but for HTTPS URLs the subsequentfetch()re-resolves DNS independently. An attacker controlling DNS could return a public IP on first lookup and a private IP on second (DNS rebinding).Solution
Use
https.Agentwith a customlookupfunction that returns the pre-resolved IP. This pins DNS at the connection level while preserving TLS certificate validation via SNI.Changes
src/services/customServiceService.jsassertNotPrivateUrl()returns{ agent }for HTTPS — single-usehttps.Agentwith pinned DNSpinnedRequest()helper fortestConnection()src/routes/custom-proxy.jsfetchWithAgent()— wrapshttp(s).requestin a fetch-like interfaceAll tests pass, lint clean.
Fixes #340