Skip to content

[HtmlSanitizer] Document the new component #16787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,027 changes: 1,027 additions & 0 deletions html_sanitizer.rst

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Topics
event_dispatcher
forms
frontend
html_sanitizer
http_cache
http_client
lock
Expand Down
11 changes: 11 additions & 0 deletions reference/configuration/framework.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,17 @@ connection is verified for authenticity. Authenticating the certificate is not
enough to be sure about the server, so you should combine this with the
``verify_host`` option.

html_sanitizer
~~~~~~~~~~~~~~

.. versionadded:: 6.1

The HTML sanitizer configuration was introduced in Symfony 6.1.

The ``html_sanitizer`` option (and its children) are used to configure
custom HTML sanitizers. Read more about the options in the
:ref:`HTML sanitizer documentation <html-sanitizer-configuration>`.

profiler
~~~~~~~~

Expand Down
18 changes: 18 additions & 0 deletions reference/forms/types/options/sanitize_html.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sanitize_html
~~~~~~~~~~~~~

**type**: ``boolean`` **default**: ``false``

.. versionadded:: 6.1

The ``sanitize_html`` option was introduced in Symfony 6.1.

When ``true``, the text input will be sanitized using the
:doc:`Symfony HTML Sanitizer component </html_sanitizer>` after the form is
submitted. This protects the form input against XSS, clickjacking and CSS
injection.

.. note::

You must :ref:`install the HTML sanitizer component <html-sanitizer-installation>`
to use this option.
11 changes: 11 additions & 0 deletions reference/forms/types/options/sanitizer.rst.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sanitizer
~~~~~~~~~

**type**: ``string`` **default**: ``"default"``

.. versionadded:: 6.1

The ``sanitizer`` option was introduced in Symfony 6.1.

When `sanitize_html`_ is enabled, you can specify the name of a
:ref:`custom sanitizer <html-sanitizer-configuration>` using this option.
4 changes: 4 additions & 0 deletions reference/forms/types/text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ an empty string, explicitly set the ``empty_data`` option to an empty string.

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

.. include:: /reference/forms/types/options/sanitize_html.rst.inc

.. include:: /reference/forms/types/options/sanitizer.rst.inc

.. include:: /reference/forms/types/options/trim.rst.inc

Overridden Options
Expand Down
11 changes: 11 additions & 0 deletions reference/forms/types/textarea.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Renders a ``textarea`` HTML element.
``<textarea>``, consider using the FOSCKEditorBundle community bundle. Read
`its documentation`_ to learn how to integrate it in your Symfony application.

.. caution::

When allowing users to type HTML code in the textarea (or using a
WYSIWYG) editor, the application is vulnerable to XSS injection,
clickjacking or CSS injection. Use the `sanitize_html`_ option to
protect against these types of attacks.

Inherited Options
-----------------

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

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

.. include:: /reference/forms/types/options/sanitize_html.rst.inc

.. include:: /reference/forms/types/options/sanitizer.rst.inc

.. include:: /reference/forms/types/options/trim.rst.inc

.. _`its documentation`: https://symfony.com/doc/current/bundles/FOSCKEditorBundle/index.html
19 changes: 19 additions & 0 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,25 @@ trans
Translates the text into the current language. More information in
:ref:`Translation Filters <translation-filters>`.

sanitize_html
~~~~~~~~~~~~~

.. versionadded:: 6.1

The ``sanitize_html()`` filter was introduced in Symfony 6.1.

.. code-block:: twig

{{ body|sanitize_html(sanitizer = "default") }}

``body``
**type**: ``string``
``sanitizer`` *(optional)*
**type**: ``string`` **default**: ``"default"``

Sanitizes the text using the HTML Sanitizer component. More information in
:ref:`HTML Sanitizer <html-sanitizer-twig>`.

yaml_encode
~~~~~~~~~~~

Expand Down