Skip to content

Fix WebSocket proxy to respect HTTP_PROXY and custom CA certificates#87

Merged
shawnburke merged 1 commit intomainfrom
fix/websocket-proxy-support
Mar 9, 2026
Merged

Fix WebSocket proxy to respect HTTP_PROXY and custom CA certificates#87
shawnburke merged 1 commit intomainfrom
fix/websocket-proxy-support

Conversation

@shawnburke
Copy link
Copy Markdown
Collaborator

@shawnburke shawnburke commented Mar 9, 2026

Summary

  • Fixes WebSocket proxy connections bypassing HTTP_PROXY settings and custom CA certificates
  • Customers behind corporate proxies with custom CAs were seeing "connection refused" errors
  • The WebSocket dialing code added in Add WebSocket proxy traversal to reflector #79 was creating direct TCP connections instead of using the configured transport
  • The relay_test.sh was designed to exercise this but did not strictly block access to the snyk-broker container, allowing it to pass when it should fail.

Root Cause

The dialWebSocketTarget function was using net.Dialer and tls.DialWithDialer directly, bypassing:

  1. Proxy settings from http.ProxyFromEnvironment
  2. Custom CA certificates loaded into the transport's TLSClientConfig

Changes

reflector.go:

  • dialWebSocketTarget now checks for proxy settings via the transport
  • Added dialThroughProxy() to establish HTTP CONNECT tunnels through proxies
  • Added getTLSConfig() to reuse the transport's TLS config (including custom CAs)
  • Added getProxyURL() to respect transport proxy function or environment variables
  • Added Info-level logging for proxy vs direct connections

reflector_test.go:

  • Added TestWebSocketProxyThroughHTTPProxy - verifies WebSocket works through HTTP CONNECT proxy
  • Added TestGetTLSConfigFromTransport - verifies TLS config inheritance
  • Added TestGetTLSConfigWithoutTransport - verifies fallback behavior

relay_test.sh:

  • Now verifies WebSocket connections go through proxy when PROXY=1
  • Checks for "Connecting to WebSocket target through proxy" log message
  • Fails if direct connections are made when proxy is configured

Test plan

  • All existing unit tests pass
  • New proxy and TLS config tests pass
  • Run PROXY=1 ./relay_test.sh to verify end-to-end proxy support
  • Verify fix in Paychex environment

🤖 Generated with Claude Code

@shawnburke shawnburke requested a review from keithfz March 9, 2026 21:38
keithfz
keithfz previously approved these changes Mar 9, 2026
@shawnburke shawnburke force-pushed the fix/websocket-proxy-support branch 3 times, most recently from 6b5a276 to 844bb15 Compare March 9, 2026 22:06
keithfz
keithfz previously approved these changes Mar 9, 2026
@shawnburke shawnburke force-pushed the fix/websocket-proxy-support branch 2 times, most recently from 12bf20c to 3d5c65d Compare March 9, 2026 22:23
The WebSocket proxy code added in 36d35f7 was bypassing the configured
HTTP transport, causing connection failures for customers using HTTP
proxies with custom CA certificates.

Changes:
- dialWebSocketTarget now checks for proxy settings via the transport
- Added dialThroughProxy() to establish HTTP CONNECT tunnels
- getTLSConfig() reuses the transport's TLS config (including custom CAs)
- Added Info-level logging for proxy vs direct connections

Test improvements:
- relay_test.sh now verifies WebSocket connections use proxy when configured
- Added unit tests for proxy support and TLS config inheritance

Fixes connection refused errors for customers behind corporate proxies.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@shawnburke shawnburke force-pushed the fix/websocket-proxy-support branch from 3d5c65d to dd80201 Compare March 9, 2026 22:27
@shawnburke shawnburke requested a review from keithfz March 9, 2026 22:39
@shawnburke shawnburke merged commit 7c4dabf into main Mar 9, 2026
19 checks passed
@shawnburke shawnburke deleted the fix/websocket-proxy-support branch March 9, 2026 22:41
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.

2 participants