-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add validation of HTTP status line, header keys and values #5452
Add validation of HTTP status line, header keys and values #5452
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5452 +/- ##
=======================================
Coverage 96.75% 96.75%
=======================================
Files 44 44
Lines 9852 9857 +5
Branches 1591 1592 +1
=======================================
+ Hits 9532 9537 +5
Misses 182 182
Partials 138 138
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Co-authored-by: Sam Bull <[email protected]>
Tests without extensions are stuck. Looks like they get stuck on |
Sorry, missed that, forgot to run the code without extensions. There should be two |
…d the second CRLF sign after the headers
Ah, yes, I missed that change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@webknjaz Unless you've got an idea on a different place to include the check, I think this should be merged.
If there's no response from @webknjaz, I'll merge this at the weekend. |
Backport to 3.8: 💚 backport PR created✅ Backport PR branch: Backported as #5984 🤖 @patchback |
* Add validation of HTTP status line, header keys and values * Apply review comments * Rename _check_string to _safe_header and remove validation for the status_line * Update aiohttp/http_writer.py Co-authored-by: Sam Bull <[email protected]> * Modify changelog message * Refactor headers join * Refactor headers serialization back to the broken down version and add the second CRLF sign after the headers * Update aiohttp/http_writer.py Co-authored-by: Sam Bull <[email protected]> (cherry picked from commit a1158c5)
…5984) * Add validation of HTTP status line, header keys and values * Apply review comments * Rename _check_string to _safe_header and remove validation for the status_line * Update aiohttp/http_writer.py Co-authored-by: Sam Bull <[email protected]> * Modify changelog message * Refactor headers join * Refactor headers serialization back to the broken down version and add the second CRLF sign after the headers * Update aiohttp/http_writer.py Co-authored-by: Sam Bull <[email protected]> (cherry picked from commit a1158c5) Co-authored-by: Franek Magiera <[email protected]>
What do these changes do?
HTTP status line, header keys and values are checked in order to prevent custom header injection. If any of those contain a carriage return or newline character a ValueError is raised. The checks are done in
_serialize_headers
.Changes where made and tested for pure python version and cython version.
Also imported the
_serialize_headers
function totest_web_response
. I wanted to prevent code duplication and make sure that future changes to the way the headers are created are reflected in the tests. Let me know what you think about it.The documentation was not updated since I could not find a suitable place to find describe the changes made. Suggestions are welcome.
Are there changes in behavior for the user?
No significant changes, except an exception may be raised.
Related issue number
#4818
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.