Skip to content

[BUG] curl -L resolves a protocol-relative Location: //host/path as a path on the current host #132

Closed

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Binding

Rust

Strands Shell Version

main @ 8f29276 (also present on #131's branch)

Language Runtime Version

Rust 1.99.0

Operating System

Amazon Linux 2023 (aarch64)

Installation Method

Source

Steps to Reproduce

Server returns 307 with Location: //other-host:8080/hello (protocol-relative, legal per RFC 3986 §4.2 / RFC 7231 §7.1.2).

curl -sSL http://127.0.0.1:PORT/redirect-proto-rel

Expected Behavior

Follow to http://other-host:8080/hello (same scheme as the current URL), as real curl does.

Actual Behavior

The builtin only treats scheme://… as absolute, so //other-host:8080/hello falls into the starts_with('/') branch and is appended to the current origin: http://127.0.0.1:PORT//other-host:8080/hello → 404 (or whatever that path returns).

src/commands/curl.rs (redirect resolution in cmd_curl):

} else if loc.starts_with('/') {
    let scheme_end = current_url.find("://").map(|i| i + 3).unwrap_or(0);
    let host_end = current_url[scheme_end..].find('/').map(|i| i + scheme_end).unwrap_or(current_url.len());
    format!("{}{loc}", &current_url[..host_end])

Reproduced with a temporary axum route in tests/curl_integration.rs during review of #131 (pre-existing; identical on main).

Additional Context

Note the kernel's check_url still runs on the resolved URL, so this is a wrong-destination bug, not a sandbox escape.

Possible Solution

Before the starts_with('/') branch: if let Some(rest) = loc.strip_prefix("//") { format!("{scheme}://{rest}") } using the current URL's scheme. Or resolve Location with url::Url::join (the url crate is already a dependency), which handles all RFC 3986 relative forms.

Related Issues

Found while reviewing #131 (not introduced by it).

Activity

  1. ikenyal commented on Oct 11, 2026

    @ikenyal
    Contributor

    I would like to take this on with a small fix for protocol-relative redirects, plus regression tests for both the first and later redirect hops. I will keep the existing URL checks and credential handling unchanged.

  2. added
    bug
    on Nov 2, 2026
  3. added theissue type on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions