Skip to content

Commit 68cdc67

Browse files
committed
add docs and changelog
1 parent 5931bf4 commit 68cdc67

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

‎user_guide_src/source/changelogs/v4.8.0.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ HTTP
321321
For example: ``php index.php command -- --myarg`` will pass ``--myarg`` as an argument instead of an option.
322322
- ``CLIRequest`` now supports options with values specified using an equals sign (e.g., ``--option=value``) in addition to the existing space-separated syntax (e.g., ``--option value``).
323323
This provides more flexibility in how you can pass options to CLI requests.
324+
- Added ``enable()`` and ``disable()`` methods to ``ContentSecurityPolicy`` to enable or disable the CSP header for the current request. See :ref:`csp-enable-disable`.
324325
- Added ``$enableStyleNonce`` and ``$enableScriptNonce`` options to ``Config\App`` to automatically add nonces to control whether to add nonces to style-* and script-* directives in the Content Security Policy (CSP) header when CSP is enabled. See :ref:`csp-control-nonce-generation` for details.
325326
- Added ``URI::withQuery()``, ``URI::withQueryArray()``, ``URI::withoutQueryVars()``, and ``URI::withOnlyQueryVars()`` to return cloned URIs with replaced or filtered query variables.
326327
- Added ``URI::withQueryVar()`` and ``URI::withQueryVars()`` to return a cloned URI with query variables added or replaced.

‎user_guide_src/source/outgoing/csp.rst‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ name or an array of them:
7878
The first parameter to each of the "add" methods is an appropriate string value,
7979
or an array of them.
8080

81+
.. _csp-enable-disable:
82+
83+
Enable or Disable CSP at Runtime
84+
================================
85+
86+
.. versionadded:: 4.8.0
87+
88+
You can enable or disable CSP for the current request by using the
89+
``enable()`` and ``disable()`` methods on the CSP instance.
90+
91+
For example, to enable/disable CSP for a specific response:
92+
93+
.. literalinclude:: csp/017.php
94+
95+
The runtime value takes precedence over the ``CSPEnabled`` configuration value
96+
for the current response.
97+
98+
These methods only affect the current response. After the response has been sent,
99+
the CSP instance is recreated and the value of ``CSPEnabled`` in
100+
**app/Config/App.php** is used as the default for subsequent requests.
101+
102+
This allows applications to keep CSP enabled globally while temporarily disabling
103+
it for specific responses, or enable it only where required.
104+
81105
Report Only
82106
===========
83107

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// get the CSP instance
4+
$csp = $this->response->getCSP();
5+
6+
// Disable CSP for the request
7+
$csp->disable();
8+
9+
// Re-enable CSP for the request
10+
$csp->enable();

0 commit comments

Comments
 (0)