Skip to content

Decode the IPv6 zone delimiter when parsing a URL - #1361

Open
Kludex wants to merge 4 commits into
mainfrom
parse-ipv6-zone
Open

Kludex wants to merge 4 commits into
mainfrom
parse-ipv6-zone

Conversation

@Kludex

@Kludex Kludex commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

A URL can name an IPv6 zone in two ways: [fe80::1%25en0], the RFC 6874 form, and the bare [fe80::1%en0]. The parser kept whatever was typed, so the two were different hosts:

import httpx2

url = httpx2.URL("http://[fe80::1%25en0]/")
print(url.host)  # before: fe80::1%25en0, now: fe80::1%en0
print(url)       # http://[fe80::1%25en0]/

The %25 form was passed to the socket as-is, so it never reached the interface. Against a server on fe80::1%lo0 (macOS):

URL Before Now
http://[fe80::1%lo0]:8768/ 204 204
http://[fe80::1%25lo0]:8768/ ConnectError: [Errno 65] No route to host 204

The zone is now parsed once, in encode_host():

  • URL.host and URL.raw_host hold the decoded form, fe80::1%en0. That is what the socket needs.
  • str(url) and URL.netloc always write %25, the form curl and Go write too.
  • Both spellings give the same URL and the same Origin.

Why it is safe for the same-origin check

#1134 kept the two spellings as distinct origins because the transport connected to different places for each. Decoding only inside Origin would have let a redirect keep Authorization while connecting elsewhere.

Here the decoding happens in the parser, so Origin and the transport read the same host. Only the %25 delimiter is decoded. [2001:db8::1%30] keeps the zone 30 and is still a different origin from [2001:db8::10].

Ambiguity

A bare zone that starts with 25, such as %251, is read as the RFC 6874 form, so the zone is 1. Write %25251 for a zone named 251. curl resolves it the same way.

This applies to URL text and to a bracketed host=. A host= without brackets is taken as the decoded form, so url.copy_with(host=url.host) never changes the zone.

Not included

  • The Host header still carries the zone. That is #1360.
  • httpcore2 still sends the zone in the proxy CONNECT target and as the TLS server_hostname.
  • The IPv6 address itself is not canonicalised in URL, only in Origin, as before.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

Session: pi --session 01a20ced-af54-7647-a636-b3d9c9458448

@veria-ai

veria-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T12:19:47.853358Z 5a88522 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codspeed

codspeed Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 18 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing parse-ipv6-zone (dc530d7) with main (538b256)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a88522986

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/httpx2/httpx2/_urlparse.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread src/httpx2/httpx2/_urlparse.py Resolved
Comment thread src/httpx2/httpx2/_urlparse.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

View guided diff | Re-trigger cubic

Comment thread tests/httpx2/models/test_url.py Resolved

This branch has not been deployed

No deployments
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.

1 participant