Commit a4b2265
committed
Fix host validation: zone ID characters and NFKC percent bypass
Finding 1: IPv6 zone IDs were not validated even when validate_host=True.
Any character — including CR, LF, and null bytes — could be embedded in
url.host via URL.build(host='::1%<bad>'). This creates an asymmetry: regular
hostnames are correctly rejected for control characters but zone IDs were
passed through verbatim.
Fix: add _ZONE_ID_RE regex (RFC 6874 unreserved + sub-delims) and validate
the zone portion of IPv6 addresses in _encode_host() when validate_host=True.
Finding 2: _check_netloc() normalizes the netloc via NFKC and checks for
URL-reserved characters but '%' was missing from the checked set. U+FF05
(FULLWIDTH PERCENT SIGN) and U+FE6A (SMALL PERCENT SIGN) both normalize to
'%' under NFKC and were accepted, ultimately producing a literal '%' in
url.host via the stdlib IDNA fallback in _idna_encode().
Fix: add '%' to the character set checked in _check_netloc().1 parent 2f180d1 commit a4b2265
6 files changed
Lines changed: 48 additions & 1 deletion
File tree
- CHANGES
- tests
- yarl
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
2465 | 2467 | | |
2466 | 2468 | | |
2467 | 2469 | | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
38 | 53 | | |
39 | 54 | | |
40 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
| 99 | + | |
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
92 | 96 | | |
93 | 97 | | |
94 | 98 | | |
| |||
1574 | 1578 | | |
1575 | 1579 | | |
1576 | 1580 | | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
1577 | 1585 | | |
1578 | 1586 | | |
1579 | 1587 | | |
| |||
0 commit comments