Commit c0ed690
fix(signing): expert-review fixes for key_origins consistency check
Folds three expert review passes into the stage 4 PR (ad-tech-protocol-expert,
code-reviewer, security-reviewer all run in parallel on the original
commit 62d2379).
**1. Spec-mandated structured detail fields (MUST-FIX, protocol expert)**
ADCP #3690 security.mdx step 7 mandates that
``request_signature_key_origin_mismatch`` carry
``{purpose, expected_origin, actual_origin}`` and
``_key_origin_missing`` carry ``{purpose, posture}`` as structured
fields, not just an opaque message string. Middleware adapters surface
them on the 401 / in a DLQ; without this, the SDK can't be spec-
conformant once Stage 5 wires the verifier.
- Extend ``SignatureVerificationError`` with optional
``detail: Mapping[str, str] | None``. ``str(exc)`` still renders the
free-form message for unstructured logs; structured callers read
``exc.detail``.
- ``check_key_origin_consistency`` now passes the spec-mandated keys.
- Two new tests pin the detail shape for both code paths.
**2. Bare-host vs URL canonicalization asymmetry (HIGH, security reviewer)**
The previous ``_origin_host`` fallback path for bare-host inputs only
guarded against ``/`` and space — accepting ``user@host``,
``host:port``, ``host?query``, ``host#fragment`` verbatim. An attacker
with capability-write access could declare a bare-host-with-port
(``keys.brand.com:8443``) to force a mismatch against the operator's
brand.json origin and DoS the honest verification path.
Fix: factor a ``_extract_host`` helper that re-parses bare-host inputs
through ``urlsplit`` with a synthetic ``https://`` scheme prepended.
URL form and bare-host form now strip port / userinfo / query /
fragment symmetrically. Two new tests cover ``host:port`` and
``user@host`` declaration shapes.
**3. Trailing-dot FQDN asymmetry (HIGH, security reviewer)**
``host.example.`` and ``host.example`` are the same FQDN — the trailing
dot denotes the root zone. Previous code preserved the dot, so a
brand.json serving the dot form against a capability declaring the
no-dot form (or vice versa) byte-mismatched. An attacker controlling
capabilities could weaponize this to deny verification against the
real counterparty.
Fix: strip a single trailing dot before IDNA-encoding. Test covers
both directions.
**4. IDN U-label vs A-label equivalence test (NICE, all three)**
The docstring promised IDN canonicalization but no test exercised it.
Added a test using ``münchen.example`` ↔ ``xn--mnchen-3ya.example``
in both directions.
**5. Carve-out for publisher-pin source in function docstring (MEDIUM, security)**
Previously the publisher-pin skip was documented only in the module
docstring. A caller reading just the function doc would miss it. Added
a "Caller contract" paragraph at the top of the function docstring
flagging that callers MUST skip this call for publisher-pinned tuples.
**6. Symmetric fail-closed test on declared side (LOW, security)**
The existing ``test_consistency_raises_mismatch_on_invalid_jwks_uri``
covers the resolved side but not the declared side. Added a symmetric
test so a future refactor can't silently invert the fail direction on
one side.
**Deferred to follow-up issues** (not in scope for this PR):
- Plumbing the ``source`` discriminant ("brand.json walk" vs
"publisher adagents.json pin") through ``BrandJsonJwksResolver`` so
Stage 5 can enforce the carve-out automatically. Belongs in the
Stage 5 verifier-integration PR.
- Migrating all four codebase callsites (jwks.py, ip_pinned_transport.py,
revocation_fetcher.py, key_origins.py) from stdlib IDNA-2003 to the
``idna`` PyPI package's IDNA-2008 in one commit. Package-wide
conformance pass, separate concern.
Tests: 20 in test_key_origins (up from 12). Full signing surface
(582 tests across tests/test_*.py + tests/conformance/signing/)
remains green. ruff + mypy clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 62d2379 commit c0ed690
3 files changed
Lines changed: 230 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
13 | 25 | | |
14 | 26 | | |
15 | 27 | | |
16 | 28 | | |
17 | 29 | | |
18 | 30 | | |
19 | 31 | | |
| 32 | + | |
20 | 33 | | |
21 | 34 | | |
22 | 35 | | |
23 | 36 | | |
| 37 | + | |
24 | 38 | | |
25 | 39 | | |
26 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
77 | 87 | | |
78 | 88 | | |
79 | 89 | | |
| |||
91 | 101 | | |
92 | 102 | | |
93 | 103 | | |
94 | | - | |
| 104 | + | |
95 | 105 | | |
96 | 106 | | |
97 | 107 | | |
| |||
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
103 | | - | |
104 | | - | |
105 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
106 | 121 | | |
107 | 122 | | |
108 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
109 | 127 | | |
110 | 128 | | |
111 | 129 | | |
112 | 130 | | |
113 | 131 | | |
114 | 132 | | |
115 | 133 | | |
| 134 | + | |
116 | 135 | | |
117 | 136 | | |
118 | 137 | | |
| |||
125 | 144 | | |
126 | 145 | | |
127 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
128 | 156 | | |
129 | 157 | | |
130 | 158 | | |
| |||
142 | 170 | | |
143 | 171 | | |
144 | 172 | | |
145 | | - | |
146 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
147 | 193 | | |
148 | | - | |
149 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
150 | 198 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 199 | + | |
157 | 200 | | |
158 | 201 | | |
159 | 202 | | |
160 | 203 | | |
161 | 204 | | |
162 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
163 | 231 | | |
164 | 232 | | |
165 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
0 commit comments