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

gh-109765: Detect TLS handshake attempt in HTTP server #130041

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ def parse_request(self):
requestline = str(self.raw_requestline, 'iso-8859-1')
requestline = requestline.rstrip('\r\n')
self.requestline = requestline

# Detect TLS handshake attempt (common when browser forces HTTPS)
if self.raw_requestline[0] == 0x16: # First TLS handshake bytes
self.requestline = "[TLS handshake bytes]"
self.send_error(
HTTPStatus.BAD_REQUEST,
"Unsupported protocol: HTTPS is not available")
return False

words = requestline.split()
if len(words) == 0:
return False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Detect TLS handshake attempt in :class:`http.server.BaseHTTPRequestHandler` to
more clear the output. Patch by Semyon Moroz.
Loading