|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +// get the CSP instance |
| 4 | +$csp = $this->response->getCSP(); |
| 5 | + |
3 | 6 | // specify the default directive treatment |
4 | | -$this->response->CSP->reportOnly(false); |
| 7 | +$csp->reportOnly(false); |
5 | 8 |
|
6 | 9 | // specify the origin to use if none provided for a directive |
7 | | -$this->response->CSP->setDefaultSrc('cdn.example.com'); |
| 10 | +$csp->setDefaultSrc('cdn.example.com'); |
8 | 11 |
|
9 | 12 | // specify the URL that "report-only" reports get sent to |
10 | | -$this->response->CSP->setReportURI('http://example.com/csp/reports'); |
| 13 | +$csp->setReportURI('http://example.com/csp/reports'); |
11 | 14 |
|
12 | 15 | // specify that HTTP requests be upgraded to HTTPS |
13 | | -$this->response->CSP->upgradeInsecureRequests(true); |
| 16 | +$csp->upgradeInsecureRequests(true); |
14 | 17 |
|
15 | 18 | // add types or origins to CSP directives |
16 | 19 | // assuming that the default treatment is to block rather than just report |
17 | | -$this->response->CSP->addBaseURI('example.com', true); // report only |
18 | | -$this->response->CSP->addChildSrc('https://youtube.com'); // blocked |
19 | | -$this->response->CSP->addConnectSrc('https://*.facebook.com', false); // blocked |
20 | | -$this->response->CSP->addFontSrc('fonts.example.com'); |
21 | | -$this->response->CSP->addFormAction('self'); |
22 | | -$this->response->CSP->addFrameAncestor('none', true); // report this one |
23 | | -$this->response->CSP->addImageSrc('cdn.example.com'); |
24 | | -$this->response->CSP->addMediaSrc('cdn.example.com'); |
25 | | -$this->response->CSP->addManifestSrc('cdn.example.com'); |
26 | | -$this->response->CSP->addObjectSrc('cdn.example.com', false); // reject from here |
27 | | -$this->response->CSP->addPluginType('application/pdf', false); // reject this media type |
28 | | -$this->response->CSP->addScriptSrc('scripts.example.com', true); // allow but report requests from here |
29 | | -$this->response->CSP->addStyleSrc('css.example.com'); |
30 | | -$this->response->CSP->addSandbox(['allow-forms', 'allow-scripts']); |
| 20 | +$csp->addBaseURI('example.com', true); // report only |
| 21 | +$csp->addChildSrc('https://youtube.com'); // blocked |
| 22 | +$csp->addConnectSrc('https://*.facebook.com', false); // blocked |
| 23 | +$csp->addFontSrc('fonts.example.com'); |
| 24 | +$csp->addFormAction('self'); |
| 25 | +$csp->addFrameAncestor('none', true); // report this one |
| 26 | +$csp->addImageSrc('cdn.example.com'); |
| 27 | +$csp->addMediaSrc('cdn.example.com'); |
| 28 | +$csp->addManifestSrc('cdn.example.com'); |
| 29 | +$csp->addObjectSrc('cdn.example.com', false); // reject from here |
| 30 | +$csp->addPluginType('application/pdf', false); // reject this media type |
| 31 | +$csp->addScriptSrc('scripts.example.com', true); // allow but report requests from here |
| 32 | +$csp->addStyleSrc('css.example.com'); |
| 33 | +$csp->addSandbox(['allow-forms', 'allow-scripts']); |
0 commit comments