Skip to content

Commit 8b1f333

Browse files
jkyberneeesclaude
andcommitted
harden(ssrf): fail safe if http.DefaultTransport was globally replaced
vprotocol axis 2.4: ssrfGuardedTransport ran at startup with an unchecked http.DefaultTransport.(*http.Transport) assertion. A third-party package that swaps the global for a custom RoundTripper would panic odek at boot. Use a checked assertion with a fresh-transport fallback. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 77812e4 commit 8b1f333

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

cmd/odek/ssrf_guard.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,21 @@ func ssrfGuardedDial(base dialFunc, lookup ipLookupFunc) dialFunc {
8080
}
8181
}
8282

83-
// ssrfGuardedTransport returns an *http.Transport (cloned from the default so
84-
// it keeps sane timeouts, proxy handling, and HTTP/2) whose DialContext is the
85-
// SSRF guard above, backed by the real dialer and resolver.
83+
// ssrfGuardedTransport returns an *http.Transport whose DialContext is the SSRF
84+
// guard above, backed by the real dialer and resolver. It clones the default
85+
// transport when possible so it inherits sane defaults (env proxy handling,
86+
// idle-conn limits, HTTP/2, TLS handshake timeout); if a third-party package
87+
// has swapped http.DefaultTransport for a non-*http.Transport RoundTripper, it
88+
// falls back to a fresh transport with explicit proxy handling rather than
89+
// panicking on the type assertion — this runs at startup, so it must fail safe.
8690
func ssrfGuardedTransport() *http.Transport {
8791
base := &net.Dialer{Timeout: 30 * time.Second, KeepAlive: 30 * time.Second}
88-
tr := http.DefaultTransport.(*http.Transport).Clone()
92+
tr, ok := http.DefaultTransport.(*http.Transport)
93+
if ok {
94+
tr = tr.Clone()
95+
} else {
96+
tr = &http.Transport{Proxy: http.ProxyFromEnvironment}
97+
}
8998
tr.DialContext = ssrfGuardedDial(base.DialContext, net.DefaultResolver.LookupIPAddr)
9099
return tr
91100
}

0 commit comments

Comments
 (0)