-
-
Notifications
You must be signed in to change notification settings - Fork 553
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
Let legacy ws clients know about invalid data frames #3633
Let legacy ws clients know about invalid data frames #3633
Conversation
Reviewer's Guide by SourceryThis pull request enhances the WebSocket implementation for legacy graphql-ws clients by adding error reporting for unsupported data frames. Previously, binary data frames were silently ignored, but now the server will close the connection with an error message when receiving such frames. This change improves protocol compliance and provides better feedback to clients. File-Level Changes
Tips
|
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.
Hey @DoctorJohn - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 2 issues found
- 🟢 Complexity: all looks good
- 🟡 Documentation: 1 issue found
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
Thanks for adding the Here's a preview of the changelog: Starting with this release, clients using the legacy graphql-ws subprotocol will receive an error when they try to send binary data frames. While vaguely defined in the protocol, the legacy graphql-ws subprotocol is generally understood to only support text data frames. Here's the tweet text:
|
Thanks for adding the Here's a preview of the changelog: Starting with this release, clients using the legacy graphql-ws subprotocol will receive an error when they try to send binary data frames. While vagugely defined in the protocol, the legacy graphql-ws subprotocol is generally understood to only support text data frames. Here's the tweet text:
|
9f9cd6c
to
a9e6326
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3633 +/- ##
==========================================
- Coverage 96.76% 94.78% -1.98%
==========================================
Files 522 518 -4
Lines 33796 32647 -1149
Branches 5635 3772 -1863
==========================================
- Hits 32703 30945 -1758
- Misses 862 1408 +546
- Partials 231 294 +63 |
CodSpeed Performance ReportMerging #3633 will not alter performanceComparing Summary
|
9984916
to
e6753ff
Compare
e6753ff
to
af0e17b
Compare
@@ -0,0 +1,6 @@ | |||
Release type: patch | |||
|
|||
Starting with this release, clients using the legacy graphql-ws subprotocol will receive an error when they try to send binary data frames. |
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.
shouldn't this say subscriptions-transport-ws
? graphql-ws
is the newer one, and then graphql-over-ws
is the current in-progress spec to standardize GraphQL on this protocol
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.
That's a classic Erik: The new subprotocol is called graphql-transport-ws
and is living in a repository called graphql-ws
, while the old subprotocol is called graphql-ws
dying in a repository called subscriptions-transport-ws
. Throughout our code and docs we refer to the subprotocols name, instead of the repository names.
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.
For reference, here's the relevant line in the newer protocols spec: https://github.com/enisdenjo/graphql-ws/blob/c030ed1d5f7e8a552dffbfd46712caf7dfe91a54/PROTOCOL.md?plain=1#L10
The legacy protocol's spec is a mess, but the subprotocol's name (graphql-ws
) can be found in the reference implementation and various clients supporting it.
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.
The title of the document is literally graphql over ws
and that is the new nomenclature for all the other transport protocols :D lets hope this becomes more consistent in the future
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.
Same. This caused way too much confusion over the years 🫠
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.
Gonna submit an issue let's see if Denis agrees 😂
Starting with this PR, we will let legacy WS clients know when they send data frames (e.g., binary instead of text data frames) that are not supported by the protocol instead of simply ignoring them.
Description
While working on unifying all WebSocket implementations, I noticed that our implementation of the legacy WS protocol currently silently ignores unsupported data frames (i.e., binary data frames). So, I rechecked the protocol specs. They say only "stringified" JSON messages are allowed. That's the same formulation used in the newer WS protocol, where it is used to indicate that only text data frames are supported (related discussion: enisdenjo/graphql-ws#409).
Starting with this PR, we report the use of unsupported data frames to clients (before, we ignored them). This should not cause any disruption to clients since they usually operate in text or binary mode. If they operate in text mode, everything will keep working. If they operate in binary mode, they never worked but will receive an error message now.
Close code
1002
was chosen because that code is also used in the reference implementation of the legacy protocol to signal protocol violations. The generally vague specs don't stipulate any more specific code for this scenario.While at it, I unified the error message across both protocols and all integrations. (With the upcoming unification PR this would have been the case anyways).
Types of Changes
Checklist
Summary by Sourcery
Enhance the legacy WebSocket protocol implementation to notify clients when unsupported binary data frames are sent, closing the connection with a specific error code and reason. Update tests to reflect this change and add documentation to inform users of the new behavior.
Enhancements:
Documentation:
Tests: