Skip to content

Commit 53f4fbf

Browse files
pre-commit-ci[bot]andrewkernel
authored andcommitted
Reject invalid HTTP method token characters
Validate parsed HTTP methods against the RFC token character set before accepting the request line. This rejects methods containing invalid token characters with a 400 Bad Request response and covers the behavior with a focused regression test.
1 parent ede37bd commit 53f4fbf

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

cheroot/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
FORWARD_SLASH = b'/'
163163
QUOTED_SLASH = b'%2F'
164164
QUOTED_SLASH_REGEX = re.compile(b''.join((b'(?i)', QUOTED_SLASH)))
165-
HTTP_TOKEN_RE = re.compile(br"^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$")
165+
HTTP_TOKEN_RE = re.compile(rb'^[!#$%&\'*+\-.^_`|~0-9A-Za-z]+$')
166166

167167

168168
_STOPPING_FOR_INTERRUPT = Exception() # sentinel used during shutdown
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rejected HTTP methods containing characters that are invalid in HTTP tokens.

0 commit comments

Comments
 (0)