Repository navigation
fix: defuse HTTP origin SSRF and warn on non-loopback metrics_bind (#579) - #622
Conversation
) HttpOrigin builds its reqwest client with redirect::Policy::none() and refuses any 3xx with a typed permanent error naming SSRF as the reason — closes the window where a compromised or misconfigured origin could 3xx-redirect pull-through to 169.254.169.254 (cloud metadata) or RFC-1918 internal addresses before BLAKE3 verification fires on the body. Origins must serve {base}/{hex} directly anyway (query/fragment are already rejected by parse_origin_url), so a redirect was never a legitimate response shape. metrics::bind emits tracing::warn! when bound to a non-loopback address, with a distinct message for is_unspecified() versus a specific public IP, preserving the documented 0.0.0.0 containerised workflow while flagging the OpenMetrics-surface exposure. Uses to_canonical() so v4-mapped IPv6 loopback (::ffff:127.0.0.1) doesn't false-positive. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements SSRF defenses by disabling HTTP redirects in the cache origin and adding warnings when the metrics server binds to non-loopback addresses. It also updates the test suite to verify that redirects are rejected and that internal addresses are not contacted. A critical issue was identified in the metrics binding logic where calling to_canonical() on an IpAddr enum will cause a compilation error, as that method is only available on specific IP address types.
There was a problem hiding this comment.
Pull request overview
This PR hardens the cache HTTP origin against SSRF by disabling automatic HTTP redirects, and improves operational safety by warning when the node’s OpenMetrics endpoint is bound to a non-loopback address.
Changes:
- Build
HttpOrigin’sreqwest::Clientwithredirect::Policy::none()and treat any 3xx response as a permanent origin error. - Add/adjust pull-through integration tests to assert redirects are rejected and redirect targets receive zero requests (SSRF-proofing).
- Emit
tracing::warn!when/metricsbinds to non-loopback addresses (with a distinct message for unspecified “all interfaces” binds), plus a smoke test for bind behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
crates/node/src/metrics.rs |
Warn on non-loopback metrics binds (including 0.0.0.0 / ::) and add a smoke test covering loopback/unspecified cases. |
crates/cache/src/origin/http.rs |
Disable redirects in the HTTP origin client and explicitly reject 3xx responses to close the redirect-based SSRF window. |
crates/cache/tests/pull_through.rs |
Update redirect-related tests to validate redirect rejection and “no requests to redirect target” behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 89.95% (was 89.98%, ▼ 0.02%) — 16723/18591 lines
History
|
Copilot review on PR #622 noted that the 302/301/307/redirect-to-404 tests asserted only "target got 0 requests" — a fetch that errored before issuing any HTTP request would pass vacuously. Mirror the pattern from http_origin_rejects_redirect_to_internal_address by also asserting redirect_server got exactly 1 hit, so the SSRF proof is non-vacuous. Also drop the now-stale "three" count in the received_requests_or_fail doc (there are five callers). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
HttpOriginbuilds itsreqwest::Clientwithredirect::Policy::none()and refuses any 3xx with a typed permanent error — closes the SSRF window where a compromised or misconfigured origin could 3xx-redirect pull-through to169.254.169.254(cloud metadata) or RFC-1918 internal addresses before BLAKE3 verification fires on the body.metrics::bindemitstracing::warn!when bound to a non-loopback address (distinct message foris_unspecified()vs a specific public IP); preserves the documented0.0.0.0containerised workflow while flagging theOpenMetrics-surface exposure. Usesto_canonical()so v4-mapped IPv6 loopback doesn't false-positive.Test plan
cargo build && cargo clippy --all-targets -- -D warningscleancargo fmt -- --checkcleancargo nextest run -p decdn-cache -p decdn-node— 328/328 passOriginErrorand prove the redirect target received zero requests via wiremock'sreceived_requests(); assertion guarded by areceived_requests_or_fail()helper that fails loudly onNoneso a future wiremock default flip cannot silently invalidate the SSRF proof.http_origin_rejects_redirect_to_internal_addressaimsLocationathttp://127.0.0.1:1/...and asserts the redirect source received exactly 1 hit — proving the 3xx is the terminal response and no follow-up TCP attempt was made.bind_accepts_loopback_and_warns_on_non_loopbackexercises IPv4 loopback, IPv6::1(skipped if v6 disabled on the host), and0.0.0.0; pins the predicate against a future narrowing that would regress on::1.Closes #579.
🤖 Generated with Claude Code