Skip to content
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

Adds protection against cross-site WebSocket hijacking using CSRF tokens #6

Merged
merged 4 commits into from
Feb 15, 2024

Conversation

amorey
Copy link
Member

@amorey amorey commented Feb 14, 2024

To protect against CSWSH attacks we need a way to identify cross-site requests and prevent them from connecting to the server. The easiest way to do this is by ensuring that the request Host and Origin are the same but unfortunately, kubectl proxy modifies the request Host so we can't use this method. Another easy method is to check the Sec-Fetch-Site header but unfortunately it isn't implemented in some popular browsers (see #3) so we can't use this method either. Instead, this PR uses the old-school method of CSRF token validation to identify cross-site requests and block them. After a WebSocket connection is made, the client is required to authenticate using the CSRF token value. If the token fails validation the connection is closed, otherwise it is allowed to continue.

This PR also moves the GraphiQL playground interface to a static page accessible at /graphiql.

@amorey amorey changed the title Added csrf token auth to graphql websocket connection requests Adds protection against cross-site WebSocket hijacking using CSRF tokens Feb 15, 2024
@amorey amorey merged commit 1fc41c1 into main Feb 15, 2024
@amorey amorey deleted the andres/kub-10-csrf branch February 15, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant