Skip to content

Commit 05f272a

Browse files
ZBUG-3640 - fix for OWASP Sanitizer blocking message from displaying in webmail.
1 parent d34df4b commit 05f272a

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/main/java/org/owasp/html/ExtensibleHtmlStreamRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ protected static int checkHtmlCdataCloseable(String localName, StringBuilder sb)
388388
}
389389
break;
390390
case '>':
391-
if (i >= 2 && sb.charAt(i - 2) == '-' && sb.charAt(i - 2) == '-') {
391+
if (i >= 2 && sb.charAt(i - 2) == '-' && sb.charAt(i - 1) == '-') {
392392
if (innerStart < 0) {
393393
return i - 2;
394394
}

src/main/java/org/owasp/html/HtmlStreamRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private static int checkHtmlCdataCloseable(
341341
}
342342
break;
343343
case '>':
344-
if (i >= 2 && sb.charAt(i - 2) == '-' && sb.charAt(i - 2) == '-') {
344+
if (i >= 2 && sb.charAt(i - 2) == '-' && sb.charAt(i - 1) == '-') {
345345
if (innerStart < 0) { return i - 2; }
346346
// Merged start and end like <!--->
347347
if (innerStart + 6 > i) { return innerStart; }

src/test/java/org/owasp/html/HtmlPolicyBuilderTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,43 @@ public static final void testTextareaIsNotTextArea() {
994994
assertEquals("x<textArea>y</textArea>", textAreaPolicy.sanitize(input));
995995
}
996996

997+
// Testing CSS Child Combinator between two selector with case ".hdg-1>._inner"
998+
@Test
999+
public static final void testCSSChildCombinator() {
1000+
HtmlPolicyBuilder builder = new HtmlPolicyBuilder();
1001+
1002+
PolicyFactory factory = builder.allowElements("span","style","h1").allowTextIn("style","h1")
1003+
.allowAttributes("type").onElements("style").allowStyling()
1004+
.toFactory();
1005+
1006+
1007+
String toSanitize = "<style type=\"text/css\">\n"
1008+
+ "<!--\n"
1009+
+ ".hdg-1 {\n"
1010+
+ "width:100%;\n"
1011+
+ "}\n"
1012+
+ "\n"
1013+
+ ".hdg-1>._inner {\n"
1014+
+ "background-color: #999;\n"
1015+
+ "}\n"
1016+
+ "-->\n"
1017+
+ "</style>\n"
1018+
+ "<h1>Test</h1>\n"
1019+
+ "\n"
1020+
+ "<style>\n"
1021+
+ "<!--\n"
1022+
+ ".hdg-1 {\n"
1023+
+ "width:100%;\n"
1024+
+ "}\n"
1025+
+ "\n"
1026+
+ ".hdg-1>._inner {\n"
1027+
+ "background-color: #666;\n"
1028+
+ "}\n"
1029+
+ "-->\n"
1030+
+ "</style>";
1031+
assertEquals(toSanitize, factory.sanitize(toSanitize));
1032+
}
1033+
9971034
private static String apply(HtmlPolicyBuilder b) {
9981035
return apply(b, EXAMPLE);
9991036
}

0 commit comments

Comments
 (0)