Skip to content

Commit 9835e0a

Browse files
committed
minor #18147 Update HTML Sanitizer doc for max_input_length option (t.le-gacque, tristan-lg)
This PR was merged into the 6.2 branch. Discussion ---------- Update HTML Sanitizer doc for `max_input_length` option Add missing documentation for https://symfony.com/doc/current/html_sanitizer.html#allow-elements Related to the bug symfony/symfony#49040 Commits ------- 370b3d9 Apply suggestions from code review 7011d17 Update HTML Sanitizer doc for `max_input_length` option 6d2e21c Update HTML Sanitizer doc for `max_input_length` option ce02cd4 Update HTML Sanitizer doc for `max_input_length` option
2 parents 97f6761 + 370b3d9 commit 9835e0a

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

html_sanitizer.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,74 @@ the HTML sanitizer: ``src``, ``href``, ``lowsrc``, ``background`` and ``ping``.
931931
->allowRelativeMedias()
932932
);
933933
934+
Max Input Length
935+
~~~~~~~~~~~~~~~~
936+
937+
To prevent DoS attacks, the HTML sanitizer limits the input length to ``20000`` by default.
938+
Using this option, you can change the max input length, Inputs longer than this value will be truncated.
939+
940+
.. configuration-block::
941+
942+
.. code-block:: yaml
943+
944+
# config/packages/html_sanitizer.yaml
945+
framework:
946+
html_sanitizer:
947+
sanitizers:
948+
app.post_sanitizer:
949+
# ...
950+
951+
# specifies the max input length. Inputs longer than this value will be
952+
max_input_length: 30000 # default: 20000
953+
954+
.. code-block:: xml
955+
956+
<!-- config/packages/html_sanitizer.xml -->
957+
<?xml version="1.0" encoding="UTF-8" ?>
958+
<container xmlns="http://symfony.com/schema/dic/services"
959+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
960+
xmlns:framework="http://symfony.com/schema/dic/symfony"
961+
xsi:schemaLocation="http://symfony.com/schema/dic/services
962+
https://symfony.com/schema/dic/services/services-1.0.xsd
963+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
964+
965+
<framework:config>
966+
<framework:html-sanitizer>
967+
<framework:sanitizer name="app.post_sanitizer">
968+
<!-- specifies the max input length. Inputs longer than this value will be
969+
truncated (default: 20000) -->
970+
<framework:max-input-length>20000</framework:max-input-length>
971+
</framework:sanitizer>
972+
</framework:html-sanitizer>
973+
</framework:config>
974+
</container>
975+
976+
.. code-block:: php
977+
978+
// config/packages/framework.php
979+
use Symfony\Config\FrameworkConfig;
980+
981+
return static function (FrameworkConfig $framework) {
982+
$framework->htmlSanitizer()
983+
->sanitizer('app.post_sanitizer')
984+
// specifies the max input length. Inputs longer than this value will be
985+
// truncated (default: 20000)
986+
->withMaxInputLength(20000)
987+
;
988+
};
989+
990+
.. code-block:: php-standalone
991+
992+
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
993+
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;
994+
995+
$postSanitizer = new HtmlSanitizer(
996+
(new HtmlSanitizerConfig())
997+
// specifies the max input length. Inputs longer than this value will be
998+
// truncated (default: 20000)
999+
->withMaxInputLength(20000)
1000+
);
1001+
9341002
Custom Attribute Sanitizers
9351003
~~~~~~~~~~~~~~~~~~~~~~~~~~~
9361004

0 commit comments

Comments
 (0)