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

[waiting for django5.1] Content Security Policy #2099

Closed
wants to merge 13 commits into from

Conversation

richardebeling
Copy link
Member

@richardebeling richardebeling commented Jan 8, 2024

Additional layer to prevent JavaScript injection. Still allows inline CSS and images to be exploited.

  • To fix CSS, we need to figure out how we can handle dynamically generated colors. Using attr() in CSS doesn't work with current browsers, at least for colors. The only workaround I currently see is having custom javascript that translates data-X helper attributes for color into "inline" style (using the .style attribute) -- seems a bit ugly to me
  • To fix images, we'd need to move the data: images we currently have (3 svg paths in CSS files) into separate files. These are currently inlined into CSS to use our color definitions.
  • Modal changes conflict with Rewrite confirmation modals #1985 -- we can just remove the modal changes from this PR once the "new" modals are merged.
  • Consider setting up CSP failure reporting, maybe using some external service that tracks / aggregates them for us? Would leak user data though. mozilla-django-csp at least had a report-view in the past, but the documentation looks they don't want to maintain that anymore

Copy link
Member

@niklasmohrin niklasmohrin left a comment

Choose a reason for hiding this comment

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

Haven't read modal commit yet, because we expect that to change after #1985 is merged. Looks good in general, some comments:

evap/evaluation/templates/infobox.html Outdated Show resolved Hide resolved
evap/evaluation/templatetags/infotext_templatetags.py Outdated Show resolved Hide resolved
evap/evaluation/templates/navbar.html Show resolved Hide resolved
evap/settings.py Outdated Show resolved Hide resolved
evap/staff/templates/staff_template_form.html Outdated Show resolved Hide resolved
evap/static/scss/_utilities.scss Outdated Show resolved Hide resolved
evap/settings.py Outdated Show resolved Hide resolved
@richardebeling
Copy link
Member Author

richardebeling commented Jan 22, 2024

Current test failures are when a view aborts request processing and we thus defer to django's default handling for 400/500 responses. When rendering the template for those, the request does not have the annotated csp_nonce anymore (because the django stack loses the original request and crafts a new one).

https://code.djangoproject.com/ticket/34830 fixes this, will have to wait for a django version that contains the change (probably 5.1?)

@richardebeling richardebeling changed the title Content Security Policy [waiting for django5.1] Content Security Policy Feb 15, 2024
@richardebeling
Copy link
Member Author

Closing for now to clean up the PR list -- I'll keep it on my list and get back to this when 5.1 is released and we upgraded.

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

Successfully merging this pull request may close these issues.

2 participants