【发布时间】:2013-04-08 12:17:06
【问题描述】:
我的任务是防止我们的网站遭受跨站点脚本 (XSS)。这个概念对我来说是新的,我搜索了很多并得到了 owasp-java-html-sanitizer。我用
创建了自己的策略public static final PolicyFactory POLICY_DEFINITION = new HtmlPolicyBuilder()
通过使用.allowAttributes,我设计了它。
但是现在我一无所知如何使用它......我发现以下代码 sn-p:
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。 请帮忙。
【问题讨论】:
标签: java xss owasp html-sanitizing