Skip to content

Commit

Permalink
Update tests due to Neko html dependency change
Browse files Browse the repository at this point in the history
  • Loading branch information
spassarop committed Mar 30, 2022
1 parent 05f041a commit 1bae19f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/test/java/org/owasp/validator/html/test/AntiSamyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1511,11 +1511,13 @@ public void entityReferenceEncodedInHtmlAttribute() throws ScanException, Policy
// Concern is that "&" is not being encoded and "#00058" was not being interpreted as ":"
// so the validations based on regexp passed and a browser would load "&:" together.
// All this when not using the XHTML serializer.

// UPDATE: Using a new HTML parser library starts decoding entities like #00058
Policy revised = policy.cloneWithDirective("useXHTML","false");
assertThat(as.scan("<p><a href=\"javascript&#00058x=1,%61%6c%65%72%74%28%22%62%6f%6f%6d%22%29\">xss</a></p>", revised, AntiSamy.DOM).getCleanHTML(),
containsString("javascript&amp;#00058"));
not(containsString("javascript")));
assertThat(as.scan("<p><a href=\"javascript&#00058x=1,%61%6c%65%72%74%28%22%62%6f%6f%6d%22%29\">xss</a></p>", revised, AntiSamy.SAX).getCleanHTML(),
containsString("javascript&amp;#00058"));
not(containsString("javascript")));
}

@Test
Expand Down Expand Up @@ -1716,5 +1718,18 @@ public void testSmuggledTagsInStyleContent() throws ScanException, PolicyExcepti
assertThat(as.scan("<select<style/>W<xmp<script>alert(1)</script>", revised2, AntiSamy.DOM).getCleanHTML(), not(containsString("script")));
assertThat(as.scan("<select<style/>W<xmp<script>alert(1)</script>", revised2, AntiSamy.SAX).getCleanHTML(), not(containsString("script")));
}

@Test(timeout = 3000)
public void testMalformedPIScan() {
// Certain malformed input including a malformed processing instruction may lead the parser to an internal memory error.
try {
as.scan("<!--><?a/", policy, AntiSamy.DOM).getCleanHTML();
as.scan("<!--><?a/", policy, AntiSamy.SAX).getCleanHTML();
} catch (ScanException ex) {
// It is OK, internal parser should fail.
} catch (Exception ex) {
fail("Parser should not throw a non-ScanException");
}
}
}

0 comments on commit 1bae19f

Please sign in to comment.