1 | <?php |
||
2 | |||
3 | namespace Signify\Extensions; |
||
4 | |||
5 | use SilverStripe\ORM\DataExtension; |
||
6 | use SilverStripe\Security\Permission; |
||
7 | use SilverStripe\Forms\FieldList; |
||
8 | use SilverStripe\Forms\OptionsetField; |
||
9 | use SilverStripe\Security\PermissionProvider; |
||
10 | |||
11 | class SecurityHeaderSiteconfigExtension extends DataExtension implements PermissionProvider |
||
12 | { |
||
13 | // The values are in this order to ensure backwards compatability with the old binary options. |
||
14 | public const CSP_WITH_REPORTING = 0; |
||
15 | |||
16 | public const CSP_WITHOUT_REPORTING = 2; |
||
17 | |||
18 | public const CSP_REPORTING_ONLY = 1; |
||
19 | |||
20 | public const CSP_DISABLE = 3; |
||
21 | |||
22 | private static $db = [ |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
23 | "CSPReportingOnly" => "Enum('0,2,1,3')", |
||
24 | ]; |
||
25 | |||
26 | public function updateCMSFields(FieldList $fields) |
||
27 | { |
||
28 | if (!Permission::check('ADMINISTER_CSP')) { |
||
29 | return; |
||
30 | } |
||
31 | |||
32 | $fields->addFieldToTab( |
||
33 | 'Root.Main', |
||
34 | OptionsetField::create( |
||
35 | 'CSPReportingOnly', |
||
36 | 'Content Security Policy', |
||
37 | [ |
||
38 | self::CSP_WITH_REPORTING => 'Enable Content Security Policy with reporting (recommended)', |
||
39 | self::CSP_WITHOUT_REPORTING => 'Enable Content Security Policy without reporting', |
||
40 | self::CSP_REPORTING_ONLY => 'Set Content Security Policy to report-only mode', |
||
41 | self::CSP_DISABLE => 'Disable Content Security Policy (not recommended)', |
||
42 | ] |
||
43 | ) |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | public function providePermissions() |
||
48 | { |
||
49 | $category = 'Content Security Policy'; |
||
50 | $permissions = [ |
||
51 | 'ADMINISTER_CSP' => [ |
||
52 | 'name' => 'Administer CSP', |
||
53 | 'category' => $category, |
||
54 | 'help' => 'Can administer settings related to the Content Security Policy' |
||
55 | ], |
||
56 | ]; |
||
57 | return $permissions; |
||
58 | } |
||
59 | } |
||
60 |