-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sonarcloud): remove CSRF exempt from /graphql/ endpoint
Fixes SonarCloud security hotspot python:S4502: "Make sure disabling CSRF protection is safe here. Disabling CSRF protections is security-sensitive": https://rules.sonarsource.com/python/RSPEC-4502/ refs KK-1417
- Loading branch information
1 parent
41ae1e7
commit 9648bb7
Showing
4 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends 'graphene/graphiql.html' %} | ||
|
||
{% block body_extra %} | ||
<script> | ||
// Add CSRF token to all GraphiQL fetch requests to make CSRF work with GraphiQL. | ||
// | ||
// window.fetch function's `options` parameter is an optional RequestInit, | ||
// which has an optional `headers` property which can be Headers or an object. | ||
// | ||
// See documentations: | ||
// - https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch | ||
// - https://developer.mozilla.org/en-US/docs/Web/API/RequestInit | ||
// - https://developer.mozilla.org/en-US/docs/Web/API/Headers | ||
const originalFetch = window.fetch; | ||
window.fetch = function(resource, options = undefined) { | ||
if (options) { | ||
options.headers = options.headers ?? {}; | ||
if (options.headers instanceof Headers) { | ||
options.headers.set('{{ csrf_header_name }}', '{{ csrf_token }}'); | ||
} else { | ||
options.headers['{{ csrf_header_name }}'] = '{{ csrf_token }}'; | ||
} | ||
} | ||
return originalFetch(resource, options); | ||
}; | ||
</script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters