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

Update authentication to include JWT-cookie #930

Open
Diggitysc opened this issue Mar 19, 2019 · 3 comments
Open

Update authentication to include JWT-cookie #930

Diggitysc opened this issue Mar 19, 2019 · 3 comments

Comments

@Diggitysc
Copy link

Diggitysc commented Mar 19, 2019

Related to #550

JWT in local storage is not secure. I recommend updating the authentication page here: https://www.howtographql.com/graphql-python/4-authentication/ Discussed in more depth here, graphql-python/graphene-django#593 (comment)

The relevant points: adding the library https://github.com/flavors/django-graphql-jwt and the code:

from graphql_jwt.decorators import jwt_cookie

 
urlpatterns = [
    path('graphql/', jwt_cookie(GraphQLView.as_view(graphiql=True))),
]

This creates a JWT token in a cookie named "JWT" allowing the browser to act as a go-between for secure authentication between js client/backend.

django-graphql-jwt then has decorators to provide security:
https://django-graphql-jwt.domake.io/en/stable/decorators.html

In this way, a javascript front end can securely access a backend data without exposure to XSS (CORS/CSRF settings required).

@jonatasbaldin
Copy link

Hey there!

Thanks so much for this PR :D

I'm a bit busy lately to make big changes to the tutorial, would you mind helping us out with a PR?

Thanks!

@Diggitysc
Copy link
Author

Hey jonatasbaldin

After further discussion with some other parties, the solution discussed above would only protect any data you are storing in the cookie itself (in this case JWT). Malicious users with access to XSS are still able to execute as the valid users browser meaning the only real prevention is to not have an XSS vulnerability from the get go.

Once I am done with a few things on my end in a month or two I will cycle back and help in any way I am able though.

Thank you for your site, it is very helpful

@jonatasbaldin
Copy link

Thanks for your help and feedback, I appreciate it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants