fix: Only wrap IPv6 addresses in square brackets per RFC 3986 #4390
+104
−3
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.
Fixes #4389
Summary
This PR fixes a bug where Dex fails to initialize Kubernetes storage when the API server uses an IPv4 address. The issue occurs in Go 1.25.2+ and 1.24.8+ due to stricter RFC 3986 enforcement introduced as part of CVE-2025-47912.
Problem
The
inClusterConfig()function unconditionally wrapped all IP addresses in square brackets when constructing the Kubernetes API server URL:This violated RFC 3986, which specifies that only IPv6 addresses should be enclosed in brackets. While older Go versions accepted this, newer versions (1.25.2+, 1.24.8+) now correctly reject it:
Solution
Use
net.ParseIP()to detect the address type and only wrap IPv6 addresses:Results:
https://172.20.0.1:443(unwrapped, RFC compliant)https://[2001:db8::1]:443(wrapped, RFC compliant)Changes
storage/kubernetes/client.goTesting
Added
TestInClusterConfigIPv4IPv6covering:Backward Compatibility
Related