question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A list of widgets breaking strict Content-Security-Policy (CSP) directives

See original GitHub issue

Is your proposal related to a problem?

Wagtail uses inline javascript and styles to provide useful feedback to the user. This causes conflicts with CSP directives.

This issue attempts to list all of the potential places this occurs in the Wagtail codebase.

Directives to be reviewed:

  • script-src ((completed 2021-04-21))
  • img-src
  • font-src
  • style-src ((completed 2021-04-21))

Extra Notes

  • The JS library modernizer-2.6.2.min.js is blocked by the style-src: 'self' CSP. You can trigger this by visiting /admin/

script-src: ‘self’

Wagtail Admin

Wagtail Admin Templates

  1. wagtail/admin/templates/wagtailadmin/

  2. wagtail/admin/templates/wagtailadmin/edit_handlers/

  3. wagtail/admin/templates/wagtailadmin/home/

  4. wagtail/admin/templates/wagtailadmin/pages/

  5. wagtail/admin/templates/wagtailadmin/permissions/includes/

  6. wagtail/admin/templates/wagtailadmin/reports/

  7. wagtail/admin/templates/wagtailadmin/shared/

  8. wagtail/admin/templates/wagtailadmin/widgets/

  9. wagtail/admin/templates/wagtailadmin/workflows/

Wagtail Contrib

Wagtail Documents

Wagtail Images

Wagtail Snippets

Wagtail Users

Wagtail Utils

style-src: ‘self’

Wagtail Embeds

Wagtail Admin

Contrib

Documents

Embeds

Images

Users

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
thibaudcolascommented, Apr 29, 2021

Reading up / based on our discussion in Slack, we’ll need to get rid of those style="" attributes in HTML/Python, and in JavaScript switch any usage of setAttribute('style') to adding individual properties on the style DOM attribute: https://stackoverflow.com/a/29089970/1798491.

I couldn’t see any setAttribute('style') in Wagtail’s JS code, but there could be in our dependencies.

For style attributes in HTML, I could see two based on the list above that will be tricky to change:

Does some clever math. This would either require a <style> attribute with a nonce and adding styles via a unique id to each iframe… or I think we might be able to refactor this to use the more modern aspect-ratio CSS property.

This might be easier by setting the values via JS.


All the other style attributes in HTML can either be replaced with CSS classes, or the hidden HTML attribute.

0reactions
lb-commented, Aug 6, 2022

Login page - inline script to focus on username field has been replaced with autofocus attribute.

Via #8925

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix 'because it violates the following content security ...
Blocked by Content Security Policy. 'csp error because it violates the following content security policy directive'. Content Security Policy error message.
Read more >
Content Security Policy (CSP) - Pendo Help Center
While Pendo is compatible with strict CSP directives, it is the user's responsibility to ensure the guide content is compatible with your CSP...
Read more >
Mitigate cross-site scripting (XSS) with a strict Content Security ...
Learn how to deploy a CSP based on script nonces or hashes as a defense-in-depth against cross-site scripting.
Read more >
Content Security Policy (CSP) - HTTP - MDN Web Docs
Chrome Edge Content‑Security‑Policy Full support. Chrome25. more. Toggle history Full sup... base‑uri Full support. Chrome40. Toggle history Full sup... block‑all‑mixed‑content. Deprecated Full support. ChromeYes. Toggle history...
Read more >
Content Security Policy | Mendix Documentation
If used with strict CSP, these widgets can result in CSP errors in the console or broken flows. Please consult a widget's documentation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found