fix: Omit default port from Host header in MqttServerWs2Connection#643
Merged
shamblett merged 1 commit intoMar 25, 2026
Merged
Conversation
Only include the port in the Host header when it differs from the scheme's default port (443 for wss, 80 for ws). This fixes 403 Forbidden errors from AWS IoT Core and other servers that normalize the Host header by stripping default ports. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Owner
|
Merged, package re published at version 10.11.10. |
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.
Summary
The
_performWSHandshakemethod inMqttServerWs2Connectionalways includes the port number in theHostheader, even when using the default port for the scheme (443 forwss://, 80 forws://).Per RFC 7230 Section 5.4:
And RFC 3986 Section 3.2.3:
Current behavior:
Host: endpoint:443(always includes port)Expected behavior:
Host: endpoint(omit default port)Problem
AWS IoT Core (and potentially other WebSocket servers that perform SigV4 or similar Host-header-based authentication) rejects WebSocket upgrade requests with
Host: endpoint:443, returning403 Forbidden. This is because the server normalizes the Host header by stripping the default port, causing a mismatch with the signed request.The standard
MqttServerWsConnectiondoes not have this issue because Dart'sWebSocket.connect()/HttpClientcorrectly omits the default port from the Host header.Fix
Only include the port in the Host header when it differs from the scheme's default port:
wss://→ default port 443ws://→ default port 80