Class CleanResults

java.lang.Object
org.owasp.validator.html.CleanResults

public class CleanResults extends Object
This class contains the results of a scan. It primarily provides access to the clean sanitized HTML, per the AntiSamy sanitization policy applied. It also provides access to some utility information, like possible error messages and error message counts.

WARNING: The ONLY output from the class you can completely rely on is the CleanResults output. As stated in the project README file, neither the getErrorMessages() nor the getNumberOfErrors() methods subtly answer the question "is this safe input?" in the affirmative if it returns an empty list. You must always use the sanitized 'clean' input and there is no way to be sure the input passed in had no attacks.

The serialization and deserialization process that is critical to the effectiveness of the sanitizer is purposefully lossy and will filter out attacks via a number of attack vectors. Unfortunately, one of the tradeoffs of this strategy is that AntiSamy doesn't always know in retrospect that an attack was seen. Thus, the getErrorMessages() API is there to help users understand whether their well-intentioned input meets the requirements of the system, not help a developer detect if an attack was present.

The list of error messages (available via getErrorMessages()) will let the user know what, if any HTML errors existed, and what, when possible, any security or validation-related errors that were detected, and what was done about them.

WARNING: As just stated, the absence of error messages does NOT mean there were no attacks in the input that were sanitized out. You CANNOT rely on the getErrorMessages() or getNumberOfErrors() methods to tell you if the input was dangerous. You MUST use the output of getCleanHTML() to ensure your output is safe.

Author:
Arshan Dabirsiaghi
  • Constructor Details

    • CleanResults

      public CleanResults()
    • CleanResults

      public CleanResults(long startOfScan, String cleanHTML, DocumentFragment XMLDocumentFragment, List<String> errorMessages)
      Create a clean set of results.
      Parameters:
      startOfScan - - The time when the scan started.
      cleanHTML - - The resulting clean HTML produced per the AntiSamy policy.
      XMLDocumentFragment - - The XML Document fragment version of the clean HTML produced during the sanitization process.
      errorMessages - - Messages describing any errors that occurred during sanitization.
    • CleanResults

      public CleanResults(long startOfScan, Callable<String> cleanHTML, DocumentFragment XMLDocumentFragment, List<String> errorMessages)
      Create a clean set of results.
      Parameters:
      startOfScan - - The time when the scan started.
      cleanHTML - - The resulting clean HTML produced per the AntiSamy policy.
      XMLDocumentFragment - - The XML Document fragment version of the clean HTML produced during the sanitization process.
      errorMessages - - Messages describing any errors that occurred during sanitization.
  • Method Details

    • getCleanHTML

      public String getCleanHTML()
      Return the filtered HTML as a String. This output is the ONLY output you can trust to be safe. The absence of error messages does NOT indicate the input was safe.
      Returns:
      A String object which contains the serialized, safe HTML.
    • getCleanXMLDocumentFragment

      public DocumentFragment getCleanXMLDocumentFragment()
      Return the DOM version of the clean HTML.
      Returns:
      The XML Document fragment version of the clean HTML produced during the sanitization process. This may be null, even if the clean HTML String is not null.
    • getErrorMessages

      public List<String> getErrorMessages()
      Return a list of error messages -- but an empty list returned does not mean there was no attack present, due to the serialization and deserialization process automatically cleaning up some attacks. Only the output of the getCleanHTML() should be considered safe. See the project README file and CleanResults class documentation for further discussion.
      Returns:
      An ArrayList object which contains the error messages, if any, after a scan.
      See Also:
    • getNumberOfErrors

      public int getNumberOfErrors()
      Return the number of errors identified, if any, during filtering. Note that 0 errors does NOT mean the input was safe. Only the output of getCleanHTML() can be considered safe.
      Returns:
      The number of errors encountered during filtering.
      See Also:
    • getScanTime

      public double getScanTime()
      Return the time elapsed during the scan.
      Returns:
      A double indicating the amount of time elapsed between the beginning and end of the scan in seconds.
    • getStartOfScan

      public long getStartOfScan()
      Get the time the scan started.
      Returns:
      time that scan started in milliseconds since epoch.