-
-
Notifications
You must be signed in to change notification settings - Fork 609
Added websocket transport support for query & mutation. #1233
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
Conversation
`subscriptions-transport-ws` supports websocket transport. I just modified the `execute` function which did the trick for me and seems to work with all the auth etc., too.
|
Auth is a little different for websockets so I had to disable queries/mutations so that it wasn’t a breaking change for people using pgSettings/etc in interesting ways. I wasn’t planning to add support until v5, but we could add this behind a flag if you like? |
|
Ah, that makes way more sense; it looked a bit weird that it was just an exception. I guess my Yes, a flag or plugin works for me. Thanks for all the great work! |
benjie
left a comment
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.
I need to think about the option name.
src/interfaces.ts
Outdated
| // Enable GraphQL websocket transport support for subscriptions (you still need a subscriptions plugin currently) | ||
| subscriptions?: boolean; | ||
| // ENable GrqphQL websocket transport support for query & Mutation | ||
| websocketTransport?: boolean; |
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.
i’m not quite happy with this naming but my suggestions aren’t better. Let me ponder.
enableQueriesAndMutationsOverWebsockets
allOperationsOverWebsockets
fullWebsocketSupport
websocketExecute
websocketOperations
graphqlOverWebsocket
wsAllOps
Co-Authored-By: Benjie Gillam <[email protected]>
|
Ah yes, the good ol' naming. Let me throw a few in.
Alternatively, instead of a flag, the actual options could be like this ( websocketTransport?: boolean|"all"|"only-subscriptions";with |
|
This is better. Great suggestion. Lets drop the boolean and go with: Internally it should default to "subscriptions". In addition to the changes in this PR we should also check it here: The reason is that the In future we can expand it to support query/mutation over websockets without allowing subscriptions themselves. We'll probably drop the |
… into patch-1 # Conflicts: # src/interfaces.ts
|
Any further things I can improve? |
benjie
left a comment
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.
Looking good! I'm going to need to spend some time analysing if there's any knock-on effects from this, but once the below suggestions are merged I think the ball's firmly in my court.
Triple equal Co-Authored-By: Benjie Gillam <[email protected]>
More triple equals Co-Authored-By: Benjie Gillam <[email protected]>
|
@benjie Just updated the build to pass the remaining format issue. Any thing else i can do to help you with this? |
|
Leave it with me 👍 |
Dismissing review so I remember to review again
|
Looks like there is a mutation error |
benjie
left a comment
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.
Sorry this has taken so long to look at. There's a few minor things we need to tidy up, but my main concern is the security ramifications of opening websockets up like this. In particular CSRF-like attacks that can reuse user cookies to retrieve data from other sites. It's up to end users to protect their endpoints with websocketMiddlewares and Origin checks or CSRF tokens, but this will need documenting and really we should try and find a way to either enforce it or have the user confirm they've read that part of the documentation. What are your thoughts on this?
Co-authored-by: Benjie Gillam <[email protected]>
|
They all look fine to me. Regarding the security issue - tell me if I get this right: you can't even invalidate the websocket session once established. That is if the attacker hits the |
|
That's one issue (which can be solved by using the session implementation in Graphile Starter which uses database-stored sessions which can be deleted and thus the RLS policies that pull from them would start failing); another is that websockets don't obey the same-origin policy so it's an easy to exploit attack vector if people don't set up their websocket connections well enough (this is still an issue with subscriptions, but it becomes significantly more dangerous when queries and mutations are allowed). There's also performance, stability and scalability concerns; to hear those in more depth I recommend you listen to the section of the last GraphQL Working Group starting here: https://www.youtube.com/watch?v=FYF15RA9H3k&feature=youtu.be&t=3972 |
|
This was incorporated into #1338; now we're using a safer graphql websocket transport I'm happier opening this up 👍 Thanks for your work on this @klemens-morgenstern and sorry it took so long to resolve. |
subscriptions-transport-wssupports websocket transport. I just modified theexecutefunction which did the trick for me and seems to work with all the auth etc., too.