From be33ec6962fa3938ec028873e269632d5d8fa55a Mon Sep 17 00:00:00 2001 From: Mike Samuel Date: Mon, 18 Oct 2021 09:23:39 -0400 Subject: [PATCH] Render style tag content more strictly. This addresses a vulnerability where policies that allow `" + + "" + + "" + + "" + + "" + + "" + + ""; + PolicyFactory pf = new HtmlPolicyBuilder() + .allowElements("option", "select", "style", "svg") + .allowTextIn("style") + .toFactory(); + assertEquals( + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "", + pf.sanitize(input) + ); + } + + @Test + public static final void testSelectIsOdd() { + String input = ""; + PolicyFactory pf = new HtmlPolicyBuilder() + .allowElements("option", "select", "xmp") + .allowTextIn("xmp") + .toFactory(); + assertEquals( + "" + + "", + pf.sanitize(input) + ); + } + @Test public static final void testStyleGlobally() { PolicyFactory policyBuilder = new HtmlPolicyBuilder() @@ -449,7 +496,7 @@ static int fac(int n) { int ifac = 1; for (int i = 1; i <= n; ++i) { int ifacp = ifac * i; - if (ifacp < ifac) { throw new IllegalArgumentException("undeflow"); } + if (ifacp < ifac) { throw new IllegalArgumentException("underflow"); } ifac = ifacp; } return ifac; diff --git a/src/test/java/org/owasp/html/TagBalancingHtmlStreamRendererTest.java b/src/test/java/org/owasp/html/TagBalancingHtmlStreamRendererTest.java index 004e95cd..5195fde9 100644 --- a/src/test/java/org/owasp/html/TagBalancingHtmlStreamRendererTest.java +++ b/src/test/java/org/owasp/html/TagBalancingHtmlStreamRendererTest.java @@ -158,7 +158,9 @@ public final void testTextContent() { + "

Hello,

" + "

Hello" // Text allowed in special style tag. - + "

" + + "" // Whitespace allowed inside