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

Fix CSRF token header usage #846

Merged
merged 5 commits into from
Jan 4, 2024
Merged

Fix CSRF token header usage #846

merged 5 commits into from
Jan 4, 2024

Conversation

evamillan
Copy link
Contributor

This PR changes how the CSRF token header is used. API calls using the JWT authorization header don't need the CSRF token. The token is only required on requests that are made from the UI, which now uses a new endpoint at /api/login to authenticate users instead of JWT. Django sets a csrftoken cookie when the interface is loaded and a sessionid cookie for authenticated users that is not available to JavaScript and includes it automatically in all requests.
Since the UI needs to be served by Django to get the token, to run it for development use yarn watch instead of yarn serve, which watches for changes and rebuilds the static files, and serve it with ./manage.py runserver , which collects the files automatically.

Adds a view at '/api/login' to authenticate a user using
Django's sessions. If authenticated, it returns the user
and their permissions as a response and sets a 'sessionid'
cookie.

Signed-off-by: Eva Millán <[email protected]>
Removes the CSRF token check from the GraphQL requests by
default. The check is only performed for requests decorated
with '@check_auth' or '@check_permissions' that don't have a
JWT authorization header.

Signed-off-by: Eva Millán <[email protected]>
Replaces the JWT authorization with '/api/login/'.
Adds the CSRF token to the template so the header
is added automatically to all requests when the UI
is served by Django.

Signed-off-by: Eva Millán <[email protected]>
Adds the 'yarn watch' command to rebuild the UI static files
whenever there is a change in the code. Running the Django
backend with './manage.py runserver' automatically collects
and serves the files with the CSRF token included.

Signed-off-by: Eva Millán <[email protected]>
Removes the 'X-CSRFToken' header and the GET request
to retrieve it since it is not needed when using JWT
authorization.

Signed-off-by: Eva Millán <[email protected]>
@sduenas sduenas merged commit 9afb57a into chaoss:master Jan 4, 2024
7 checks passed
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.

2 participants