|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2007-2020, Arshan Dabirsiaghi, Jason Li |
| 2 | + * Copyright (c) 2007-2021, Arshan Dabirsiaghi, Jason Li |
3 | 3 | *
|
4 | 4 | * All rights reserved.
|
5 | 5 | *
|
|
35 | 35 | import static org.junit.Assert.fail;
|
36 | 36 | import static org.hamcrest.CoreMatchers.containsString;
|
37 | 37 | import static org.hamcrest.CoreMatchers.equalTo;
|
| 38 | +import static org.hamcrest.CoreMatchers.is; |
38 | 39 | import static org.hamcrest.CoreMatchers.not;
|
39 | 40 | import static org.hamcrest.MatcherAssert.assertThat;
|
40 | 41 |
|
|
62 | 63 | import org.owasp.validator.html.model.Attribute;
|
63 | 64 | import org.owasp.validator.html.model.Tag;
|
64 | 65 |
|
65 |
| - |
66 | 66 | /**
|
67 | 67 | * This class tests AntiSamy functionality and the basic policy file which
|
68 | 68 | * should be immune to XSS and CSS phishing attacks.
|
@@ -1454,4 +1454,29 @@ public void testGithubIssue48() throws ScanException, PolicyException {
|
1454 | 1454 | assertThat(as.scan(danglingMarkup2, policy, AntiSamy.SAX).getCleanHTML(), not(containsString("//evilactor.com/")));
|
1455 | 1455 | assertThat(as.scan(danglingMarkup2, policy, AntiSamy.DOM).getCleanHTML(), not(containsString("//evilactor.com/")));
|
1456 | 1456 | }
|
| 1457 | + |
| 1458 | + @Test |
| 1459 | + public void testGithubIssue62() { |
| 1460 | + // Concern is that when a processing instruction is at the root level, node removal gets messy and Null pointer exception arises. |
| 1461 | + // More test cases are added for PI removal. |
| 1462 | + |
| 1463 | + try{ |
| 1464 | + assertThat(as.scan("|<?ai aaa", policy, AntiSamy.DOM).getCleanHTML(), is("|")); |
| 1465 | + assertThat(as.scan("|<?ai aaa", policy, AntiSamy.SAX).getCleanHTML(), is("|")); |
| 1466 | + |
| 1467 | + assertThat(as.scan("<div>|<?ai aaa", policy, AntiSamy.DOM).getCleanHTML(), is("<div>|</div>")); |
| 1468 | + assertThat(as.scan("<div>|<?ai aaa", policy, AntiSamy.SAX).getCleanHTML(), is("<div>|</div>")); |
| 1469 | + |
| 1470 | + assertThat(as.scan("<div><?foo note=\"I am XML processing instruction. I wish to be excluded\" ?></div>", policy, AntiSamy.DOM) |
| 1471 | + .getCleanHTML(), not(containsString("<?foo"))); |
| 1472 | + assertThat(as.scan("<div><?foo note=\"I am XML processing instruction. I wish to be excluded\" ?></div>", policy, AntiSamy.SAX) |
| 1473 | + .getCleanHTML(), not(containsString("<?foo"))); |
| 1474 | + |
| 1475 | + assertThat(as.scan("<?xml-stylesheet type=\"text/css\" href=\"style.css\"?>", policy, AntiSamy.DOM).getCleanHTML(), is("")); |
| 1476 | + assertThat(as.scan("<?xml-stylesheet type=\"text/css\" href=\"style.css\"?>", policy, AntiSamy.SAX).getCleanHTML(), is("")); |
| 1477 | + |
| 1478 | + } catch (Exception exc) { |
| 1479 | + fail(exc.getMessage()); |
| 1480 | + } |
| 1481 | + } |
1457 | 1482 | }
|
0 commit comments