Skip to content

[BUG] curl -L resolves a relative Location: name to the wrong host when the URL has no path #342

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 @ 2664aa7 (src/commands/curl.rs is identical at 5f80040, where this was run)

Language Runtime Version

Rust 1.100.0

Operating System

Debian 12 (aarch64)

Installation Method

built from source

Steps to Reproduce

A server answers GET / with 302 and Location: hello (a relative reference with no leading slash), and serves /hello. The origin is in allowed_urls.

curl -sSLv http://127.0.0.1:PORT      # no trailing slash

Expected Behavior

Follow to http://127.0.0.1:PORT/hello and print its body, as real curl does and as the same command with a trailing slash already does here.

Actual Behavior

* Redirecting to http://hello
curl: (6) error sending request for url (http://hello/)

Exit status 6. The redirect target's name becomes the host. With a trailing slash (http://127.0.0.1:PORT/) the same redirect resolves correctly and exits 0.

Additional Context

The last arm of the redirect resolution in cmd_curl (src/commands/curl.rs:484-489, repeated at :561-566) takes everything up to the last / of the current URL as the base:

let base = current_url
    .rfind('/')
    .map(|i| &current_url[..i + 1])
    .unwrap_or(&current_url);
format!("{base}{loc}")

For http://127.0.0.1:PORT the last / is the one in ://, so the base is http://.

From reading the same code, and not run: a current URL whose query contains a / (http://host/a?next=/x/y) would also pick a base inside the query string.

The kernel's check_url still runs on the resolved URL, so this is a wrong-destination bug, not a sandbox escape. Once #144 merges, a protocol-relative Location: //host with no path leaves the current URL in this path-less form, so a relative redirect on the next hop hits it too.

Reproduced with a temporary axum route in tests/curl_integration.rs while reviewing #144 (not introduced by it).

Possible Solution

Resolve Location with url::Url::join (the url crate is already a dependency), which handles every RFC 3986 relative form. A narrower fix is to cut the query and fragment off first and treat a URL with no path as /.

Related Issues

#132, #144

Activity

  1. added
    bug
    on Nov 21, 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