Skip to content

Commit cc4fffd

Browse files
m-burstwebknjaz
authored andcommitted
Sanitize URL in Location header in redirects
PR aio-libs#3613 by @m-burst
1 parent 59ccf3a commit cc4fffd

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

CHANGES/3613.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use sanitized URL as Location header in redirects

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Mathias Fröjdman
152152
Matthieu Hauglustaine
153153
Matthieu Rigal
154154
Michael Ihnatenko
155+
Mikhail Burshteyn
155156
Mikhail Kashkin
156157
Mikhail Lukyanchenko
157158
Mikhail Nacharov

aiohttp/web_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def __init__(self,
203203
raise ValueError("HTTP redirects need a location to redirect to.")
204204
super().__init__(headers=headers, reason=reason,
205205
text=text, content_type=content_type)
206-
self.headers['Location'] = str(location)
207206
self._location = URL(location)
207+
self.headers['Location'] = str(self.location)
208208

209209
@property
210210
def location(self) -> URL:

tests/test_web_exceptions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ def test_HTTPFound_empty_location() -> None:
133133
web.HTTPFound(location=None)
134134

135135

136+
def test_HTTPFound_location_CRLF() -> None:
137+
exc = web.HTTPFound(location='/redirect\r\n')
138+
assert '\r\n' not in exc.headers['Location']
139+
140+
136141
async def test_HTTPMethodNotAllowed() -> None:
137142
exc = web.HTTPMethodNotAllowed('GET', ['POST', 'PUT'])
138143
assert 'GET' == exc.method

0 commit comments

Comments
 (0)