Skip to content

Update HTML Sanitizer doc for max_input_length option #18147

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

Closed
Closed
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
68 changes: 68 additions & 0 deletions html_sanitizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,74 @@ the HTML sanitizer: ``src``, ``href``, ``lowsrc``, ``background`` and ``ping``.
->allowRelativeMedias()
);

Max Input Length
~~~~~~~~~~~~~~~~

To prevent DoS attacks, the HTML sanitizer limits the input length to ``20000`` by default.
Using this option, you can change the max input length, Inputs longer than this value will be truncated.

.. configuration-block::

.. code-block:: yaml

# config/packages/html_sanitizer.yaml
framework:
html_sanitizer:
sanitizers:
app.post_sanitizer:
# ...

# specifies the max input length. Inputs longer than this value will be
max_input_length: 30000 # default: 20000

.. code-block:: xml

<!-- config/packages/html_sanitizer.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:html-sanitizer>
<framework:sanitizer name="app.post_sanitizer">
<!-- specifies the max input length. Inputs longer than this value will be
truncated (default: 20000) -->
<framework:max-input-length>20000</framework:max-input-length>
</framework:sanitizer>
</framework:html-sanitizer>
</framework:config>
</container>

.. code-block:: php

// config/packages/framework.php
use Symfony\Config\FrameworkConfig;

return static function (FrameworkConfig $framework) {
$framework->htmlSanitizer()
->sanitizer('app.post_sanitizer')
// specifies the max input length. Inputs longer than this value will be
// truncated (default: 20000)
->withMaxInputLength(20000)
;
};

.. code-block:: php-standalone

use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;

$postSanitizer = new HtmlSanitizer(
(new HtmlSanitizerConfig())
// specifies the max input length. Inputs longer than this value will be
// truncated (default: 20000)
->withMaxInputLength(20000)
);

Custom Attribute Sanitizers
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down