Questions re: authentication and credential refresh #292
-
Expected Behaviour Actual Behaviour Further Information I operate a GraphQL server and would like to abort long-running operations (presently just subscriptions) when their associated authentication expires. It would be wrong from a security perspective to allow unending access to confidential data on subscriptions long after we cease to trust the credential on whose basis the subscription was initially authorized. Tangent: Regarding "authentication is connection-scoped" vs "operation-scoped":
Regardless of if authentication is connection- or operation-scoped, the ideal UX from a client's perspective is that there be some mechanism to refresh credentials for incomplete operations on the connection. To satisfy all the stated requirements,
Given that we should be careful about what's in scope of this protocol and what's not, my question is admittedly vague:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Since WebSocket connections cannot be hijacked, I personally don't bother much. I know for a fact that the identity resolved during the connection initialization process is persisted as long as the connection is alive - so, re-authenticating within an active connection is kinda useless if you ask me. Of course, there are cases where you want to kick the client off - like when the user gets his rights revoked while being connected - but, these cases can be solved differently: keep a map of all user IDs with connected sockets and simply close the socket behind a user ID whenever he's deemed unauthorized. Additionally, if you worry about connections being alive for too long, simply set a limit of how long a single connection can live and close the connection after the timeout.
No, on the contrary, the ping's payload is meant to be used for any sort of keep-alive logic - be it authentication or latency metrics. However, I'd still prefer closing the connection with the client and have the client re-authenticate by repeating the connection initialization process.
No, not really. TBH I'd rather leave it to the implementer to decide how his authentication/authorization works since there is no one-size-fits-all here - I'd rather not have an opinion. Additionally, there's an abundance of WebSocket security articles on the internet which were written by much smarter people than me. |
Beta Was this translation helpful? Give feedback.
-
FWIW, in my keycloak-graphql project, I've taken the approach of making the client responsible for authenticating and obtaining an access token. The graphql-transport-ws Ping and Pong messages are used as follows:
When the client creates a new subscription, the access token is retrieved from the session, validated, and added to the GraphQL context making it available to the resolvers. The access token is also retrieved from the session, validated, and added to the GraphQL context whenever an established subscription event "fires". If the access token cannot be validated, the socket is closed. |
Beta Was this translation helpful? Give feedback.
Since WebSocket connections cannot be hijacked, I personally don't bother much. I know for a fact that the identity resolved during the connection initialization process is persisted as long as the connection is alive - so, re-authenticating within an active connection is kinda useless if you ask me.
Of course, there are cases where you want to kick the client off - like when the user gets his rights revoked while being connected - but, these cases can be solved differently: keep a map of all user IDs with connected sockets and simply close the socket behind a user ID whenever he's deemed unauthorized.
Additionally, if you worry about connections being alive for too long, simply set a lim…