Skip to content

Commit 1545503

Browse files
authored
Merge pull request #8444 from kenjis/docs-improve-csp
docs: improve csp
2 parents ac50a3e + ab7a678 commit 1545503

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

user_guide_src/source/general/common_functions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ Miscellaneous Functions
226226
:rtype: string
227227

228228
Returns the nonce attribute for a script tag. For example: ``nonce="Eskdikejidojdk978Ad8jf"``.
229-
See :ref:`content-security-policy`.
229+
See :ref:`Content Security Policy <csp-using-functions>`.
230230

231231
.. php:function:: csp_style_nonce()
232232
233233
:returns: The CSP nonce attribute for style tag.
234234
:rtype: string
235235

236236
Returns the nonce attribute for a style tag. For example: ``nonce="Eskdikejidojdk978Ad8jf"``.
237-
See :ref:`content-security-policy`.
237+
See :ref:`Content Security Policy <csp-using-functions>`.
238238

239239
.. php:function:: csrf_token()
240240

user_guide_src/source/outgoing/csp.rst

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ the response's ``Content-Security-Policy`` header and offers various configurati
2121
options.
2222

2323
This sounds complex, and on some sites, can definitely be challenging. For many simple sites, though, where all content
24-
is served by the same domain (http://example.com), it is very simple to integrate.
24+
is served by the same domain (e.g., **http://example.com**), it is very simple to integrate.
2525

2626
As this is a complex subject, this user guide will not go over all of the details. For more information, you should
2727
visit the following sites:
@@ -88,7 +88,12 @@ Inline Content
8888

8989
It is possible to set a website to not protect even inline scripts and styles on its own pages, since this might have
9090
been the result of user-generated content. To protect against this, CSP allows you to specify a nonce within the
91-
``<style>`` and ``<script>`` tags, and to add those values to the response's header. This is a pain to handle in real
91+
``<style>`` and ``<script>`` tags, and to add those values to the response's header.
92+
93+
Using Placeholders
94+
==================
95+
96+
This is a pain to handle in real
9297
life, and is most secure when generated on the fly. To make this simple, you can include a ``{csp-style-nonce}`` or
9398
``{csp-script-nonce}`` placeholder in the tag and it will be handled for you automatically::
9499

@@ -109,7 +114,13 @@ life, and is most secure when generated on the fly. To make this simple, you can
109114

110115
.. warning:: If an attacker injects a string like ``<script {csp-script-nonce}>``, it might become the real nonce attribute with this functionality. You can customize the placeholder string with the ``$scriptNonceTag`` and ``$styleNonceTag`` properties in **app/Config/ContentSecurityPolicy.php**.
111116

112-
If you don't like this auto replacement functionality, you can turn it off with setting ``$autoNonce = false`` in **app/Config/ContentSecurityPolicy.php**.
117+
.. _csp-using-functions:
118+
119+
Using Functions
120+
===============
121+
122+
If you don't like the auto replacement functionality above, you can turn it off
123+
with setting ``$autoNonce = false`` in **app/Config/ContentSecurityPolicy.php**.
113124

114125
In this case, you can use the functions, :php:func:`csp_script_nonce()` and :php:func:`csp_style_nonce()`::
115126

0 commit comments

Comments
 (0)