Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sanitized URL as Location header in redirects #3613

Merged
merged 1 commit into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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