Commit cdb0ed4
fix(signing): validate the port per RFC 3986 instead of trusting int()
Review follow-up. `_malformed_authority_reason` judged the host but never the
port, so `portstr` went straight into `int()` -- far more permissive than the
grammar `port = *DIGIT`, in three distinct ways:
- `int("-80")` produced the authority `host:-80`, which is not an authority.
- `int("8_0")` is 80: Python accepts underscore digit separators.
- `int("٨٠")` is also 80: `int()` accepts non-ASCII digits, so `host:٨٠` and
`host:80` collapsed to the SAME canonical authority. That is a
raw-vs-canonical differential -- a peer that does not fold Arabic-Indic
digits derives a different @authority from identical bytes and the signature
fails for a reason neither side can see in its own logs.
`str.isdigit()` does NOT close the third case -- `"٨٠".isdigit()` is True --
so the gate tests ASCII digits specifically.
An empty port is NOT rejected. RFC 3986 §3.2.3 makes it legal (`*DIGIT`),
meaning "default", and directs normalizers to drop the port and its colon, so
`https://host:/p` normalizes to `host`. `urlsplit` agrees (`port=None`).
Rejecting it would refuse a valid URI; it previously raised a bare `ValueError`
from `int("")` carrying no code -- the same "passes on someone else's
exception" failure `_split_or_reject` exists to prevent, one frame lower.
Refs #978.1 parent d0c626a commit cdb0ed4
2 files changed
Lines changed: 77 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
236 | 236 | | |
237 | 237 | | |
238 | 238 | | |
239 | | - | |
| 239 | + | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| |||
248 | 248 | | |
249 | 249 | | |
250 | 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 | + | |
251 | 284 | | |
252 | 285 | | |
253 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 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 | + | |
0 commit comments