Problem/Motivation

When using Content-Security-Policy header, it is not recommended to use unsafe-inline in style-src.
Not having unsafe-inline means the CSP does not allow inline CSS (style tags and style attributes).

But currently this breaks many places in core:

Content-Security-Policy : Les paramètres de la page ont empêché l’application d’un style intégré (style-src-attr) car il enfreint la directive suivante : « style-src 'self' ». Pensez à utiliser une empreinte (« sha256-tebxQlMf4baoYjNK42e57+Vot1eLPS/ixIS6aN9WlyE= », nécessite « unsafe-hashes » pour les attributs de style) ou un nonce.
Source: --color--primary-hue:202;--color--primar… web
Content-Security-Policy : Les paramètres de la page ont empêché l’application d’un style intégré (style-src-elem) car il enfreint la directive suivante : « style-src 'self' ». Pensez à utiliser une empreinte (« sha256-1VTAHS0X+0lgrfu7iW/2ikIZ/VIANi00phY6Pqavxdg= », nécessite « unsafe-hashes » pour les attributs de style) ou un nonce. toolbar.anti-flicker.js:62:38
Content-Security-Policy : Les paramètres de la page ont empêché l’application d’un style intégré (style-src-elem) car il enfreint la directive suivante : « style-src 'self' ». Pensez à utiliser une empreinte (« sha256-wXNpUtH5sYUAuvozoeFeOb1ltEkb75rMCA6rfsoPPj8= », nécessite « unsafe-hashes » pour les attributs de style) ou un nonce. toolbar.anti-flicker.js:67:40
Content-Security-Policy : Les paramètres de la page ont empêché l’application d’un style intégré (style-src-elem) car il enfreint la directive suivante : « style-src 'self' ». Pensez à utiliser une empreinte (« sha256-faU7yAF8NxuMTNEwVmBz+VcYeIoBQ2EMHW3WaVxCvnk= », nécessite « unsafe-hashes » pour les attributs de style) ou un nonce. htmx.min.js:1:50354

Steps to reproduce

Add this your .htaccess file:

Header add Content-Security-Policy "style-src 'self'"

Proposed resolution

There would be two ways to improve this:

  • Identify places in core that use inline style and open child issues to try to avoid it.
  • Add a mechanism to generate nonces to explicitly allow some inline style tags.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

prudloff created an issue.

prudloff’s picture

The csp contrib module provides a way to add nonces to render arrays: https://git.drupalcode.org/project/csp/-/blob/3cadb773a7bf19347d23ef39c7...

cilefen’s picture

Should we go so far as to say that CSP management should be a core feature?