Skip to content

Commit 297d482

Browse files
committed
add content for secure Java libs
1 parent 0855d46 commit 297d482

1 file changed

Lines changed: 44 additions & 11 deletions

File tree

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,55 @@
1-
The OWASP [Java HTML Sanitizer][html-sanitizer-project] and OWASP [Java Encoder][java-encoder-project] projects
1+
The OWASP [Java Encoder][java-encoder-project] and OWASP [Java HTML Sanitizer][html-sanitizer-project] projects
22
are security libraries for Java web applications that provide output encoding and HTML input sanitization.
33

4-
The OWASP [JSON Sanitizer][json-sanitizer] Java library is used to ensure JSON input / output is standards compliant.
4+
The OWASP [JSON Sanitizer][json-sanitizer] Java library is used to ensure both JSON input and output
5+
are _reasonably_ safe for Java applications.
56

67
#### What are they?
78

8-
Java Encoder
9-
contextual output encoding as part of a defense in depth approach to preventing XSS
9+
Java Encoder package provides the Java application with contextual output encoding of HTML.
10+
It provides individual methods for HTML, URLs, JavaScript and CSS.
1011

11-
#### Why use the libraries?
12+
Java HTML Sanitizer is used to sanitize untrusted HTML so that it can be safely handled within a Java application.
13+
The JAR file is included in a Java application and then a policy is defined for it.
14+
15+
These are both established projects with a regular release history stretching back to 2013.
1216

13-
The use of these libraries is widely used to protect against
17+
The JSON Sanitizer is a Java component that will transform arbitrary JSON
18+
to well-formed JSON as defined by [RFC 4627][rfc4627].
19+
This can be used to accept JSON input from an untrusted source and then safely output JSON to other processes.
1420

15-
and remain widely used to this day.
21+
JSON Sanitizer is a widely used library provided by OWASP,
22+
and it is a direct dependents for many 1000s of other libraries and in many more applications.
23+
It is a project that was transferred to OWASP in 2021 by github user `mikesamuel`
24+
and so this OWASP library is identified as `com.mikesamuel:json-sanitizer`.
25+
26+
#### Why use the libraries?
1627

17-
These are both established projects with a regular release history from 2026 back to 2013.
28+
The use of both Java Encoder and Java HTML Sanitizer is part of a defense in depth approach
29+
to preventing [cross site scripting][csxss] (XSS) and other attacks.
30+
They are well established OWASP projects with 'Lab' status.
1831

19-
The OWASP [JSON Sanitizer][json-sanitizer] Java library is less well supported
20-
but should be considered for JSON specific output sanitization; it is a direct dependency for literally 1000s of projects.
32+
The OWASP [JSON Sanitizer][json-sanitizer] Java library is widely used,
33+
for example it is a direct dependency for literally [1000s of Java components][json-sanitizer-dependents],
34+
and should be considered for JSON specific output normalization and input validation.
35+
It is less well supported than the Java Encoder or Java HTML Sanitizer, version 1.2.2 was released in January 2021,
36+
but it is still stable and (really) useful.
2137

2238
#### How to use the libraries
2339

24-
[via Maven][java-encoder]
40+
Include the Java Encoder package into a Java application [via Maven][java-encoder].
41+
The '[How to Use the OWASP Java Encoder][java-encoder-usage]' documentation explains how to use it in various contexts,
42+
such as HTML, URLs, JavaScript and CSS.
43+
44+
Follow the [examples][html-sanitizer-examples] provided by Java HTML Sanitizer
45+
to include the utility and configure it with policy.
46+
47+
The JSON Sanitizer JAR file can be fetched from Maven Central, follow the [Getting Started][json-sanitizer-usage] guide:
48+
49+
```text
50+
import com.google.json.JsonSanitizer;
51+
String wellFormedJson = JsonSanitizer.sanitize(myJsonLikeString);
52+
```
2553

2654
#### References
2755

@@ -38,9 +66,14 @@ then [submit an issue][issue050304] or [edit on GitHub][edit050304].
3866
[csxss]: https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet
3967
[edit050304]: https://github.com/OWASP/DevGuide/blob/main/docs/en/05-implementation/03-secure-libraries/04-java-secure-libs.md
4068
[html-sanitizer]: https://github.com/OWASP/java-html-sanitizer/releases/latest/
69+
[html-sanitizer-examples]: https://github.com/OWASP/java-html-sanitizer/tree/main/owasp-java-html-sanitizer/src/main/java/org/owasp/html/examples
4170
[html-sanitizer-project]: https://owasp.org/www-project-java-html-sanitizer/
4271
[issue050304]: https://github.com/OWASP/DevGuide/issues/new?labels=content&template=request.md&title=Update:%2005-implementation/03-secure-libraries/04-java-secure-libs
4372
[java-encoder]: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.owasp.encoder%22
4473
[java-encoder-github]: https://github.com/OWASP/owasp-java-encoder/releases/latest/
4574
[java-encoder-project]: https://owasp.org/www-project-java-encoder/
75+
[java-encoder-usage]: https://owasp.org/www-project-java-encoder/#div-use
4676
[json-sanitizer]: https://github.com/OWASP/json-sanitizer/releases/latest/
77+
[json-sanitizer-dependents]: https://central.sonatype.com/artifact/com.mikesamuel/json-sanitizer/dependents
78+
[json-sanitizer-usage]: https://github.com/OWASP/json-sanitizer/blob/master/docs/getting_started.md
79+
[rfc4627]: https://www.ietf.org/rfc/rfc4627.txt

0 commit comments

Comments
 (0)