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

Changes to make browsable API compatbile with strong CSP [WIP] #5740

Closed
wants to merge 1 commit into from

Conversation

jxcl
Copy link
Contributor

@jxcl jxcl commented Jan 10, 2018

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.

@jxcl
Copy link
Contributor Author

jxcl commented Jan 10, 2018

I realize that this PR doesn't remove all inline javascript, but it looks to me like all of the remaining inline javascript can simply be moved into their own files; the most complex change was the CSRF stuff.

@tomchristie
Copy link
Member

Not sure I have enough context, where’s best to read up on CSP?

@jxcl
Copy link
Contributor Author

jxcl commented Mar 24, 2018

Sorry! I got caught up in what I was doing and totally didn't realize I was using acronyms. CSP stands for Content Security Policy. (https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP).

A site using CSP (without unsafe-inline) will, by default, prevent inline javascript from running. Everything has to be loaded from other files. This mitigates the risk of XSS attacks, since if your application somehow renders valid and unescaped javascript from user input, it won't be run.

DRF is currently incompatible with a strong CSP precisely because it uses inline javascript. By injecting the template variables into javascript with an application/json tag instead of javascript and moving all current inline javascript to external files, DRF can be made compatible with a CSP that does not allow unsafe-inline.

@s4ke
Copy link

s4ke commented Oct 14, 2020

The way this is implemented looks good to me and once rebased would fix the issue.

Copy link
Contributor

@craiga craiga left a comment

Choose a reason for hiding this comment

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

Changes here look good to me. There's still inline CSS which can cause CSP violations.

@jscaux
Copy link

jscaux commented May 30, 2021

@craiga @carltongibson I also need to enforce strong CSP and would like inline javascript to be removed. I've tested this patch (with cosmetic changes) locally and it works for me. I'd love to see it go through.

@tomchristie tomchristie added this to the 3.14 milestone Dec 13, 2021
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@juspence
Copy link
Contributor

I rebased, tested, and merged this as part of #8784 - thanks @jxcl for your PR!

@juspence juspence closed this Nov 29, 2022
@auvipy auvipy removed this from the 3.15 milestone Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants