Skip to content

Fix wheel metadata reads after redirects - #21347

Open
dimbleby wants to merge 1 commit into
astral-sh:mainfrom
dimbleby:fix/range-metadata-redirects
Open

Fix wheel metadata reads after redirects#21347
dimbleby wants to merge 1 commit into
astral-sh:mainfrom
dimbleby:fix/range-metadata-redirects

Conversation

@dimbleby

Copy link
Copy Markdown

When a wheel URL redirected, the HEAD request followed the redirect but the range requests still used the original URL. Their HTTP client did not follow redirects, so metadata reads failed and uv downloaded whole wheels.

Use the final URL from the HEAD response for range requests. Drop the original Authorization header when that URL is in a different auth realm.


A healthy assist from the AI on this: but I am a human in the loop and it looks good to me.

Tested live against a feed that does not support PEP658 but does support range requests; which is what prompted the investigation.

When a wheel URL redirected, the HEAD request followed the redirect but
the range requests still used the original URL. Their HTTP client did not
follow redirects, so metadata reads failed and uv downloaded whole wheels.

Use the final URL from the HEAD response for range requests. Drop the
original Authorization header when that URL is in a different auth realm.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7cad5dd5-3d0d-4a32-8c4b-852d920b7978
@zanieb zanieb self-assigned this Aug 28, 2026
@zanieb

zanieb commented Aug 28, 2026

Copy link
Copy Markdown
Member

👋 thanks for the pull, I'll take a look.

In what context did you encounter this?

@dimbleby

Copy link
Copy Markdown
Author

In what context did you encounter this?

the day job has moved us to using an Azure Artifacts feed, at which point resolution started downloading whole wheels

@zanieb

zanieb commented Aug 28, 2026

Copy link
Copy Markdown
Member

This sounded familiar so I pulled some history with Codex, I think there's a bunch of nuance we'll need to consider here:

@astral-sh-bot

astral-sh-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

uv test inventory changes

This PR changes the tests when compared with the main base revision.

  • Added tests: 1
  • Removed tests: 0
  • Changed suites: 1
uv-client::it: +1 / -0

Added:

  • uv-client::it::remote_metadata::remote_metadata_uses_head_redirect_target_for_range_requests

Removed: none

@dimbleby

dimbleby commented Aug 28, 2026

Copy link
Copy Markdown
Author

What fun...

I had found #18998 and decided it wasn't the same: our HEAD does advertise "Accepts-Ranges: bytes", whereas the other seems to be saying that: even if a HEAD does not advertise support, that might not mean much.

But I didn't spot the others, and it seems this is going to be more complicated than I probably want for a drive-by fix.

Shall I raise an issue report instead?

@zanieb

zanieb commented Aug 28, 2026

Copy link
Copy Markdown
Member

If you want to open an issue with details about what happened and some logs that'd be great.

I will probably add some more test coverage and weigh a couple different approaches here. I haven't really decided if this change is correct or if something else is more appropriate, I have to refresh my memory on all that context.

@dimbleby

Copy link
Copy Markdown
Author

AFAIK the testcase here is an accurate representation of the observed real world behaviour (and fails without the fix) so I will just reference that unless you want something specific.

@thomasaarholt

Copy link
Copy Markdown

Hi @zanieb, we're a few folks at Microsoft discussing this right now.

We can test against a new PyPI proxy feed which is open to the public. It doesn't support PEP 658, but should support range requests. https://packagefeedproxy.microsoft.io/pypi/simple

We can create an issue with some more context.

@zanieb

zanieb commented Aug 28, 2026

Copy link
Copy Markdown
Member

Thanks a public registry is super helpful here.

What level of urgency is this for ya'll?

@thomasaarholt

Copy link
Copy Markdown

Thanks for asking. It would be great to get in a fix in the next week or so, but no-one is fully blocked here.

@thomasaarholt

Copy link
Copy Markdown

I had my own Opus instance have a go at this, and it came up with a very similar solution, branch here. Sol had a go too, but I think it went a bit overboard trying to make things secure.

Very cool to see the automations bot at work here! Thanks for taking the time.

zanieb added a commit that referenced this pull request Aug 29, 2026
Wheel metadata extraction takes a different path for redirects depending
on whether range requests stay within an origin, cross origins, or
receive method-specific targets. Capture the current behavior for all
three cases, including source credential propagation, cross-origin
credential stripping, destination credentials, and the existing
streaming fallback.

This provides an explicit behavioral baseline for #21347 and
its follow-up implementation.

These are unit tests overlapping with
#21350

---------

Co-authored-by: Zanie Blue <contact@zanie.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants