Skip to content

fix: defuse HTTP origin SSRF and warn on non-loopback metrics_bind (#579) - #622

Merged
thiras merged 2 commits into
mainfrom
fix/579-origin-ssrf-metrics-bind
May 20, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/579-origin-ssrf-metrics-bind

Conversation

@thiras

@thiras thiras commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • HttpOrigin builds its reqwest::Client with redirect::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 to 169.254.169.254 (cloud metadata) or RFC-1918 internal addresses before BLAKE3 verification fires on the body.
  • metrics::bind emits tracing::warn! when bound to a non-loopback address (distinct message for is_unspecified() vs a specific public IP); preserves the documented 0.0.0.0 containerised workflow while flagging the OpenMetrics-surface exposure. Uses to_canonical() so v4-mapped IPv6 loopback doesn't false-positive.

Test plan

  • cargo build && cargo clippy --all-targets -- -D warnings clean
  • cargo fmt -- --check clean
  • cargo nextest run -p decdn-cache -p decdn-node — 328/328 pass
  • 4 redirect tests (301 / 302 / 307 / redirected-404) assert OriginError and prove the redirect target received zero requests via wiremock's received_requests(); assertion guarded by a received_requests_or_fail() helper that fails loudly on None so a future wiremock default flip cannot silently invalidate the SSRF proof.
  • http_origin_rejects_redirect_to_internal_address aims Location at http://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_loopback exercises IPv4 loopback, IPv6 ::1 (skipped if v6 disabled on the host), and 0.0.0.0; pins the predicate against a future narrowing that would regress on ::1.

Closes #579.

🤖 Generated with Claude Code

)

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]>
Copilot AI review requested due to automatic review settings May 20, 2026 18:45

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/node/src/metrics.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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’s reqwest::Client with redirect::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 /metrics binds 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.

Comment thread crates/cache/tests/pull_through.rs Resolved
Comment thread crates/cache/tests/pull_through.rs Resolved
Comment thread crates/cache/tests/pull_through.rs Resolved
Comment thread crates/cache/tests/pull_through.rs Resolved
@github-actions

github-actions Bot commented May 20, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 89.95% (was 89.98%, ▼ 0.02%) — 16723/18591 lines

File Coverage Lines Δ
crates/cache/src/origin/http.rs 93.43% 199/213 ▼ 3.66%
crates/node/src/metrics.rs 84.10% 349/415 ▲ +2.70%
History
Commit Total Δ vs base
a72f626 89.95% ▼ 0.03%
f1793fb (HEAD) 89.95% ▼ 0.02%

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]>
@thiras
thiras merged commit 7cfc5a0 into main May 20, 2026
11 checks passed
@thiras
thiras deleted the fix/579-origin-ssrf-metrics-bind branch May 20, 2026 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Origin pull-through SSRF + metrics_bind non-loopback warning

2 participants