Repository navigation
fix(curl): follow relative redirects from a URL with no path - #344
ferdingler merged 4 commits into
Conversation
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Changes requested — one regression, small fix. The #342 fix itself is correct at both call sites and I found no allowlist, credential or --proto bypass. But Url::join("") returns the current URL, so a 3xx with an empty or non-ASCII Location now replays the original request (body and injected credential included) 10 more times; on main it sent it once. Details and a tested 4-line fix are inline.
✅ What I verified (head 6fdfd45 vs base dbb6189)
cargo test --workspace --all-targetson head: exit 0, 2,734 passed, 0 failed, 0 ignored.cargo test --test curl_integration: 73 passed.cargo fmt --checkexit 0;cargo clippy --workspace --all-targetsexit 0, no warnings in the touched files.- The new test fails on base (
http://hello/) and passes on head; reverting either call site fails it. 25 sequential + 40 parallel runs, no flakes. - Allowlist holds: 11 host-changing
Locationforms that now reachjoin(\\H/x,https:/H/x,http:/\H/x,ht<TAB>tp://H/x, …) × both call sites and a path-less URL all exit 1access denied; the non-allowlisted server got 0 requests. 24 SSRF spellings: 0 reached the blocked server. - Injected Bearer,
-u,-band the body are not sent on a hop to another allowlisted host, same as base. --proto/--proto-redirdecide on the resolved scheme; 40,000 randomLocationvalues under https-only flags sent 0 http URLs to the kernel, no panics.- A 27,061-case base/head differential: same effective URL except for empty, leading
?, leading#, leading\, and scheme-like first segment. - Not run: wasm32, Python and Node bindings; real-curl controls are 7.88.1 only.
Appendix — non-blocking (4)
- ⚪ Behaviour change worth knowing: a
Locationwhose first segment looks like a scheme (item:42,localhost:8080/x,data:,x) used to be followed as a path and now exits 1access denied: unsupported scheme. Real curl 7.88.1 also exits 1 on these, so this is closer to curl. - ⚪
src/commands/curl.rs:112: theErr(_)fallback has no test (changing it toloc.to_string()passes all 73 tests) and glues the strings, e.g.Location: https:requests…/dir/pagehttps:. Base produced different garbage; real curl exits 3. An error would be clearer than a request. - ⚪ The docstring names
../nameand?q; neither is asserted. Both work. - Pre-existing, not filed:
src/vfs_kernel.rs:941turns any non-ASCII header value into"", soLocation: /caféis never followed (real curl follows it). Say the word and I'll open an issue. One more pre-existing observation about request headers on cross-host redirects may fall under SECURITY.md, so I'm leaving it out of this thread; tell me where you'd like it.
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve at ae1a9f2. Previous finding: fixed. An empty or non-ASCII Location now sends the request once, and Location: ./new with --proto-redir '=https' exits 1 after one request, same as main and real curl. No new findings.
✅ What I verified (ae1a9f2, delta from 6fdfd45)
cargo test --workspace --all-targets: exit 0, 2,736 passed, 0 failed, 0 ignored.cargo fmt --checkexit 0;cargo clippy --workspace --all-targetsexit 0, nothing in the touched files.- My earlier repro (
adv_repro.rs) now passes 4/4: empty and/caféLocationgive 1 request each;./newwith--proto-redir '=https'gives 1 request and exit 1. - Both new tests fail with
src/commands/curl.rsreverted to 6fdfd45 (left: 11 right: 1andleft: 0 right: 1) and pass on ae1a9f2. - Attacked the fix: an empty
Locationon the second hop (/a→b→"") stops after 2 requests, body sent once, stdoutsecond302, exit 0.redirects_leftonly changes at the twocontinuesites, so hop count is a sound first-request test, including without-L(max_redirects = 0). - Not run: wasm32, Python and Node bindings.
Appendix — non-blocking (1)
- ⚪ The
.filter(|loc| !loc.is_empty())at the redirect-hop site (src/commands/curl.rs:552) has no test: removing it passes all 75curl_integrationtests, and the second-hop case above then makes 11 requests (10 bodyless, no credential). A/a→b→ empty case incurl_empty_redirect_location_is_not_followedwould pin it.
Description
When
curl -Lgot a redirect to a plain relative name likehello, it worked out the new URL by cutting the current one at its last slash. If the URL had no path (http://host:port), the last slash was the one after the scheme, so it tried to reach a host literally calledhelloand failed. A slash in the query or fragment threw it off the same way and landed on the wrong page.Now those relative redirects are resolved the standard way against the current page's path, ignoring its query and fragment. Absolute, protocol-relative and root-relative redirects are handled as before, and the allowlist still checks every hop.
Related Issues
Fixes #342
Documentation PR
None needed.
Type of Change
Bug fix
Testing
I added a test with a local server covering a URL with no path, one with a trailing slash, a slash in the query, a slash in the fragment, and a protocol-relative hop to a bare host followed by a relative one. On main the no-path cases errored and the query and fragment cases fetched the wrong page; with the fix all of them pass, and the full Rust suite passes.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo 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.