Skip to content

Commit 896477c

Browse files
committed
Upgrade OWASP sanitizer
This upgrades the OWASP sanitizer library to the latest version. Guava is removed from this version. https://github.com/OWASP/java-html-sanitizer/releases/tag/release-20220608.1 The order of noreferrer, nofollow, noopener is apparently random now, so I had to rewrite those tests to not care about order (OWASP/java-html-sanitizer#336).
1 parent 882c020 commit 896477c

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

NOTICE

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,9 @@ specific language governing permissions and limitations
1212
under the License.
1313

1414
This project includes:
15-
Checker Qual under The MIT License
1615
digipost-html-validator under Apache License, Version 2.0
17-
error-prone annotations under Apache 2.0
18-
FindBugs-jsr305 under The Apache Software License, Version 2.0
19-
Guava InternalFutureFailureAccess and InternalFutures under The Apache Software License, Version 2.0
20-
Guava ListenableFuture only under The Apache Software License, Version 2.0
21-
Guava: Google Core Libraries for Java under Apache License, Version 2.0
22-
J2ObjC Annotations under Apache License, Version 2.0
16+
Java 10 Shim under Apache License, Version 2.0
17+
Java 8 Shim under Apache License, Version 2.0
2318
OWASP Java HTML Sanitizer under Apache License, Version 2.0
2419
SLF4J API Module under MIT License
2520

pom.xml

+3-9
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838
<type>pom</type>
3939
<scope>import</scope>
4040
</dependency>
41-
<!-- Override Guava version of owasp-java-html-sanitizer to fix vulnerability -->
42-
<dependency>
43-
<groupId>com.google.guava</groupId>
44-
<artifactId>guava</artifactId>
45-
<version>32.1.2-jre</version>
46-
</dependency>
4741
</dependencies>
4842
</dependencyManagement>
4943

@@ -61,17 +55,17 @@
6155
<dependency>
6256
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
6357
<artifactId>owasp-java-html-sanitizer</artifactId>
64-
<version>20211018.2</version>
58+
<version>20240325.1</version>
6559
</dependency>
6660
<dependency>
6761
<groupId>org.slf4j</groupId>
6862
<artifactId>slf4j-api</artifactId>
69-
<version>1.7.32</version>
63+
<version>1.7.36</version>
7064
</dependency>
7165
<dependency>
7266
<groupId>commons-io</groupId>
7367
<artifactId>commons-io</artifactId>
74-
<version>2.11.0</version>
68+
<version>2.16.1</version>
7569
<scope>test</scope>
7670
</dependency>
7771
<dependency>

src/test/java/no/digipost/sanitizing/internal/RichHtmlValidatorTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import no.digipost.sanitizing.DigipostValidatingHtmlSanitizer;
1919
import no.digipost.sanitizing.exception.ValidationException;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
2021
import org.junit.jupiter.api.Test;
2122

2223
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -190,13 +191,19 @@ public void skal_tillate_maillenker_uten_target_blank() {
190191
@Test
191192
public void skal_bruke_target_blank_på_lenker_ved_andre_targets() {
192193
String validatedHtml = validator.sanitize("<a href=\"http://example.org\" target=\"_self\">Clicky clicky</a>", ApiHtmlValidatorPolicy.V2_VALIDATE_HTML_AND_CSS_POLICY);
193-
assertEquals("<a href=\"http://example.org\" target=\"_blank\" rel=\"nofollow noreferrer noopener\">Clicky clicky</a>", validatedHtml);
194+
assertTrue(validatedHtml.contains("target=\"_blank\""));
195+
assertTrue(validatedHtml.contains("noopener"));
196+
assertTrue(validatedHtml.contains("noreferrer"));
197+
assertTrue(validatedHtml.contains("nofollow"));
194198
}
195199

196200
@Test
197201
public void skal_legge_på_target_blank_ved_manglende_target() {
198202
String validatedHtml = validator.sanitize("<a href=\"http://example.org\">Clicky clicky</a>", ApiHtmlValidatorPolicy.V2_VALIDATE_HTML_AND_CSS_POLICY);
199-
assertEquals("<a href=\"http://example.org\" target=\"_blank\" rel=\"nofollow noreferrer noopener\">Clicky clicky</a>", validatedHtml);
203+
assertTrue(validatedHtml.contains("target=\"_blank\""));
204+
assertTrue(validatedHtml.contains("noopener"));
205+
assertTrue(validatedHtml.contains("noreferrer"));
206+
assertTrue(validatedHtml.contains("nofollow"));
200207
}
201208

202209
// https://nvd.nist.gov/vuln/detail/CVE-2021-42575

0 commit comments

Comments
 (0)