Class AntiSamy
java.lang.Object
org.owasp.validator.html.AntiSamy
This and the
CleanResults class are generally the only classes which the outside world
should be calling. The scan() method holds the meat and potatoes of AntiSamy. The file
contains a number of ways for scan()'ing, depending on the accessibility of the policy
file. However, it should be noted that the SAX scan type, which uses a SAX-based parser should be
the preferred way of using AntiSamy as it is much more efficient, and generally faster, than the
DOM-based parser.- Author:
- Arshan Dabirsiaghi
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionUse this method if caller has Streams rather than Strings for I/O.Thescan()family of methods are the only methods the outside world should be calling to invoke AntiSamy.This method scans the supplied HTML input and produces clean/sanitized results per the previously configured AntiSamy policy using the specified DOM or SAX parser.This method scans the supplied HTML input and produces clean/sanitized results per the supplied AntiSamy policy file using the DOM parser.This method scans the supplied HTML input and produces clean/sanitized results per the supplied AntiSamy policy file using the DOM parser.This method scans the supplied HTML input and produces clean/sanitized results per the supplied AntiSamy policy using the DOM parser.This method scans the supplied HTML input and produces clean/sanitized results per the supplied AntiSamy policy using the specified DOM or SAX parser.
-
Field Details
-
DOM
public static final int DOMDesignates DOM scan type which calls the DOM parser.- See Also:
-
SAX
public static final int SAXDesignates SAX scan type which calls the SAX parser.- See Also:
-
-
Constructor Details
-
AntiSamy
public AntiSamy() -
AntiSamy
-
-
Method Details
-
scan
Thescan()family of methods are the only methods the outside world should be calling to invoke AntiSamy. This is the primary method that most AntiSamy users should be using. This method scans the supplied HTML input and produces clean/sanitized results per the previously configured AntiSamy policy using the SAX parser.- Parameters:
taintedHTML- Untrusted HTML which may contain malicious code.- Returns:
- A
CleanResultsobject which contains information about the scan (including the results). - Throws:
ScanException- When there is a problem encountered while scanning the HTML input.PolicyException- When there is a problem validating or parsing the policy file.
-
scan
This method scans the supplied HTML input and produces clean/sanitized results per the previously configured AntiSamy policy using the specified DOM or SAX parser.- Parameters:
taintedHTML- Untrusted HTML which may contain malicious code.scanType- The type of scan (DOM or SAX).- Returns:
- A
CleanResultsobject which contains information about the scan (including the results). - Throws:
ScanException- When there is a problem encountered while scanning the HTML input.PolicyException- When there is a problem validating or parsing the policy file.
-
scan
This method scans the supplied HTML input and produces clean/sanitized results per the supplied AntiSamy policy using the DOM parser.- Parameters:
taintedHTML- Untrusted HTML which may contain malicious code.policy- The custom policy to enforce.- Returns:
- A
CleanResultsobject which contains information about the scan (including the results). - Throws:
ScanException- When there is a problem encountered while scanning the HTML input.PolicyException- When there is a problem validating or parsing the policy file.
-
scan
public CleanResults scan(String taintedHTML, Policy policy, int scanType) throws ScanException, PolicyException This method scans the supplied HTML input and produces clean/sanitized results per the supplied AntiSamy policy using the specified DOM or SAX parser.- Parameters:
taintedHTML- Untrusted HTML which may contain malicious code.policy- The custom policy to enforce.scanType- The type of scan (DOM or SAX).- Returns:
- A
CleanResultsobject which contains information about the scan (including the results). - Throws:
ScanException- When there is a problem encountered while scanning the HTML input.PolicyException- When there is a problem validating or parsing the policy file.
-
scan
Use this method if caller has Streams rather than Strings for I/O. This uses the SAX parser. It is useful for when the input being processed is expected to be very large and we don't validate, but rather simply encode as bytes are consumed from the stream.- Parameters:
reader- Reader that produces the input, possibly a little at a timewriter- Writer that receives the cleaned output, possibly a little at a timepolicy- Policy that directs the scan- Returns:
- CleanResults where the cleanHtml is null. If caller wants the clean HTML, it must capture the writer's contents. When using Streams, caller generally doesn't want to create a single string containing clean HTML.
- Throws:
ScanException- When there is a problem encountered while scanning the HTML input.
-
scan
public CleanResults scan(String taintedHTML, String policyFilename) throws ScanException, PolicyException This method scans the supplied HTML input and produces clean/sanitized results per the supplied AntiSamy policy file using the DOM parser.- Parameters:
taintedHTML- Untrusted HTML which may contain malicious code.policyFilename- The file name of the custom policy to enforce.- Returns:
- A
CleanResultsobject which contains information about the scan (including the results). - Throws:
ScanException- When there is a problem encountered while scanning the HTML input.PolicyException- When there is a problem validating or parsing the policy file.
-
scan
This method scans the supplied HTML input and produces clean/sanitized results per the supplied AntiSamy policy file using the DOM parser.- Parameters:
taintedHTML- Untrusted HTML which may contain malicious code.policyFile- The File object of the custom policy to enforce.- Returns:
- A
CleanResultsobject which contains information about the scan (including the results). - Throws:
ScanException- When there is a problem encountered while scanning the HTML input.PolicyException- When there is a problem validating or parsing the policy file.
-