Commit 2cb6e5d
Harden header/host control-char validation: unicode values + trailing newline
Two defense-in-depth gaps in the 2.7.18.14 header-injection backports
(CVE-2024-6923 / control-char cluster), surfaced in review of PR #85:
- wsgiref.headers._check_string only checked `str`, so a `unicode` header
name/value carrying control characters bypassed the guard and could still
be serialized. Check `basestring` instead.
- email.generator.NEWLINE_WITHOUT_FWSP used consuming character classes
([^ \t]) that require a following character, so a value ending in a bare
CR/LF/CRLF was not rejected -- the generator then appends its own newline,
prematurely terminating the header block. Add an end-of-string anchor so a
trailing bare CR/LF is caught too, and drop the redundant `\r\n` branch (a
CRLF that is not a valid fold is already matched by the lone-LF branch or
the end anchor) -- per PR #86 review. Valid CRLF folding is still permitted.
Regression tests extended in test_wsgiref (unicode names/values) and
test_email (trailing-newline values). A third review comment, about
urlparse._check_bracketed_host leaking TypeError from socket.inet_pton on
unicode hosts, does not reproduce: CPython 2.7's "s" arg parser encodes
unicode, so invalid hosts raise UnicodeEncodeError (a ValueError subclass)
or socket.error, both already handled.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent fdf0d24 commit 2cb6e5d
4 files changed
Lines changed: 22 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
91 | 97 | | |
92 | 98 | | |
93 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
312 | 317 | | |
313 | 318 | | |
| 319 | + | |
314 | 320 | | |
315 | 321 | | |
316 | 322 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
0 commit comments