Repository navigation
Conversation
…, and OIDC JWKS client
There was a problem hiding this comment.
Code Review
This pull request introduces several security and resource management improvements. It hardens the generic auth service by using a secure HTTP client for JWKS fetching, introducing a Close method to cancel background refresh goroutines, and ensuring replaced or shut down auth services are properly closed. It also enhances SSRF protection by expanding blocked non-global IP ranges using netip and stripping sensitive headers on cross-origin redirects. Additionally, the HTTP tool's URL construction is refactored to prevent query string or fragment injection via path parameters. Feedback on these changes suggests updating the Close method receiver in AuthService to a pointer receiver to avoid copying the struct.
|
/gcbrun |
Description
Hardens the HTTP source, HTTP tool, and generic OIDC auth service against SSRF bypasses, path parameter smuggling, cross-origin credential leakage on redirects, and unhardened JWKS HTTP fetches (tracking b/587679837 and b/591501548).
Summary of Changes
internal/sources/http/http.go):net/netip.AddrFromSliceandUnmap()whenAllowPrivateNetworksis false so IPv4-mapped IPv6 addresses (e.g.::ffff:127.0.0.1,::ffff:169.254.169.254) receive the same checks as IPv4.!addr.IsGlobalUnicast() || addr.IsPrivate()plus IANA special-purpose and transition ranges missing from Go stdlib:0.0.0.0/8,100.64.0.0/10,192.0.0.0/24,192.0.2.0/24,198.18.0.0/15,198.51.100.0/24,203.0.113.0/24,240.0.0.0/4,::/96,64:ff9b::/96,64:ff9b:1::/48,100::/64,2001::/23,2001:db8::/32,2002::/16, andfec0::/10, while preservingAllowedRangesandCustomBlockedprecedence.Initialize, dialerControl, andCheckRedirect.internal/sources/http/http.go):createHTTPClientCheckRedirectto detect cross-origin redirects across all prior hops invia(normalizing scheme, case-insensitive hostname, IPv6 brackets, and default ports80/443), including for IP-literal redirects.A -> B -> Abounces), stripped all headers except safe non-credential negotiation headers (User-Agent,Accept,Accept-Encoding,Accept-Language), droppingX-Api-Key,Authorization,Cookie, and customheaderParams. Same-origin redirects preserve all headers.internal/tools/http/http.go):pathtemplate at its first?before template execution.?and#in the rendered path portion (and#injection in rendered query templates) so unescaped{{.param}}values cannot smuggle query parameters or fragments, while keeping{{pathEscape .param}}and static query templates working without double escaping.internal/auth/generic/generic.go,internal/server/primitives/primitives.go,internal/server/server.go):keyfunc.NewDefaultwithkeyfunc.NewDefaultOverrideCtxusing a cancelable context andhttpClient(newSecureHTTPClient(), 10s timeout,CheckRedirectreturninghttp.ErrUseLastResponse).AuthService.Close()and closed replaced/stopped auth services onPrimitiveManager.SetPrimitivesandServer.Shutdownso background JWKS refresh goroutines do not leak on reload or shutdown.Security Verification & Tests Run
gofmt -l .(clean)go vet ./...go build ./...go mod tidy && git diff --exit-code go.mod go.sumgo test -race -count=1 ./internal/sources/http/... ./internal/tools/http/... ./internal/auth/... ./internal/server/primitives/... ./internal/servergo test -race ./internal/auth/... ./internal/server/... ./cmd/...go test -run '^$' ./tests/http ./tests/auth(compile check)PR Checklist