ISE-ComProg-After-Midterm/screwdriver-3.5.6/box/snippets/java/XssSanitizer.java

38 lines
938 B
Java
Raw Normal View History

2020-10-29 09:38:56 +00:00
package +zoccolo+.web.sanitizer;
import org.owasp.validator.html.AntiSamy;
import org.owasp.validator.html.CleanResults;
import org.owasp.validator.html.Policy;
import org.owasp.validator.html.PolicyException;
import org.owasp.validator.html.ScanException;
public class XssSanitizer {
private AntiSamy antiSamy;
private Policy policy;
public XssSanitizer(String policyFilePath) throws PolicyException{
this.policy = Policy.getInstance(this.getClass().getResourceAsStream(policyFilePath));
this.antiSamy = new AntiSamy(this.policy);
}
public CleanResults scan(String input) throws ScanException, PolicyException{
if(input == null)
throw new ScanException("input parameter is null.");
CleanResults cleanResults = this.antiSamy.scan(input);
return cleanResults;
}
public AntiSamy getAntiSamy() {
return antiSamy;
}
public Policy getPolicy() {
return policy;
}
/* screwdriver_knife */
}