Repository navigation
fix(curl): follow protocol-relative redirects - #144
ferdingler merged 5 commits into
Conversation
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Verdict: approve, nothing blocking. Posted as a comment, so a maintainer's approval is still needed. @ferdingler
The fix does what #132 asks. Location: //host/path now resolves against the current scheme on the first and later hops, the same as curl 7.88.1. The allowlist, the SSRF guard, --proto-redir and credential handling treat it exactly like the same redirect written as an absolute URL.
Two non-blocking test comments are inline:
- 🟡
curl_protocol_relative_redirect_respects_proto_redirpasses without the fix. - 🟡 No test covers inheriting the scheme from an
httpsorigin.
✅ What was verified
Head b3cd4b6, base 5f80040, rustc 1.100.0, Debian 12 aarch64.
- Repo gates on head:
cargo test --workspace --all-targetsgave 2,573 passed, 0 failed, exit 0.cargo fmt --all -- --checkandcargo docwith-D warningsare clean.cargo clippy --workspace --all-targetsreports nothing in the two changed files. - Regression: with
src/commands/curl.rsfrom base,…preserves_target_and_strips_credentialsand…checks_target_allowlistfail; both pass on head. Removing either arm alone is caught too (redirectcovers the first-request arm,chainthe hop arm). - Against real curl 7.88.1, same local servers: 97 redirect cases across
-w '%{url_effective}',-v,-I,-i,-o,-f, 301–308, IPv6,//HOST,//host,//host?x=1and queries containing://. Head matches curl on exit code, servers hit and final path in 65. Of the other 32, 16 are malformedLocationvalues that curl rejects, 6 are cosmetic, and 10 are the older relative-path arms, unchanged by this PR. - Unchanged outside
//: 330Locationvalues that don't start with//behave the same on base and head. - SSRF and allowlist: 29 payloads on first and later hops, each sent protocol-relative and absolute (loopback,
localhost, IMDS, 10/8,[::1], v4-mapped, hex/decimal IPs,//allowed:port@blocked, backslash, tab). Protocol-relative on head equals absolute on head and base in 58/58, with no request to a server outside the allowlist. 1,550 fuzzed//…values: no request off the allowlisted source, no panic. - Credentials: injected bearer and query credentials,
-u,-band the-dbody are not sent to the target on either hop. - Scheme inheritance: works for
httpandhttpsagainst a local self-signed TLS server, and in one probe through the publichttps://httpbingo.org/redirect-to?url=//example.com/. - Stability: the three new tests ran 210 times with 0 failures.
- Not run: Python, Node and WASM suites; macOS and Windows.
Appendix — non-blocking (3)
- ⚪
https:/hostfalls back tohttp. A current URL spelled with a single slash has no://, somap_or("http", …)sends the protocol-relative hop over plain http; base kept https. The default kernel only accepts that spelling for an allowlisted host, so this is contrived.split_once(':')instead ofsplit_once("://")fixes it, andcurl_integrationstays 71/71 with that change. - Pre-existing, filed #342: a relative
Location: nameon a URL with no path resolves tohttp://name. After this PR aLocation: //hostwith no path leaves the URL in that form for the next hop. - A few other pre-existing observations in this area fall under
SECURITY.md, so they are not written up here. @ferdingler, ask me in a private channel for the details.
The test passed with the fix reverted, because --proto-redir '=https' refuses the unresolved http://source//target hop with the same message. Assert the resolved hop from -v so it fails without the fix.
Every origin in the protocol-relative tests was http, so hard-coding "http" for a //host Location still passed. A kernel that scripts HTTP replies lets the test start from https://source.test without a TLS server, and checks both the first request and a later hop.
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Verdict: approve, nothing open. Both findings from my last review are fixed. Posted as a comment, so a maintainer's approval is still needed. @ferdingler
- ✅ 🟡
…respects_proto_redirpasses without the fix: fixed in49e644c. The test now fails on the basecurl.rs. - ✅ 🟡 Nothing tests that the scheme is inherited: fixed in
f44d600. The new…keeps_https_schemetest catches a hard-coded"http"in either arm.
The delta since b3cd4b6 is test-only; src/commands/curl.rs is unchanged, so the earlier behavior checks still apply.
✅ What was verified
Head f44d600, base 5f80040, rustc 1.100.0, Debian 12 aarch64.
- Repo gates on head:
cargo test --workspace --all-targetsgave 2,574 passed, 0 failed, exit 0 (one more than atb3cd4b6).cargo fmt --all -- --checkandcargo docwith-D warningsare clean.cargo clippy --workspace --all-targetsreports nothing in the two changed files. CI is green onf44d600. - Regression: with
src/commands/curl.rsfrom base, all fourcurl_protocol_relative_*tests fail (4/4, exit 101). On head all four pass. - Scheme mutation (
|(scheme, _)| schemereplaced by|_| "http"),cargo test --test curl_integration curl_protocol_relative:- both arms:
…keeps_https_schemefails withhttp://target.test/hello. - first-request arm only: fails on the
redirectleg. - hop arm only: fails on the
chainleg.
- both arms:
- Hermetic:
ScriptedHttpKernelanswershttp_requestitself, so the.testhosts are never resolved or contacted. - Stability: the four tests ran 50 times with 0 failures.
- Not run locally: Python, Node and WASM suites; macOS and Windows (CI covers them).
Appendix — non-blocking (1)
- ⚪ Still open from the last review, contrived: a current URL spelled
https:/hostfalls back tohttpfor a//hop.split_once(':')fixes it.
Description
curl -Ltreats a protocol-relativeLocation: //host/pathas a path on the original server, so valid redirects reach the wrong destination. Resolve these references by preserving the current scheme and using the authority fromLocation, on both the initial request and subsequent redirect hops.Absolute URLs and ordinary relative paths retain their existing handling. URL allowlisting, DNS/IP checks, protocol restrictions, and credential injection are unchanged.
Related Issues
Fixes #132
Documentation PR
Not applicable: this restores the expected redirect behavior without changing the command's public interface.
Type of Change
Bug fix
Testing
cargo xtask check --rust-onlypassed on macOS arm64 with Rust 1.92: formatting, clippy, 1,808 Rust tests, and documentation generation with warnings denied. Clippy reports existing warnings in untouched files; none concern the changed files.The new redirect and target-allowlist regressions fail against the original implementation and pass with the fix. The local HTTP integration tests cover both first and later hops, target path/query preservation, injected credentials being stripped, blocked destinations, and
--proto-redirenforcement.Also exercised the built CLI against two local HTTP servers: direct and chained redirects returned the target's response when allowed and were denied when only the original server was allowed. No AWS or model calls were made.
Python, Node, and WASM binding suites and the cross-platform matrix were not run locally; their binding surfaces are unchanged.
cargo test --workspace --all-targets,pytest tests/python,npm test) — Rust core suite; other bindings not changedcargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.