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

Support Content-Security-Policy without "script-src unsafe-inline" #5381

Open
graingert opened this issue Jun 8, 2016 · 9 comments
Open

Comments

@graingert
Copy link

graingert commented Jun 8, 2016

Django 1.10 lands support for running the admin with a Content-Security-Policy without "script-src unsafe-inline" applied. This allows the django admin to be completely immune from XSS attacks.

Django CMS should follow suit and remove all inline JavaScript. Replacing large blocks of JS with <script src={% static 'path/to/old_inlines/eg.js' %}></script> and <script>var foo = {{bar}}></script> with:

# path/to/fooUsage.js
window.foo = $('#django-cms-foo').data('foo');
<script id='django-cms-foo' src={% static 'path/to/fooUsuage.js' %} data-foo={{ bar }}></script>
@vxsx vxsx added this to the 3.4 milestone Jun 8, 2016
@vxsx vxsx self-assigned this Jun 8, 2016
@vxsx
Copy link
Contributor

vxsx commented Jun 8, 2016

Thanks for the report, we'll take care of it.
It would also require changes in some of the essential addons though, e.g. djangocms-text-ckeditor etc.

@yakky
Copy link
Member

yakky commented Jun 8, 2016

I think that this should undergo a deprecation period. Django 1.10 just removed its own inline javascript to allow enabling "Content-Security-Policy", it does not enforce it.
I think that django CMS 3.4 can adopt the same behavior, and then let addons adapt to it by providing a "suggested timeframe"

@rspeed
Copy link

rspeed commented Sep 17, 2017

I gave this a look and it's a bit harder than I expected. Replacing CMS.config with a block of JSON was fairly straightforward, but plugins are another story altogether. Gonna put it aside for now and take another look when I have some time.

Another issue is that Django-CMS uses jQuery's PEP.js library, which builds a dynamic script element and inserts it into the DOM, violating style-src 'self'. So there's at least one upstream blocker.

@graingert
Copy link
Author

graingert commented Sep 17, 2017 via email

@rspeed
Copy link

rspeed commented Sep 17, 2017

Some good news: I got the plugins/placeholders sorted out. I've got it running on my personal site right now (with style-src 'self' 'unsafe-inline' in the CSP) and haven't encountered any issues.

@graingert
Copy link
Author

@rspeed oh great stuff, any chance of some PRs?

@rspeed
Copy link

rspeed commented Sep 18, 2017

Yup, already working on one. I found a few more inline scripts that needed to be fixed. Finishing that up now.

@marksweb
Copy link
Member

@vxsx @yakky what's the status of CSP support?

Following a PEN test I've got a client who wants us to implement a CSP & I've done what I can, but can't complete the task without support from the CMS.

I've not looked at the commits involved in #6072 yet, but it's full of conflicts given it's age now so not sure how viable those changes are now.

marksweb added a commit to marksweb/django-cms that referenced this issue Jan 18, 2019
marksweb added a commit to marksweb/django-cms that referenced this issue Jan 18, 2019
This addresses CSP support in django-cms#5381
Rebuilt the JS
@Aiky30 Aiky30 modified the milestones: 3.4.x, DCA Needs clarification Dec 8, 2020
@GrazingScientist
Copy link

I give this a push, because I find it highly relevant that I do not have to set unsafe-inline in my code, because it more or less makes the CSP useless.

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

Successfully merging a pull request may close this issue.

8 participants