Skip to content

Commit db92ff8

Browse files
bluetechpgjones
authored andcommitted
Explicitly require Host header in handshake
Per RFC 6455, 4.1 Client Requirements: 4. The request MUST contain a |Host| header field whose value contains /host/ plus optionally ":" followed by /port/ (when not using the default port). The h11 library should already be verifying this, but it doesn't hurt to repeat, and also assures mypy that it is not None.
1 parent 0ad2a5d commit db92ff8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: wsproto/handshake.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def events(self) -> Generator[Event, None, None]:
169169

170170
############ Server mode methods
171171

172-
def _process_connection_request(self, event: h11.Request) -> Request:
172+
def _process_connection_request(self, event: h11.Request) -> Request: # noqa: MC0001
173173
if event.method != b"GET":
174174
raise RemoteProtocolError(
175175
"Request method must be GET", event_hint=RejectConnection()
@@ -228,6 +228,10 @@ def _process_connection_request(self, event: h11.Request) -> Request:
228228
raise RemoteProtocolError(
229229
"Missing header, 'Sec-WebSocket-Version'", event_hint=RejectConnection()
230230
)
231+
if host is None:
232+
raise RemoteProtocolError(
233+
"Missing header, 'Host'", event_hint=RejectConnection()
234+
)
231235

232236
self._initiating_request = Request(
233237
extensions=extensions,

0 commit comments

Comments
 (0)