我的任务是防止我们的网站遭受跨站点脚本 (XSS)。这个概念对我来说是新的,我搜索了很多并得到了 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。请帮忙。