PHP Classes

File: site/guide/csp.md

Recommend this page to a friend!
  Packages of Boss Ibrahim Mussa   Caelrik   site/guide/csp.md   Download  
File: site/guide/csp.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: Caelrik
Build Web user interface from PHP components
Author: By
Last change:
Date: 8 days ago
Size: 1,391 bytes
 

 

Contents

Class file image Download

Content Security Policy

Components write no inline scripts or styles, so a strict policy works. Pass a nonce to the assets tag:

::: code-group

<x-caelrik-assets :nonce="$nonce" />

{{ caelrik_assets(nonce: nonce) }}

<?= Assets::tags('/vendor/caelrik', nonce: $nonce) ?>

:::

The nonce goes on the module script, and is printed as <meta name="csp-nonce">, which FullCalendar uses for the styles it injects.

Tested policy

default-src 'self'; script-src 'self' 'nonce-?'; style-src 'self' 'nonce-?';
img-src 'self' data:; font-src 'self' data:; connect-src 'self'

  • `font-src data:` is needed for the Scheduler's toolbar icons.
  • Add your CDN to `script-src` and `style-src` if Bootstrap and jQuery come from one, and `https://cdn.jsdelivr.net` if the Caelrik bundle does (`Assets::cdnUrl()`).
  • The File Manager also needs `style-src-attr 'unsafe-inline'`: elFinder builds its interface with inline `style` attributes. That allows style attributes only (they cannot run code); scripts and `<style>` elements still need the nonce.
  • Code fields (`Field::code()`) need the nonce in `style-src`: CodeMirror injects its stylesheet as a `<style>` element, with the nonce of `<meta name="csp-nonce">`.
  • The ThemeBuilder previews themes with a constructed stylesheet, which needs no change to the policy.