Improve HTTPS-on-HTTP parser error#12672
Open
puneetdixit200 wants to merge 2 commits into
Open
Conversation
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12672 +/- ##
=======================================
Coverage 98.95% 98.95%
=======================================
Files 131 131
Lines 46688 46697 +9
Branches 2421 2422 +1
=======================================
+ Hits 46200 46209 +9
Misses 366 366
Partials 122 122
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
Special-cases request parser errors where the incoming method bytes start with
\x16\x03, which is the common TLS ClientHello prefix. Both the pure-Python and Cython parser paths now report that HTTPS traffic was received on an HTTP port instead of showing the generic invalid method message.Are there changes in behavior for the user?
Yes. Misconfigured clients that send HTTPS traffic to an aiohttp HTTP server port now get a clearer 400 parser error message. There are no public API changes.
Is it a substantial burden for the maintainers to support this?
No. The change is a small error-message special case for a well-known byte prefix, with regression coverage for both parser implementations.
Related issue number
Fixes #10142.
Checklist
CONTRIBUTORS.txtCHANGES/folder<issue_or_pr_num>.<type>.rst(e.g.588.bugfix.rst)number after creating the PR
.bugfix: A bug fix for something the maintainers deemed animproper undesired behavior that got corrected to match
pre-agreed expectations.
.feature: A new behavior, public APIs. That sort of stuff..deprecation: A declaration of future API removals and breakingchanges in behavior.
.breaking: When something public is removed in a breaking way.Could be deprecated in an earlier release.
.doc: Notable updates to the documentation structure or buildprocess.
.packaging: Notes for downstreams about unobvious side effectsand tooling. Changes in the test invocation considerations and
runtime assumptions.
.contrib: Stuff that affects the contributor experience. e.g.Running tests, building the docs, setting up the development
environment.
.misc: Changes that are hard to assign to any of the abovecategories.
Local validation
pytest tests/test_http_parser.py::test_http_request_parser_tls_handshake_on_http_port -qfailed because the message was still the generic bad method error.AIOHTTP_NO_EXTENSIONS=1 PYTHONPATH=. pytest tests/test_http_parser.py -q-> 377 passed, 13 skipped, 4 deselected.PYTHONPATH=. pytest tests/test_http_parser.py -q-> 725 passed, 12 skipped, 6 deselected, 3 xfailed.PYTHONPATH=. pytest tests/test_http_exceptions.py -q-> 19 passed.black --check aiohttp/http_exceptions.py tests/test_http_parser.pypassed.git diff --checkreported only Windows LF-to-CRLF working-copy warnings.Drafted with OpenAI GPT-5; reviewed by puneetdixit200.