derp/derphttp: honor DERPNode.DERPPort in proxied CONNECT dial#120
Merged
Conversation
dialNode picks the destination port from n.DERPPort when non-zero, falling back to 443 (or 3340 when useHTTPS is false). The proxy path, dialNodeUsingProxy, hardcoded "443" in the CONNECT target, so a DERP server reachable only on a custom port was unreachable through HTTPS_PROXY: the proxy would faithfully tunnel to :443 at the DERP hostname, and TLS would either fail cert validation or talk to the wrong service. Mirror dialNode's port selection so both paths behave the same. Fixes tailscale#19748 Signed-off-by: Martin Zihlmann <martizih@outlook.com>
deansheather
approved these changes
May 18, 2026
Author
|
I think failure is unrelated, no? |
Author
|
CI failures here are pre-existing on |
Member
|
Yeah CI is broken on our fork, the main thing we care about is tests on Linux. Thanks for the contribution! |
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.
Cherry-pick of tailscale#19752 (fixes tailscale#19748) onto coder's fork.
When
derphttp.Clientroutes a DERP connection through an HTTPS forward proxy (HTTPS_PROXY), the CONNECT request always targets port 443, even when the DERP map specifies a customDERPPort.The non-proxy path,
dialNode, derp/derphttp/derphttp_client.go#L909-L913, correctly honorsn.DERPPort:The proxy path,
dialNodeUsingProxy, same file L993, hardcodes"443"and never consultsn.DERPPort:A custom DERP server on a non-443 port is therefore unreachable through
HTTPS_PROXY: the CONNECT line is sent tohost:443, the proxy faithfully tunnels to whatever sits on :443 at that hostname/IP, and TLS either fails on cert validation (if a different service runs on :443) or talks to the wrong service.This PR mirrors
dialNode's port selection indialNodeUsingProxy. The end-to-end test from the upstream PR doesn't port cleanly (this fork lacksfeature.HookProxyFromEnvironment, renamed/narrowed types) and the unit-test variant was dropped on the upstream PR (commit bb8b711), so this PR is fix-only.