Skip to content

Fix doubled scheme in the custom http tool's recording proxy URL - #187

Merged
BaaRai merged 1 commit into
mainfrom
fix/customtool-proxy-scheme
Nov 11, 2026
Merged

BaaRai merged 1 commit into
mainfrom
fix/customtool-proxy-scheme

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 11, 2026

Copy link
Copy Markdown
Owner

What

  • server/customtool.go: new helper proxyURLString(s): trims the value; an empty value or one that already contains :// is returned as is, a bare host:port gets http://. httpProxyTransport uses it for the operator proxy (spec.Proxy) and for s.m.ProxyAddr() (use_recording_proxy).
  • httpToolTransport: when http.DefaultTransport is not an *http.Transport, it clones a fresh &http.Transport{} instead of panicking on the type assertion.

Why

httpProxyTransport built the recording-proxy URL as "http://" + s.m.ProxyAddr(), but ProxyAddr() already returns a URL with a scheme: traffic.ProxyAddr() returns http://127.0.0.1:<port> / http://<addr> (traffic/traffic.go:305-310), and with capture off it returns the global proxy, which is validated with a scheme. So a custom http tool with use_recording_proxy: true was sent to a proxy URL that does not work.

Proxy URL before / after

Input Before After
use_recording_proxy, ProxyAddr() = http://127.0.0.1:3128 http://http://127.0.0.1:3128 (request fails: proxyconnect tcp: dial tcp: lookup http ...: no such host) http://127.0.0.1:3128
operator proxy = http://10.0.0.5:8080 http://10.0.0.5:8080 http://10.0.0.5:8080
operator proxy = 10.0.0.5:8080 (bare) 10.0.0.5:8080 (no scheme) http://10.0.0.5:8080

Tests

  • TestBypass_CustomHTTPProxyPeerNotPinned: g.m.globalProxy is now proxy.URL (with a scheme, as in production); the old comment that said the address was given without a scheme is fixed. On the code before this change it fails:
    use_recording_proxy: error=true out="request failed: Get \"http://api.example.com:45495/bypass\": proxyconnect tcp: dial tcp: lookup http on 172.22.0.1:53: no such host"; it passes after.
  • New TestHTTPProxyTransportProxyScheme (no database): recording proxy with a global proxy carrying a scheme, operator proxy with a scheme, operator proxy as bare host:port; asserts the transport's Proxy(req) URL. Before the fix the first case returned http://http://127.0.0.1:3128.
  • New TestHTTPToolTransportDefaultTransportNotStd (no database, not parallel): replaces http.DefaultTransport with a RoundTripper that delegates to the original, calls httpToolTransport in a gated scope, asserts a non-nil transport with DialContext set, and restores it. Before the fix it panicked on the type assertion.

Run locally with Go 1.26.10 (linux/amd64) against a throwaway PostgreSQL 16 container:

  • go build ./...: ok
  • go vet ./server/: ok
  • gofmt on the two changed files: clean
  • go test -count=1 ./server/ -run 'TestHTTPProxyTransport|TestBypass_CustomHTTPProxyPeerNotPinned|TestCustomHTTP': ok
  • go test -count=1 -p 1 ./... on a fresh database: all packages ok

Not verified

  • No end-to-end run of a custom http tool through the real recording MITM proxy (traffic capture on) in a running instance; the recording-proxy case is covered through the global proxy path of ProxyAddr() and the unit test.
  • ./server was not run under -race (CI does not run it there either). The DefaultTransport test swaps a package global; it is sequential and the replacement delegates to the original transport, but it is a formal write to a global that leftover goroutines of earlier tests could read.

ProxyAddr returns a URL that already carries a scheme (the recording
proxy and the validated global proxy), but httpProxyTransport wrote
"http://" before it, so use_recording_proxy produced http://http://...
proxyURLString now adds http:// only to a bare host:port, for both the
operator proxy and ProxyAddr. httpToolTransport falls back to a fresh
http.Transport when http.DefaultTransport is not an *http.Transport.
@BaaRai
BaaRai merged commit 31e56a1 into main Nov 11, 2026
4 checks passed
@BaaRai BaaRai mentioned this pull request Nov 11, 2026
usinfosec pushed a commit to usinfosec/ARTEX that referenced this pull request Nov 17, 2026
fix(notify): 汇总模式退化、目的地留空误判、SMTP 缺 SSRF 守卫
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.

1 participant