Skip to content

Commit d2a2dff

Browse files
committed
docs: use getCSP() instead of CSP property
The CSP property is deprecated.
1 parent 6624395 commit d2a2dff

3 files changed

Lines changed: 29 additions & 23 deletions

File tree

user_guide_src/source/outgoing/response.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ call basis, by providing an optional second parameter to the adding method call.
170170
Runtime Configuration
171171
---------------------
172172

173-
If your application needs to make changes at run-time, you can access the instance at ``$this->response->CSP`` in your controllers. The
173+
If your application needs to make changes at run-time, you can access the instance at ``$this->response->getCSP()`` in your controllers. The
174174
class holds a number of methods that map pretty clearly to the appropriate header value that you need to set.
175175
Examples are shown below, with different combinations of parameters, though all accept either a directive
176176
name or an array of them:
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
<?php
22

3+
// get the CSP instance
4+
$csp = $this->response->getCSP();
5+
36
// specify the default directive treatment
4-
$this->response->CSP->reportOnly(false);
7+
$csp->reportOnly(false);
58

69
// 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');
811

912
// 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');
1114

1215
// specify that HTTP requests be upgraded to HTTPS
13-
$this->response->CSP->upgradeInsecureRequests(true);
16+
$csp->upgradeInsecureRequests(true);
1417

1518
// add types or origins to CSP directives
1619
// 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']);
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
$this->response->CSP->addChildSrc('https://youtube.com'); // allowed
4-
$this->response->CSP->reportOnly(true);
5-
$this->response->CSP->addChildSrc('https://metube.com'); // allowed but reported
6-
$this->response->CSP->addChildSrc('https://ourtube.com', false); // allowed
3+
// get the CSP instance
4+
$csp = $this->response->getCSP();
5+
6+
$csp->addChildSrc('https://youtube.com'); // allowed
7+
$csp->reportOnly(true);
8+
$csp->addChildSrc('https://metube.com'); // allowed but reported
9+
$csp->addChildSrc('https://ourtube.com', false); // allowed

0 commit comments

Comments
 (0)