Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-143916: Reject control characters in wsgiref.headers.Headers (GH-143917)#143972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 1 commit intopython:3.14frommiss-islington:backport-f7fceed-3.14
Jan 17, 2026
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionsLib/test/support/__init__.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3216,3 +3216,10 @@ def linked_to_musl():
return_linked_to_musl
_linked_to_musl=tuple(map(int,version.split('.')))
return_linked_to_musl


defcontrol_characters_c0()->list[str]:
"""Returns a list of C0 control characters as strings.
C0 control characters defined as the byte range 0x00-0x1F, and 0x7F.
"""
return [chr(c)forcinrange(0x00,0x20)]+ ["\x7F"]
12 changes: 11 additions & 1 deletionLib/test/test_wsgiref.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
fromunittestimportmock
fromtestimportsupport
fromtest.supportimportsocket_helper
fromtest.supportimportsocket_helper,control_characters_c0
fromtest.test_httpserversimportNoLogRequestHandler
fromunittestimportTestCase
fromwsgiref.utilimportsetup_testing_defaults
Expand DownExpand Up@@ -503,6 +503,16 @@ def testExtras(self):
'\r\n'
)

deftestRaisesControlCharacters(self):
headers=Headers()
forc0incontrol_characters_c0():
self.assertRaises(ValueError,headers.__setitem__,f"key{c0}","val")
self.assertRaises(ValueError,headers.__setitem__,"key",f"val{c0}")
self.assertRaises(ValueError,headers.add_header,f"key{c0}","val",param="param")
self.assertRaises(ValueError,headers.add_header,"key",f"val{c0}",param="param")
self.assertRaises(ValueError,headers.add_header,"key","val",param=f"param{c0}")


classErrorHandler(BaseCGIHandler):
"""Simple handler subclass for testing BaseHandler"""

Expand Down
3 changes: 3 additions & 0 deletionsLib/wsgiref/headers.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@
# existence of which force quoting of the parameter value.
importre
tspecials=re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')
_control_chars_re=re.compile(r'[\x00-\x1F\x7F]')

def_formatparam(param,value=None,quote=1):
"""Convenience function to format and return a key=value pair.
Expand DownExpand Up@@ -41,6 +42,8 @@ def __init__(self, headers=None):
def_convert_string_type(self,value):
"""Convert/check value type."""
iftype(value)isstr:
if_control_chars_re.search(value):
raiseValueError("Control characters not allowed in headers")
returnvalue
raiseAssertionError("Header names/values must be"
" of type str (got {0})".format(repr(value)))
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Reject C0 control characters within wsgiref.headers.Headers fields, values,
and parameters.
Loading

[8]ページ先頭

©2009-2026 Movatter.jp