Skip to content

Commit c07ea0f

Browse files
committed
Updated documentation
1 parent 2aef51a commit c07ea0f

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

user_guide_src/source/outgoing/csp.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,18 @@ In this case, you can use the functions, :php:func:`csp_script_nonce()` and :php
171171
<style <?= csp_style_nonce() ?>>
172172
. . .
173173
</style>
174+
175+
.. _csp-control-nonce-generation:
176+
177+
Control Nonce Generation
178+
====================
179+
180+
.. versionadded:: 4.8.0
181+
182+
By default, both the script and style nonces are generated automatically. If you want to only generate one of them,
183+
you can set ``$enableStyleNonce`` or ``$enableScriptNonce`` to false in **app/Config/ContentSecurityPolicy.php**:
184+
185+
.. literalinclude:: csp/016.php
186+
187+
By setting one of these to false, the corresponding nonce will not be generated, and the placeholder will be replaced with an empty string.
188+
This gives you the flexibility to use nonces for only one type of content if you choose, without affecting the other.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Config;
4+
5+
use CodeIgniter\Config\BaseConfig;
6+
7+
class ContentSecurityPolicy extends BaseConfig
8+
{
9+
// ...
10+
11+
public bool $enableStyleNonce = false;
12+
13+
public bool $enableScriptNonce = false;
14+
}

0 commit comments

Comments
 (0)