Skip to content

validate idna-encoded host against reg-name in _encode_host#1743

Draft
alhudz wants to merge 1 commit into
aio-libs:masterfrom
alhudz:encode-host-idna-reg-name-validation
Draft

validate idna-encoded host against reg-name in _encode_host#1743
alhudz wants to merge 1 commit into
aio-libs:masterfrom
alhudz:encode-host-idna-reg-name-validation

Conversation

@alhudz

@alhudz alhudz commented Jun 1, 2026

Copy link
Copy Markdown

_encode_host validates ASCII hosts against the reg-name grammar but sends non-ASCII hosts straight through _idna_encode, whose IDNA 2003 stdlib codec fallback does not reject reserved characters. A host like user:pass@bücher.example then keeps its @, : or / and yields a confusable authority. Running the same NOT_REG_NAME check on the encoded ASCII result makes with_host and URL.build reject these, while valid IDN hosts still encode normally. Fixes #955.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jun 1, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 97 untouched benchmarks


Comparing alhudz:encode-host-idna-reg-name-validation (e1fec9e) with master (6e784fb)

Open in CodSpeed

@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.90%. Comparing base (6e784fb) to head (e1fec9e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1743      +/-   ##
==========================================
+ Coverage   99.86%   99.90%   +0.04%     
==========================================
  Files          21       21              
  Lines        4310     4318       +8     
  Branches      252      253       +1     
==========================================
+ Hits         4304     4314      +10     
+ Misses          4        2       -2     
  Partials        2        2              
Flag Coverage Δ
CI-GHA 99.83% <100.00%> (+0.04%) ⬆️
OS-Linux 99.83% <100.00%> (+0.04%) ⬆️
OS-Windows 98.58% <100.00%> (+0.04%) ⬆️
OS-macOS 98.77% <100.00%> (+0.04%) ⬆️
Py-3.10 99.74% <100.00%> (+0.04%) ⬆️
Py-3.11 99.74% <100.00%> (+0.04%) ⬆️
Py-3.12 99.74% <100.00%> (+0.04%) ⬆️
Py-3.13 99.79% <100.00%> (+0.04%) ⬆️
Py-3.14 99.78% <100.00%> (+0.04%) ⬆️
Py-3.14t 99.78% <100.00%> (+0.04%) ⬆️
Py-pypy-3.11 99.42% <100.00%> (+0.04%) ⬆️
VM-macos-latest 98.77% <100.00%> (+0.04%) ⬆️
VM-ubuntu-latest 99.83% <100.00%> (+0.04%) ⬆️
VM-windows-latest 98.58% <100.00%> (+0.04%) ⬆️
pytest 99.83% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alhudz

alhudz commented Jun 21, 2026

Copy link
Copy Markdown
Author

gentle ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-ASCII hostnames are not validated and so allow "@" and other reserved gen-delims characters

1 participant