|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Security\Presets; |
| 4 | + |
| 5 | +use Spatie\Csp\Directive; |
| 6 | +use Spatie\Csp\Keyword; |
| 7 | +use Spatie\Csp\Policy; |
| 8 | +use Spatie\Csp\Preset; |
| 9 | + |
| 10 | +class MyCspPreset implements Preset |
| 11 | +{ |
| 12 | + public function configure(Policy $policy): void |
| 13 | + { |
| 14 | + $policy->add(Directive::BASE, Keyword::SELF); |
| 15 | + |
| 16 | + $policy->add(Directive::CONNECT, Keyword::SELF); |
| 17 | + $policy->add(Directive::DEFAULT, Keyword::SELF); |
| 18 | + $policy->add(Directive::FONT, Keyword::SELF); |
| 19 | + $policy->add(Directive::FORM_ACTION, Keyword::SELF); |
| 20 | + $policy->add(Directive::IMG, [ |
| 21 | + Keyword::SELF, |
| 22 | + 'data:', |
| 23 | + ]); |
| 24 | + $policy->add(Directive::MEDIA, Keyword::SELF); |
| 25 | + $policy->add(Directive::OBJECT, Keyword::NONE); |
| 26 | + |
| 27 | + $policy->add(Directive::SCRIPT, Keyword::SELF); |
| 28 | + |
| 29 | + $policy->add(Directive::STYLE, [ |
| 30 | + Keyword::SELF, |
| 31 | + Keyword::UNSAFE_INLINE, |
| 32 | + ]); |
| 33 | + |
| 34 | + // Fathom Analytics |
| 35 | + $policy->add(Directive::SCRIPT, 'cdn.usefathom.com'); |
| 36 | + $policy->add(Directive::CONNECT, 'cdn.usefathom.com'); |
| 37 | + $policy->add(Directive::SCRIPT, 'cdn-eu.usefathom.com'); |
| 38 | + $policy->add(Directive::CONNECT, 'cdn-eu.usefathom.com'); |
| 39 | + } |
| 40 | +} |
0 commit comments