This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org
Difference between revisions of "OWASP Java HTML Sanitizer Project"
(→Quick Download) |
m (→Quick Download) |
||
Line 61: | Line 61: | ||
== Quick Download == | == Quick Download == | ||
− | [https://owasp-java-html-sanitizer | + | [https://search.maven.org/remotecontent?filepath=com/googlecode/owasp-java-html-sanitizer/owasp-java-html-sanitizer/r239/owasp-java-html-sanitizer-r239.jar v239 at Maven Central]<br/> |
− | [ | + | [http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/index.html JavaDoc v239]<br/> |
== News and Events == | == News and Events == |
Revision as of 11:08, 7 July 2014
OWASP HTML Sanitizer ProjectThe OWASP HTML Sanitizer is a fast and easy to configure HTML Sanitizer written in Java which lets you include HTML authored by third-parties in your web application while protecting against XSS. The existing dependencies are on guava and JSR 305. The other jars are only needed by the test suite. The JSR 305 dependency is a compile-only dependency, only needed for annotations. This code was written with security best practices in mind, has an extensive test suite, and has undergone adversarial security review. A great place to get started using the OWASP Java HTML Sanitizer is here: https://code.google.com/p/owasp-java-html-sanitizer/wiki/GettingStarted. Benefits
LicensingThe OWASP HTML Sanitizer is free to use and is dual licensed under the Apache 2 License and the New BSD License. |
What is this?The OWASP HTML Sanitizer Projects provides Java based HTML sanitization of untrusted HTML! Code RepoOWASP HTML Sanitizer at Google Code Email ListQuestions? Please sign up for our Project Email List Project LeadersAuthor: Mike Samuel @ Related Projects
Ohloh |
Quick Downloadv239 at Maven Central News and Events
Change LogFor recent release notes, please visit the changelog on Google Code. Classifications
|
You can use prepackaged policies here: http://owasp-java-html-sanitizer.googlecode.com/svn/trunk/distrib/javadoc/org/owasp/html/Sanitizers.html.
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); String safeHTML = policy.sanitize(untrustedHTML);
or the tests show how to configure your own policy here: http://code.google.com/p/owasp-java-html-sanitizer/source/browse/trunk/src/tests/org/owasp/html/HtmlPolicyBuilderTest.java
PolicyFactory policy = new HtmlPolicyBuilder() .allowElements("a") .allowUrlProtocols("https") .allowAttributes("href").onElements("a") .requireRelNofollowOnLinks() .build(); String safeHTML = policy.sanitize(untrustedHTML);
or you can write custom policies to do things like changing h1s to divs with a certain class:
PolicyFactory policy = new HtmlPolicyBuilder() .allowElements("p") .allowElements( new ElementPolicy() { public String apply(String elementName, List<String> attrs) { attrs.add("class"); attrs.add("header-" + elementName); return "div"; } }, "h1", "h2", "h3", "h4", "h5", "h6")) .build(); String safeHTML = policy.sanitize(untrustedHTML);
- How was this project tested?
- This code was written with security best practices in mind, has an extensive test suite, and has undergone adversarial security review.
- How is this project deployed?
- This project is best deployed through Maven https://code.google.com/p/owasp-java-html-sanitizer/wiki/Maven