-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
More details about the issue: Given the following sample aiohttp app: from aiohttp import web
def test_view(request):
param = request.query.get('param')
raise web.HTTPFound(f'http://example.com?param={param}')
def create_app():
app = web.Application()
app.router.add_get('/', test_view)
return app
if __name__ == '__main__':
web.run_app(create_app(), port=5000) Sending a request with a urlencoded CRLF in the query parameter results in the following:
Though the user's code itself needs to be vulnerable in order to exploit this bug, the case is pretty common and aiohttp should protect the users from this (as most other web frameworks do). This PR fixes the issue by essentially setting the Location header to |
Codecov Report
@@ Coverage Diff @@
## master #3613 +/- ##
======================================
Coverage 97.9% 97.9%
======================================
Files 43 43
Lines 8556 8556
Branches 1376 1376
======================================
Hits 8377 8377
Misses 74 74
Partials 105 105
Continue to review full report at Codecov.
|
@m-burst thanks! Would you mind sending a backport against the stable branch? |
What do these changes do?
When performing HTTP redirects (e.g. using
raise HTTPFound(location)
), the URL in the Location header is now passed throughURL
constructor and thus sanitized. Most importantly, any CRLF in the location will be escaped, which will prevent HTTP Response Splitting attacks.Are there changes in behavior for the user?
None unless the user's code is vulnerable.
Related issue number
None
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.