Skip to content

Commit 7ba0c87

Browse files
committed
minor #16787 [HtmlSanitizer] Document the new component (wouterj)
This PR was merged into the 6.1 branch. Discussion ---------- [HtmlSanitizer] Document the new component Fixes #16332, fixes #16716, fixes #16804 A first start with the documentation for the new HTML sanitizer component. I'm using the same style as we did in the HttpClient documentation, as I think that worked pretty well. cc `@tgalopin` Commits ------- 5f3cfeb [HTML Sanitizer] Write documentation
2 parents 7688eb5 + 5f3cfeb commit 7ba0c87

File tree

8 files changed

+1102
-0
lines changed

8 files changed

+1102
-0
lines changed

html_sanitizer.rst

+1,027
Large diffs are not rendered by default.

index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Topics
4040
event_dispatcher
4141
forms
4242
frontend
43+
html_sanitizer
4344
http_cache
4445
http_client
4546
lock

reference/configuration/framework.rst

+11
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,17 @@ connection is verified for authenticity. Authenticating the certificate is not
11981198
enough to be sure about the server, so you should combine this with the
11991199
``verify_host`` option.
12001200

1201+
html_sanitizer
1202+
~~~~~~~~~~~~~~
1203+
1204+
.. versionadded:: 6.1
1205+
1206+
The HTML sanitizer configuration was introduced in Symfony 6.1.
1207+
1208+
The ``html_sanitizer`` option (and its children) are used to configure
1209+
custom HTML sanitizers. Read more about the options in the
1210+
:ref:`HTML sanitizer documentation <html-sanitizer-configuration>`.
1211+
12011212
profiler
12021213
~~~~~~~~
12031214

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
sanitize_html
2+
~~~~~~~~~~~~~
3+
4+
**type**: ``boolean`` **default**: ``false``
5+
6+
.. versionadded:: 6.1
7+
8+
The ``sanitize_html`` option was introduced in Symfony 6.1.
9+
10+
When ``true``, the text input will be sanitized using the
11+
:doc:`Symfony HTML Sanitizer component </html_sanitizer>` after the form is
12+
submitted. This protects the form input against XSS, clickjacking and CSS
13+
injection.
14+
15+
.. note::
16+
17+
You must :ref:`install the HTML sanitizer component <html-sanitizer-installation>`
18+
to use this option.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sanitizer
2+
~~~~~~~~~
3+
4+
**type**: ``string`` **default**: ``"default"``
5+
6+
.. versionadded:: 6.1
7+
8+
The ``sanitizer`` option was introduced in Symfony 6.1.
9+
10+
When `sanitize_html`_ is enabled, you can specify the name of a
11+
:ref:`custom sanitizer <html-sanitizer-configuration>` using this option.

reference/forms/types/text.rst

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ an empty string, explicitly set the ``empty_data`` option to an empty string.
5757

5858
.. include:: /reference/forms/types/options/row_attr.rst.inc
5959

60+
.. include:: /reference/forms/types/options/sanitize_html.rst.inc
61+
62+
.. include:: /reference/forms/types/options/sanitizer.rst.inc
63+
6064
.. include:: /reference/forms/types/options/trim.rst.inc
6165

6266
Overridden Options

reference/forms/types/textarea.rst

+11
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ Renders a ``textarea`` HTML element.
2222
``<textarea>``, consider using the FOSCKEditorBundle community bundle. Read
2323
`its documentation`_ to learn how to integrate it in your Symfony application.
2424

25+
.. caution::
26+
27+
When allowing users to type HTML code in the textarea (or using a
28+
WYSIWYG) editor, the application is vulnerable to XSS injection,
29+
clickjacking or CSS injection. Use the `sanitize_html`_ option to
30+
protect against these types of attacks.
31+
2532
Inherited Options
2633
-----------------
2734

@@ -61,6 +68,10 @@ The default value is ``''`` (the empty string).
6168

6269
.. include:: /reference/forms/types/options/row_attr.rst.inc
6370

71+
.. include:: /reference/forms/types/options/sanitize_html.rst.inc
72+
73+
.. include:: /reference/forms/types/options/sanitizer.rst.inc
74+
6475
.. include:: /reference/forms/types/options/trim.rst.inc
6576

6677
.. _`its documentation`: https://symfony.com/doc/current/bundles/FOSCKEditorBundle/index.html

reference/twig_reference.rst

+19
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,25 @@ trans
377377
Translates the text into the current language. More information in
378378
:ref:`Translation Filters <translation-filters>`.
379379

380+
sanitize_html
381+
~~~~~~~~~~~~~
382+
383+
.. versionadded:: 6.1
384+
385+
The ``sanitize_html()`` filter was introduced in Symfony 6.1.
386+
387+
.. code-block:: twig
388+
389+
{{ body|sanitize_html(sanitizer = "default") }}
390+
391+
``body``
392+
**type**: ``string``
393+
``sanitizer`` *(optional)*
394+
**type**: ``string`` **default**: ``"default"``
395+
396+
Sanitizes the text using the HTML Sanitizer component. More information in
397+
:ref:`HTML Sanitizer <html-sanitizer-twig>`.
398+
380399
yaml_encode
381400
~~~~~~~~~~~
382401

0 commit comments

Comments
 (0)