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.13] gh-143916: Reject control characters in wsgiref.headers.Headers (GH-143917)#143973

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.13fromgpshead:backport-f7fceed-3.13
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@@ -2856,3 +2856,10 @@ def linked_to_musl():
except (OSError,subprocess.CalledProcessError):
returnFalse
return ('musl'instdout)


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 @@
from unittest import mock
from test import support
from test.support import socket_helper
from test.support import socket_helper, control_characters_c0
from test.test_httpservers import NoLogRequestHandler
from unittest import TestCase
from wsgiref.util import setup_testing_defaults
Expand DownExpand Up@@ -503,6 +503,16 @@ def testExtras(self):
'\r\n'
)

def testRaisesControlCharacters(self):
headers = Headers()
for c0 in control_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}")


class ErrorHandler(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