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

Add CSRF token to GraphiQL view #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add CSRF token to GraphiQL view #35

wants to merge 1 commit into from

Conversation

cellis
Copy link

@cellis cellis commented Oct 19, 2016

This change adds a getCSRFToken method that if provided can be invoked with the request to get a CSRF token for example: req.csrfToken().

This is needed for securing the GraphiQL views (especially on production instances!). I'm using a modified version of this in development to allow my csrf strategy to work. Let me know what you think!

@tothandras
Copy link
Contributor

Thanks for the PR! Can you add support for the other frameworks too (koa, hapi)?

@cellis
Copy link
Author

cellis commented Nov 21, 2016

@tothandras I'll look at these other frameworks soon

@phra
Copy link

phra commented Apr 24, 2017

any updates on this?

@@ -16,7 +16,8 @@ export function required() {

const GRAPHIQL_VERSION = '0.7.1';

export function renderGraphiQL({ query, variables, version = GRAPHIQL_VERSION } = {}) {
export function renderGraphiQL({ query, variables, version = GRAPHIQL_VERSION, csrfToken } = {}) {
csrfToken = csrfToken ? `,'x-csrf-token': '${csrfToken}'` : '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's usually a good idea to treat function parameters as immutable. In this case a better name could perhaps be csrfHeader, as it's more aligned with the actual value.

@@ -89,7 +90,8 @@ export function renderGraphiQL({ query, variables, version = GRAPHIQL_VERSION }
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Content-Type': 'application/json'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave the trailing comma on this line. The main benefit of trailing commas is that they help reduce the size of diffs. This diff section could be +1 instead of +2 -1.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CMTegner good points. I don't have time to see this through to completion, as I no longer use this library.

@cellis
Copy link
Author

cellis commented May 9, 2017

@phra sorry for the delay. I don't have time to work on this anymore, as I've moved on to using another library. Perhaps someone else is interested in taking this to the finish line by implementing @tothandras' request to add koa and hapi support?

@phra
Copy link

phra commented May 9, 2017

@cellis which library are you using? i'm using this one right now.

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.

4 participants