Contextual Output Encoding is a computer programming technique necessary to stop Cross-Site Scripting. This project is a Java 8+ simple-to-use drop-in high-performance encoder class with little baggage.
For more detailed documentation on the OWASP Java Encoder please visit https://owasp.org/www-project-java-encoder/.
You can download the core library from Maven Central.
JSP tags and EL functions are also available from Maven Central:
- encoder-jakarta-jsp - Jakarta Servlet 5.0+
- encoder-jsp - legacy
javax.servletAPI
The jars are also available in Central:
<dependency>
<groupId>org.owasp.encoder</groupId>
<artifactId>encoder</artifactId>
<version>1.4.0</version>
</dependency>
<!-- using Servlet Spec 5 in the jakarta.servlet package use: -->
<dependency>
<groupId>org.owasp.encoder</groupId>
<artifactId>encoder-jakarta-jsp</artifactId>
<version>1.4.0</version>
</dependency>
<!-- using the Legacy Servlet Spec in the javax.servlet package use: -->
<dependency>
<groupId>org.owasp.encoder</groupId>
<artifactId>encoder-jsp</artifactId>
<version>1.4.0</version>
</dependency>The OWASP Java Encoder library is intended for quick contextual encoding with very little
overhead, either in performance or usage. To get started, add the encoder dependency shown
above and import org.owasp.encoder.Encode.
Example usage:
PrintWriter out = ...;
out.println("<textarea>" + Encode.forHtml(userData) + "</textarea>");Please look at the javadoc for Encode to see the variety of contexts for which you can encode.
Happy Encoding!
Due to test cases for the encoder-jakarta-jsp project Java 17 is required to package and test
the project. Simply run:
mvn packageTo validate that the Jakarta JSP tags and EL functions work correctly, run the integration test:
mvn verify -PtestJakartaThe integration test requires a running Docker-compatible container runtime.
| JAR | Explicit JPMS Module | Automatic-Module-Name |
|---|---|---|
| encoder | owasp.encoder | org.owasp.encoder |
| encoder-jakarta-jsp | owasp.encoder.jakarta | org.owasp.encoder.jakarta |
| encoder-jsp | owasp.encoder.jsp | org.owasp.encoder.jsp |
| encoder-esapi | owasp.encoder.esapi | org.owasp.encoder.esapi |
The multi-release descriptors define the explicit Java 9+ module names. The manifest names intentionally retain their historical values for consumers that disable multi-release support or otherwise use automatic-module discovery.
| Lib | TagLib |
|---|---|
| encoder-jakarta-jsp | <%@taglib prefix="e" uri="owasp.encoder.jakarta"%> |
| encoder-jsp | <%@taglib prefix="e" uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project"%> |
The OWASP Java Encoder project is a multi-module Maven project:
$ mvn packageBenchmarks (currently in need of improvement) can be run with:
$ mvn verify -PbenchmarksReleases are done via central-publishing-maven-plugin:
mvn clean deploy -DperformRelease=trueThe team is happy to announce that version 1.4.0 has been released!
- feat: add XML 1.1 encoding support #88.
The team is happy to announce that version 1.3.1 has been released!
- fix: add OSGi related entries in the MANIFEST.MF file #82.
- fix: java.lang.NoSuchMethodError when running on Java 8 #80.
The team is happy to announce that version 1.3.0 has been released!
- Minimum JDK Requirement is now Java 8
- Requires Java 17 to build due to test case dependencies.
- Adds Java 9 Module name via Multi-Release Jars #77.
- Fixed compilation errors with the ESAPI Thunk #76.
- Adds support for Servlet Spec 5 using the
jakarta.servlet.*#75.- taglib : <%@taglib prefix="e" uri="owasp.encoder.jakarta"%>
The team is happy to announce that version 1.2.3 has been released!
The team is happy to announce that version 1.2.2 has been released!
- This is a minor release fixing documentation and licensing issues.
The team is happy to announce that version 1.2.1 has been released!
- The CDATA Encoder was modified so that it does not emit intermediate characters between adjacent CDATA sections.
- The documentation on gh-pages has been improved.
OWASP Java Encoder has been moved to GitHub. Version 1.2 was also released!
Please visit https://owasp.org/www-project-java-encoder/ to see detailed documentation and examples for each API.
We're happy to announce that version 1.1.1 has been released. Along with an important bug fix, we added ESAPI integration to replace the legacy ESAPI encoders with the OWASP Java Encoder.
We're happy to announce that version 1.1 has been released. Along with a few minor encoding enhancements, we improved performance, and added a JSP tag and function library.