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.10] gh-144370: Disallow usage of control characters in status in wsgiref.handlers for security (#144371)#145673

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

Open
vstinner wants to merge1 commit intopython:3.10
base:3.10
Choose a base branch
Loading
fromvstinner:wsgiref310
Open
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
19 changes: 19 additions & 0 deletionsLib/test/test_wsgiref.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -879,6 +879,25 @@ def write(self, b):
self.assertIsNotNone(h.status)
self.assertIsNotNone(h.environ)

def testRaisesControlCharacters(self):
for c0 in control_characters_c0():
with self.subTest(c0):
base = BaseHandler()
with self.assertRaises(ValueError):
base.start_response(c0, [('x', 'y')])

base = BaseHandler()
with self.assertRaises(ValueError):
base.start_response('200 OK', [(c0, 'y')])

# HTAB (\x09) is allowed in header values, but not in names.
base = BaseHandler()
if c0 != "\t":
with self.assertRaises(ValueError):
base.start_response('200 OK', [('x', c0)])
else:
base.start_response('200 OK', [('x', c0)])


if __name__ == "__main__":
unittest.main()
4 changes: 3 additions & 1 deletionLib/wsgiref/handlers.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
"""Base classes for server/gateway implementations"""

from .util import FileWrapper, guess_scheme, is_hop_by_hop
from .headers import Headers
from .headers import Headers, _name_disallowed_re

import sys, os, time

Expand DownExpand Up@@ -238,6 +238,8 @@ def start_response(self, status, headers,exc_info=None):
self.status = status
self.headers = self.headers_class(headers)
status = self._convert_string_type(status, "Status")
if _name_disallowed_re.search(status):
raise ValueError("Control characters are not allowed in status")
assert len(status)>=4,"Status must be at least 4 characters"
assert status[:3].isdigit(), "Status message must begin w/3-digit code"
assert status[3]==" ", "Status message must have a space after code"
Expand Down
1 change: 1 addition & 0 deletionsMisc/ACKS
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1006,6 +1006,7 @@ Wolfgang Langner
Detlef Lannert
Rémi Lapeyre
Soren Larsen
Seth Michael Larson
Amos Latteier
Piers Lauder
Ben Laurie
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
Disallow usage of control characters in status in :mod:`wsgiref.handlers` to prevent HTTP header injections.
Patch by Benedikt Johannes.
Loading

[8]ページ先頭

©2009-2026 Movatter.jp