Module org.htmlunit

Class ContentSecurityPolicyViolation

java.lang.Object
org.htmlunit.html.csp.ContentSecurityPolicyViolation
All Implemented Interfaces:
Serializable

public final class ContentSecurityPolicyViolation extends Object implements Serializable
The details of a violation of the Content-Security-Policy of a page. The properties correspond to the ones of the securitypolicyviolation event (see CSP - Violation Events).
  • blockedUri: the blocked url; 'inline' for inline scripts, event handler attributes and javascript: urls, 'eval' for the evaluation of strings; only the scheme for urls without host (e.g. 'data'); for frame-ancestors the ancestor not allowed to embed the document
  • effectiveDirective: the directive whose enforcement caused the violation (e.g. 'script-src-elem', 'script-src-attr', 'script-src', 'connect-src', 'frame-ancestors')
  • sourceFile, lineNumber, columnNumber: the location of the code causing the violation; an empty string or 0 if not known
  • sample: the first 40 characters of the blocked code if the directive contains 'report-sample', an empty string otherwise
Author:
Ronald Brill
See Also:
  • Constructor Details

    • ContentSecurityPolicyViolation

      public ContentSecurityPolicyViolation(String documentUri, String blockedUri, String effectiveDirective, String originalPolicy, String sourceFile, String sample, int lineNumber, int columnNumber, int statusCode, boolean reportOnly)
      Ctor.
      Parameters:
      documentUri - the url of the document
      blockedUri - the blocked url
      effectiveDirective - the directive whose enforcement caused the violation
      originalPolicy - the policy (serialized) that was violated
      sourceFile - the url of the source causing the violation
      sample - the sample of the blocked code
      lineNumber - the line number in the source file
      columnNumber - the column number in the source file
      statusCode - the http status code of the document
      reportOnly - whether the violated policy is a report only policy
  • Method Details

    • getDocumentUri

      public String getDocumentUri()
      Returns the url of the document.
      Returns:
      the url of the document
    • getBlockedUri

      public String getBlockedUri()
      Returns the blocked url.
      Returns:
      the blocked url
    • getEffectiveDirective

      public String getEffectiveDirective()
      Returns the directive whose enforcement caused the violation.
      Returns:
      the directive whose enforcement caused the violation
    • getOriginalPolicy

      public String getOriginalPolicy()
      Returns the policy (serialized) that was violated.
      Returns:
      the policy (serialized) that was violated
    • getSourceFile

      public String getSourceFile()
      Returns the url of the source causing the violation.
      Returns:
      the url of the source causing the violation
    • getSample

      public String getSample()
      Returns the sample of the blocked code.
      Returns:
      the sample of the blocked code
    • getLineNumber

      public int getLineNumber()
      Returns the line number in the source file.
      Returns:
      the line number in the source file
    • getColumnNumber

      public int getColumnNumber()
      Returns the column number in the source file.
      Returns:
      the column number in the source file
    • getStatusCode

      public int getStatusCode()
      Returns the http status code of the document.
      Returns:
      the http status code of the document
    • getViolatedDirective

      public String getViolatedDirective()
      Returns the violated directive; same as getEffectiveDirective().
      Returns:
      the violated directive
    • isReportOnly

      public boolean isReportOnly()
      Returns whether the violated policy is a report only policy (Content-Security-Policy-Report-Only header); in this case the action was not blocked.
      Returns:
      true if the violated policy is a report only policy
    • getDisposition

      public String getDisposition()
      Returns the disposition of the violated policy ('enforce' or 'report').
      Returns:
      the disposition
    • toString

      public String toString()
      Overrides:
      toString in class Object