String html = "<script>alert('This is Daniel testing');</script><a href='javascript:alert("This is Daniel testing 2.");'>Testing</a> Testing."
PolicyFactory policy = new HtmlPolicyBuilder() // Allow http, https, mailto .allowStandardUrlProtocols() // Allow title attribute on any element .allowAttributes("title").globally() // Allow href on anchor elements .allowAttributes("href").onElements("a") // Allow the following elements .allowElements( "a", "p", "div", "i", "b", "strong", "em", "br", "ul", "ol", "li" ) .toFactory()
def courseDescription = policy.sanitize(html)render template: "sectionDetails/sectionDetailsCourseDescription", model: [courseDescription: courseDescription, section: params.first ? section : ""]<g:if test="${courseDescription || courseDescription?.length() > 0}">${raw(courseDescription)} </g:if>
Testing
xssThis is the first time I'm tying to use the sanitizer, but "xss" is being appended to the end. The script and link are sanitized so it looks like it's working. Is this behavior expected?This is a Grails app and I've included the relevant code below.
Controller:String html = "<script>alert('This is Daniel testing');</script><a href='javascript:alert("This is Daniel testing 2.");'>Testing</a> Testing."
PolicyFactory policy = new HtmlPolicyBuilder()// Allow http, https, mailto.allowStandardUrlProtocols()// Allow title attribute on any element.allowAttributes("title").globally()// Allow href on anchor elements.allowAttributes("href").onElements("a")// Allow the following elements.allowElements("a", "p", "div", "i", "b", "strong", "em","br", "ul", "ol", "li").toFactory()def courseDescription = policy.sanitize(html)render template: "sectionDetails/sectionDetailsCourseDescription", model: [courseDescription: courseDescription, section: params.first ? section : ""]
View:<g:if test="${courseDescription || courseDescription?.length() > 0}">${raw(courseDescription)} </g:if>
Output:Testingxss
{
String html = "<script>alert('This is Daniel testing');</script><a href='javascript:alert(\"This is Daniel testing 2.\");'>Testing</a> Testing.";
PolicyFactory policy = new HtmlPolicyBuilder()
// Allow http, https, mailto
.allowStandardUrlProtocols()
// Allow title attribute on any element
.allowAttributes("title").globally()
// Allow href on anchor elements
.allowAttributes("href").onElements("a")
// Allow the following elements
.allowElements(
"a", "p", "div", "i", "b", "strong", "em",
"br", "ul", "ol", "li"
)
.toFactory();
String courseDescription = policy.sanitize(html);
assertEquals("Testing Testing.", courseDescription);
}
You received this message because you are subscribed to the Google Groups "OWASP Java HTML Sanitizer Support" group.--
To unsubscribe from this group and stop receiving emails from it, send an email to owasp-java-html-saniti...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to owasp-java-html-sanitizer-support+unsubscribe@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to owasp-java-html-saniti...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "OWASP Java HTML Sanitizer Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to owasp-java-html-saniti...@googlegroups.com.