Skip to content

Commit

Permalink
Sanitize URL in Location header in redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
m-burst authored and webknjaz committed Feb 17, 2019
1 parent 59ccf3a commit cc4fffd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/3613.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use sanitized URL as Location header in redirects
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Mathias Fröjdman
Matthieu Hauglustaine
Matthieu Rigal
Michael Ihnatenko
Mikhail Burshteyn
Mikhail Kashkin
Mikhail Lukyanchenko
Mikhail Nacharov
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/web_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def __init__(self,
raise ValueError("HTTP redirects need a location to redirect to.")
super().__init__(headers=headers, reason=reason,
text=text, content_type=content_type)
self.headers['Location'] = str(location)
self._location = URL(location)
self.headers['Location'] = str(self.location)

@property
def location(self) -> URL:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_web_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def test_HTTPFound_empty_location() -> None:
web.HTTPFound(location=None)


def test_HTTPFound_location_CRLF() -> None:
exc = web.HTTPFound(location='/redirect\r\n')
assert '\r\n' not in exc.headers['Location']


async def test_HTTPMethodNotAllowed() -> None:
exc = web.HTTPMethodNotAllowed('GET', ['POST', 'PUT'])
assert 'GET' == exc.method
Expand Down

0 comments on commit cc4fffd

Please sign in to comment.