我已经实现了一个 XSS 过滤器,如下所示,
@Override
public String getParameter(String parameter) {
String value = super.getParameter(parameter);
return stripXSS(value);
}
@Override
public String getHeader(String name) {
String value = super.getHeader(name);
return stripXSS(value);
}
private String stripXSS(String value)
{
System.err.println("Initial Value "+value);
if (value != null)
{
// NOTE: It's highly recommended to use the ESAPI library and uncomment the following line to
// avoid encoded attacks.
value = ESAPI.encoder().canonicalize(value);
System.err.println("Encoded Value "+value);
// Avoid null characters
value = value.replaceAll("\0", "");
// Remove all sections that match a pattern
for (Pattern scriptPattern : patterns){
value = scriptPattern.matcher(value).replaceAll("");
}
System.err.println("Pattern Value "+value);
}
System.err.println("Final Value "+value);
return value;
}
几乎所有请求都通过这些方法之一,但是当我使用 Struts 2ModelDriven
方法时,这些方法不会被调用。
Struts 如何检索参数,我可以在哪里剥离参数?