Commit 977322d
committed
fix(signing): idna-normalize hosts in etld+1 binding
tldextract is IDNA-agnostic: given a U-label it returns a U-label. Because
host_from only case-folded, registrable_domain emitted 'straße.de' for the
U-label spelling and 'xn--strae-oqa.de' for the A-label spelling of the same
host, so same_registrable_domain compared two strings that can never be equal
and returned False.
That predicate is step 2a of the brand-authorization binding
(brand_authz.py:255) and the redirect-containment gate (adagents.py:404). A
brand whose brand.json and agent URL disagreed on spelling had its legitimate
agent refused with reason="binding_failed"; the authorized_operators[] fallback
compared the same mis-normalized values and missed too. Nothing was wrongly
accepted, but a correct agent could not bind.
Both branches of host_from now delegate to _idna_canonicalize.canonicalize_host
— the same normalizer jwks, revocation_fetcher and key_origins already use.
etld was the last signing module still on a bare .lower() after PR #777. That
also fixes a second asymmetry the old docstring got wrong: the URL branch
trimmed no trailing root dot while the bare-host branch trimmed all of them, so
'https://Example.COM./' and 'Example.COM.' normalized differently.
registrable_domain maps idna.IDNAError onto None rather than letting it
propagate or falling back to the raw string. Fail-closed is deliberate:
- Propagating is not viable. IDNAError is a ValueError subclass, so it would
be silently reclassified as brand_domain_invalid at one callsite and escape
uncaught at five others mid-verification.
- Failing open would loosen an existing check. adagents._idna_ascii_host is
today the only gate rejecting an IDNA-invalid redirect target
(_check_safe_host does not reject underscores). With a raw-string fallback,
'under_score.brand.com' would reduce to 'brand.com', match the origin, and
the redirect would be accepted.
- It widens a category the module already documents rather than inventing a
contract: a string that is not an encodable hostname has no derivable
eTLD+1, alongside IP literals and single-label hosts.
The cost, stated plainly: hosts with an underscore label, a label over 63
bytes, or a leading/trailing-hyphen label now yield None instead of an eTLD+1.
These are not valid hostnames per RFC 952/1123 and cannot appear in a fetchable
https:// agent URL, but this is the one place an agent that binds today stops
binding.
Adopter-visible: registrable_domain and host_from are public exports and now
return A-labels for IDN input; host_from additionally raises on IDNA-invalid
input where it previously returned the string unchanged. Both sides of
same_registrable_domain move together, so the predicate stays correct.
adagents._idna_ascii_host is left in place — canonicalize_host is idempotent on
the A-label output it produces, so it becomes a harmless double normalization.
Removing that duplicate belongs in a follow-up that touches adagents.
Fixes #9881 parent 1ca7e07 commit 977322d
2 files changed
Lines changed: 169 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
26 | 36 | | |
27 | 37 | | |
28 | 38 | | |
29 | 39 | | |
30 | 40 | | |
31 | 41 | | |
32 | 42 | | |
| 43 | + | |
33 | 44 | | |
34 | 45 | | |
| 46 | + | |
| 47 | + | |
35 | 48 | | |
36 | 49 | | |
37 | 50 | | |
| |||
58 | 71 | | |
59 | 72 | | |
60 | 73 | | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
65 | 87 | | |
66 | 88 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
70 | 95 | | |
71 | 96 | | |
72 | 97 | | |
| |||
75 | 100 | | |
76 | 101 | | |
77 | 102 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
83 | 110 | | |
84 | 111 | | |
85 | 112 | | |
| |||
92 | 119 | | |
93 | 120 | | |
94 | 121 | | |
95 | | - | |
96 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
97 | 133 | | |
98 | 134 | | |
99 | 135 | | |
100 | 136 | | |
101 | 137 | | |
102 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
103 | 142 | | |
104 | 143 | | |
105 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
0 commit comments