@@ -931,6 +931,73 @@ the HTML sanitizer: ``src``, ``href``, ``lowsrc``, ``background`` and ``ping``.
931931 ->allowRelativeMedias()
932932 );
933933
934+ Max Input Length
935+ ~~~~~~~~~~~~~~~~
936+
937+ In order to prevent `DoS attacks `_, by default the HTML sanitizer limits the
938+ input length to ``20000 `` characters (as measured by ``strlen($input) ``). All
939+ the contents exceeding that length will be truncated. Use this option to
940+ increase or decrease this limit:
941+
942+ .. configuration-block ::
943+
944+ .. code-block :: yaml
945+
946+ # config/packages/html_sanitizer.yaml
947+ framework :
948+ html_sanitizer :
949+ sanitizers :
950+ app.post_sanitizer :
951+ # ...
952+
953+ # inputs longer (in characters) than this value will be truncated
954+ max_input_length : 30000 # default: 20000
955+
956+ .. code-block :: xml
957+
958+ <!-- config/packages/html_sanitizer.xml -->
959+ <?xml version =" 1.0" encoding =" UTF-8" ?>
960+ <container xmlns =" http://symfony.com/schema/dic/services"
961+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
962+ xmlns : framework =" http://symfony.com/schema/dic/symfony"
963+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
964+ https://symfony.com/schema/dic/services/services-1.0.xsd
965+ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" >
966+
967+ <framework : config >
968+ <framework : html-sanitizer >
969+ <framework : sanitizer name =" app.post_sanitizer" >
970+ <!-- inputs longer (in characters) than this value will be truncated (default: 20000) -->
971+ <framework : max-input-length >20000</framework : max-input-length >
972+ </framework : sanitizer >
973+ </framework : html-sanitizer >
974+ </framework : config >
975+ </container >
976+
977+ .. code-block :: php
978+
979+ // config/packages/framework.php
980+ use Symfony\Config\FrameworkConfig;
981+
982+ return static function (FrameworkConfig $framework) {
983+ $framework->htmlSanitizer()
984+ ->sanitizer('app.post_sanitizer')
985+ // inputs longer (in characters) than this value will be 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+ // inputs longer (in characters) than this value will be truncated (default: 20000)
998+ ->withMaxInputLength(20000)
999+ );
1000+
9341001 Custom Attribute Sanitizers
9351002~~~~~~~~~~~~~~~~~~~~~~~~~~~
9361003
@@ -1013,3 +1080,4 @@ to enable it for an HTML sanitizer:
10131080
10141081 .. _`HTML Sanitizer W3C Standard Proposal` : https://wicg.github.io/sanitizer-api/
10151082.. _`W3C Standard Proposal` : https://wicg.github.io/sanitizer-api/
1083+ .. _`DoS attacks` : https://en.wikipedia.org/wiki/Denial-of-service_attack
0 commit comments