[英]how to use policy of owasp-java-html-sanitizer on a jsp page
我负有防止我们的网站跨站点脚本(XSS)的任务。 这个概念对我来说并不陌生,我在Google上搜索了很多,并获得了owasp-java-html-sanitizer。 我制定了自己的政策
public static final PolicyFactory POLICY_DEFINITION = new HtmlPolicyBuilder()
通过使用.allowAttributes
,我对其进行了设计。 但是现在我不知道如何使用它...我发现了以下代码片段:
System.err.println("[Reading from STDIN]");
// Fetch the HTML to sanitize.
String html = CharStreams.toString(new InputStreamReader(System.in,
Charsets.UTF_8));
// Set up an output channel to receive the sanitized HTML.
HtmlStreamRenderer renderer = HtmlStreamRenderer.create(System.out,
// Receives notifications on a failure to write to the output.
new Handler<IOException>() {
public void handle(IOException ex) {
Throwables.propagate(ex); // System.out suppresses
// IOExceptions
}
},
// Our HTML parser is very lenient, but this receives
// notifications on
// truly bizarre inputs.
new Handler<String>() {
public void handle(String x) {
throw new AssertionError(x);
}
});
// Use the policy defined above to sanitize the HTML.
HtmlSanitizer.sanitize(html, POLICY_DEFINITION.apply(renderer));
}
但是如何将其应用于我的JSP,因为我认为这是针对简单的HTML。 请帮忙。
您可以将渲染器附加到StringWriter
而不是System.out
,但是仅使用策略的sanitize
方便方法可能会更容易:
public java.lang.String sanitize(@Nullable java.lang.String html)
方便功能,用于清理HTML字符串。
它返回安全插入到您的JSP页面中的HTML字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.