Skip to content

[HtmlSanitizer] Add a blockAll helper #48358

@Neirda24

Description

@Neirda24

Description

At the moment the HtmlSanitizerConfig::class is defaulting to dropAll. Then we can "upgrade" some elements / attributes to be "blocked" or even "allowed". If we want to allow things then we have a per element methods and the two methods allowSafeElements & allowStaticElements.

If we want to have everything blocked (as opposed to droped) then we have to list all elements that we want to block manually. There is no easy way.
I thing this should be the default behaviour on form inputs : if the user writes <h1>My Title</h1> I expect the tool to block any HTML tag by default instead of either droping it (with a custom sanitizer and empty configuration) or just sanitizing attributes (with default sanitizer).

WDYT ?

Example

framework:
    html_sanitizer:
        sanitizers:
            block_all:
                block_all_known: true
                allow_elements:
                    b: '*'
                    i: '*'
                    ul: '*'
                    li: '*'
<?php

$sanitizer->sanitize(<<<'HTML'
<h1>My Title</h1>
<ul>
    <li><h3>Something :</h3> Hello there
</ul>
HTML
);

/* 
Would output :
My Title
<ul>
    <li>Something : Hello there
</ul>
*/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy