cargo icon indicating copy to clipboard operation
cargo copied to clipboard

`cargo search` doesn't follow redirects

Open gtirloni opened this issue 7 months ago • 1 comments

Problem

If a registry is redirecting the request to a different location, cargo search will fail with the following error (trimmed):

error: failed to retrieve search results from the registry at https://example.com/my_repo

Caused by:
  failed to get a 200 OK response, got 302
  headers:
  	HTTP/2 302
  	location: https://example.org/some_path/api/v1/crates?q=log&per_page=10
  	
  body:
  <html>
  <head><title>302 Found</title></head>
  <body>
  <center><h1>302 Found</h1></center>
  </body>
  </html>

Steps

  1. setup a registry that redirects
  2. cargo search --index 'sparse+https://example.com/my_repo' some_package

Possible Solution(s)

Follow redirects

Notes

No response

Version

cargo 1.87.0 (Homebrew)
release: 1.87.0
host: aarch64-apple-darwin
libgit2: 1.9.0 (sys:0.20.0 system)
libcurl: 8.7.1 (sys:0.4.80+curl-8.12.1 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 15.5.0 [64-bit]

gtirloni avatar May 24 '25 09:05 gtirloni

Possible Solution(s)

Follow redirects

Note that the change in #15593 not only affects cargo search but also other registry related commands. I wonder if there is any security implication. That said, yes, when downloading crate index and tarballs, Cargo already follows redirections.

@0xPoe, any thought?

weihanglo avatar May 24 '25 16:05 weihanglo