-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Changes to make browsable API compatbile with strong CSP #8784
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
Conversation
After testing locally, this fixes the CSP warnings in the developer console, if you have a strict CSP like |
thanks |
I came across this pull request as I am currently adding CSP to our Django application. We are using the django rest framework in version 3.14. With the changes in this PR the load-ajax-form errors are fixed for me. But the line 290 in base.html is also generating a CSP error.
I think the same approach makes sense in this case and the inline script should be outsourced, as we already have a csrf.js file. I'm looking forward to your feedback |
@mnacken Thank you for reporting! There was an existing PR to fix this issue which I tested (in Chrome and Firefox) then merged: Above changed an inline script to use JSON instead of real javascript, which appeared to prevent the script from actually executing. It just made the data / token available in the page HTML. I'm not sure what browser you're using or why the new form still causes errors, but I'd be happy to look over a PR if you want to submit one. I guess using an external script is also a cleaner, more consistent approach than this dirty hack 😄 |
Thx for response, you are right! Is there any roadmap/timeline for releasing version 3.15? |
There is a milestone for it: I assume it will be released when all the linked issues are complete, but I don't actually know for sure. |
most probably by the end of this month or first half of next month |
I'm looking to add a `Content-Security-Policy` to API responses, and there were some important improvements for that in 3.15.0 (e.g. encode/django-rest-framework#8784).
I'm looking to add a `Content-Security-Policy` to API responses, and there were some important improvements for that in 3.15.0 (e.g. encode/django-rest-framework#8784).
I'm looking to add a `Content-Security-Policy` to API responses, and there were some important improvements for that in 3.15.0 (e.g. encode/django-rest-framework#8784).
(Copied from #5740, conflicting CSRF changes removed. These were already handled as part of #7016)
Currently the browsable API contains inline JS for configuring forms and allowing for custom CSRF cookie/header names. Use of CSP with this page requires 'unsafe-inline'.
This patch is a concept for getting rid of all inline scripts from the browsable API. It's not tested, as I just wanted to see if there was interest in merging this before I spend too much time on it.