Skip to content
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

word-break in style is discarded because it is not considered a valid value in CSSSchema #192

Open
mrabhishek opened this issue Feb 3, 2020 · 3 comments

Comments

@mrabhishek
Copy link

mrabhishek commented Feb 3, 2020

input:

<div>
<table>
<td style="word-break: keep-all;">
</td>
</table>
</div>

policy:
Sanitizers.BLOCKS .and(Sanitizers.FORMATTING) .and(Sanitizers.LINKS) .and(Sanitizers.TABLES) .and(Sanitizers.IMAGES) .and(Sanitizers.STYLES) .and(.and(new HtmlPolicyBuilder() .allowElements("style") .allowAttributes("style").onElements("td", "table","div") .allowAttributes("type", "word-break").onElements("style") .toFactory());

Expected output (should contain word-break).

<div>
<table>
<td style="word-break: keep-all;">
</td>
</table>
</div>
@juanmacoo
Copy link

juanmacoo commented Apr 18, 2020

word-wrap does not have any similar behaviour to the property break-all. Is there a reason it is not included in the allowed attributes?

@mrabhishek
Copy link
Author

mrabhishek commented Dec 10, 2021

How do we get an answer for this one? It does not look like the default Style policy can be overridden - If not, then it means that there is no way to provide a custom CSS schema that can allow elements like word-break and display that are not part of the default CSS schema.

Looking for some explanation on why display is part of CSS definitions but not in the default schema that is used in Style,

https://github.com/OWASP/java-html-sanitizer/blob/main/src/main/java/org/owasp/html/CssSchema.java#L593

@csware
Copy link
Contributor

csware commented Jan 31, 2024

CSS properties defined in CssSchema but not on the default list can be allowed by adding:
.allowStyling(CssSchema.withProperties(List.of("word-break")))

The default CSS definitions can also be overwritten (inprinciple, but currently it does not work because of issue #313), by adding the following code to the HTMLPolicyBuilder:

              .allowStyling(
                  CssSchema.withProperties(
                      Map.of("word-break",
                          new CssSchema.Property(0,
                              Set.of("keep-all", "valid-values"),
                              Collections.emptyMap()))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants