Share one HTTP client and stop promcheck following redirects - #219
Conversation
httpcheck and promcheck each defined HTTPClient and RealHTTPClient. The
copies were identical except promcheck's never gained the CheckRedirect
guard, so `preflight prometheus` followed 3xx anywhere — including to
another host.
Go strips Authorization and Cookie across hosts but not custom headers, and
Mimir, Cortex, Thanos and Grafana Cloud carry tenancy in exactly those.
Reproduced against a Prometheus that 302s elsewhere:
X-Api-Key: SUPERSECRET arrived at the redirect destination
X-Scope-OrgID: tenant-42 arrived too
[OK] verdict came from the attacker's response body
So the destination both harvested the credentials and decided the check
passed.
pkg/httpclient now holds the single Client interface and Real implementation
with redirects off unless FollowRedirects is set, which is what httpcheck
already did and promcheck did not. This is the duplication causing the bug,
so removing the duplication is the fix rather than a cleanup alongside it.
The RealHTTPClient tests move to pkg/httpclient, where the type now lives.
|
Warning Review limit reached
Next review available in: 45 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #219 +/- ##
==========================================
+ Coverage 93.11% 93.19% +0.07%
==========================================
Files 49 50 +1
Lines 1873 1865 -8
==========================================
- Hits 1744 1738 -6
+ Misses 93 92 -1
+ Partials 36 35 -1
🚀 New features to boost your workflow:
|
httpcheckandpromcheckeach defined their ownHTTPClientandRealHTTPClient. The copies were identical except promcheck's never gained theCheckRedirectguard — sopreflight prometheusfollowed 3xx responses anywhere, including to another host.This is the clearest case in the review of duplication causing a security bug rather than merely being untidy, so removing the duplication is the fix.
The leak
Go strips
AuthorizationandCookiewhen a redirect crosses hosts, but not custom headers — and Mimir, Cortex, Thanos and Grafana Cloud carry tenancy in exactly those. Reproduced with a Prometheus that 302s to a different server:So the destination both harvested the credentials and decided the check passed.
promcheckhas no--follow-redirectsflag, so there was no way to opt out either.Change
pkg/httpclientholds the singleClientinterface andRealimplementation. Redirects are off unlessFollowRedirectsis set — what httpcheck already did, and promcheck did not.httpcheck's--follow-redirectsstill works as an explicit opt-in.InsecureSkipVerifynow appears exactly once in non-test code, where it previously appeared twice with two separate//nolint:gosecjustifications.Tests
TestRealHTTPClient_DoesNotFollowRedirectswas written first and confirmed red — it printed the leaked headers verbatim:It asserts both that credentials don't reach the destination and that a 302 is not a passing verdict. The existing
RealHTTPClienttests move topkg/httpclientalongside the type — including the redirects-enabled case, so the opt-in path stays covered.Suite green,
go vetclean on linux/darwin/windows.