Interface nsIContentSecurityPolicyType

Hierarchy

Properties

blockAllMixedContent: bool

Returns whether this policy uses the directive block-all-mixed-content. Please note that block-all-mixed-content takes presedence in case the directive upgrade-insecure-requests is defined in the same policy and will therefore block all mixed content without even trying to perform an upgrade.

enforcesFrameAncestors: bool

Returns whether this policy enforces the frame-ancestors directive.

innerWindowID: number
policyCount: number

Returns the number of policies attached to this CSP instance. Useful with getPolicy().

referrer: string
requestPrincipal: nsIPrincipal

Get the various arguments needed to create a new request context for a CSP.

selfURI: nsIURI
skipAllowInlineStyleCheck: boolean

Warning: Do not set that attribute unless you know exactly what you are doing!

Primarily used to allow Devtools to edit inline styles!

upgradeInsecureRequests: bool

Returns whether this policy uses the directive upgrade-insecure-requests. Please note that upgrade-insecure-reqeusts also applies if the parent or including document (context) makes use of the directive.

Methods

  • Increases the reference count for this interface. The associated instance will not be deleted unless the reference count is returned to zero.

    Returns

    The resulting reference count.

    Returns number

  • Accessor method for a read-only pointer the policy object at a given index. Returns a null pointer if the index is larger than the current policy count.

    Parameters

    • index: number

    Returns CSPPolicyPtr

  • Parameters

    • aIID: object
    • Optional aInstancePtr: object

    Returns any

  • A run time mechanism for interface discovery.

    Returns

    NS_OK if the interface is supported by the associated instance, NS_NOINTERFACE if it is not.

    aInstancePtr must not be null.

    Parameters

    • aIID: object

      [in] A requested interface IID

    • aInstancePtr: object

      [out] A pointer to an interface pointer to receive the result.

    Returns void

  • Decreases the reference count for this interface. Generally, if the reference count returns to zero, the associated instance is deleted.

    Returns

    The resulting reference count.

    Returns number

  • Parse and install a CSP policy.

    Parameters

    • policyString: string
    • reportOnly: boolean

      Should this policy affect content, script and style processing or just send reports if it is violated?

    • deliveredViaMetaTag: boolean

      Indicates whether the policy was delivered via the meta tag.

    Returns void

  • Ensure we have a nsIEventTarget to use to label CSPReportSenderRunnable

    Parameters

    • aEventTarget: nsIEventTarget

    Returns void

  • Whether this policy allows eval and eval-like functions such as setTimeout("code string", time).

    Returns

    Whether or not the effects of the eval call should be allowed (block the call if false).

    Parameters

    • shouldReportViolations: boolean

      Whether or not the use of eval should be reported. This function returns "true" when violating report-only policies, but when any policy (report-only or otherwise) is violated, shouldReportViolations is true as well.

    Returns boolean

  • Whether this policy allows inline script or style.

    Returns

    Whether or not the effects of the inline style should be allowed (block the rules if false).

    Parameters

    • aDirective: nsIContentSecurityPolicy_CSPDirective
    • aHasUnsafeHash: bool

      Only hash this when the 'unsafe-hashes' directive is also specified.

    • aNonce: string

      The nonce string to check against the policy

    • aParserCreated: boolean

      If the script element was created by the HTML Parser

    • aTriggeringElement: Element

      The script element of the inline resource to hash. It can be null.

    • aCSPEventListener: nsICSPEventListener
    • aContentOfPseudoScript: string

      The content of the psuedo-script to compare to hash (and compare to the hashes listed in the policy)

    • aLineNumber: number

      The line number of the inline resource (used for reporting)

    • aColumnNumber: number

      The column number of the inline resource (used for reporting)

    Returns boolean

  • Whether this policy allows a navigation subject to the navigate-to policy.

    Returns

    Whether or not the effects of the navigation is allowed

    Parameters

    • aURI: nsIURI

      The target URI

    • aIsFormSubmission: boolean

      True if the navigation was initiated by a form submission. This is important since the form-action directive overrides navigate-to in that case.

    • aWasRedirected: boolean
    • aEnforceAllowlist: boolean

      True if the allowlist of allowed targets must be enforced. If this is true, the allowlist must be enforced even if 'unsafe-allow-redirects' is used. If 'unsafe-allow-redirects' is not used then the allowlist is always enforced

    Returns boolean

  • Whether this policy allows the evaluation (and compilation) of WASM code from functions like WebAssembly.compile.

    Returns

    Whether or not the effects of the WASM evaluation should be allowed (block the call if false).

    Parameters

    • shouldReportViolations: boolean

      Whether or not the use of WASM evaluation should be reported. This function returns "true" when violating report-only policies, but when any policy (report-only or otherwise) is violated, shouldReportViolations is true as well.

    Returns boolean

  • Delegate method called by the service when the protected document is loaded. Returns the union of all the sandbox flags contained in CSP policies. This is the most restrictive interpretation of flags set in multiple policies. See nsSandboxFlags.h for the possible flags.

    Returns

    sandbox flags or SANDBOXED_NONE if no sandbox directive exists

    Returns uint32_t

  • Accessor method for a read-only string version of the policy at a given index.

    Parameters

    • index: number

    Returns string

  • For each violated policy (of type violationType), log policy violation on the Error Console and send a report to report-uris present in the violated policies.

    Parameters

    • violationType: number

      one of the VIOLATION_TYPE_* constants, e.g. eval or wasm-eval

    • triggeringElement: Element

      the element that triggers this CSP violation. It can be null.

    • aCSPEventListener: nsICSPEventListener
    • sourceFile: string

      name of the source file containing the violation (if available)

    • scriptSample: string
    • lineNum: int32_t

      source line number of the violation (if available)

    • columnNum: int32_t

      source column number of the violation (if available)

    • nonce: string
    • content: string

    Returns void

  • Checks if a specific directive permits loading of a URI.

    Returns

    Whether or not the provided URI is allowed by CSP under the given directive. (block the pending operation if false).

    Parameters

    • aTriggeringElement: Element

      The element that triggers this CSP check. It can be null.

    • aCSPEventListener: nsICSPEventListener
    • aURI: nsIURI

      The URI about to be loaded or used.

    • aDir: nsIContentSecurityPolicy_CSPDirective

      The CSPDirective to query (see above constants *_DIRECTIVE).

    • aSpecific: boolean

      If "true" and the directive is specified to fall back to "default-src" when it's not explicitly provided, directivePermits will NOT try default-src when the specific directive is not used. Setting this to "false" allows CSP to fall back to default-src. This function behaves the same for both values of canUseDefault when querying directives that don't fall-back.

    • aSendViolationReports: boolean

      If true and the uri is not allowed then trigger violation reports. This should be false for caching or preloads.

    Returns boolean

  • Verifies ancestry as permitted by the policy.

    NOTE: Calls to this may trigger violation reports when queried, so this value should not be cached.

    Returns

    true if the frame's ancestors are all allowed by policy (except for report-only policies, which will send reports and then return true here when violated).

    Parameters

    • aLoadInfo: nsILoadInfo

      The loadinfo of the channel containing the protected resource

    Returns boolean

  • Initialize the object implementing nsISerializable, which must have been freshly constructed via CreateInstance. All data members that can't be set to default values must have been serialized by write, and should be read from aInputStream in the same order by this method.

    Parameters

    • aInputStream: nsIObjectInputStream

    Returns void

  • Called after the CSP object is created to fill in appropriate request context. Either use

    • aDocument (preferred), or if no document is available, then provide
    • aPrincipal, aSelfURI, aReferrer, aInnerWindowId explicitly.

    Parameters

    • aDocument: Document

    Returns void

  • Parameters

    • aRequestPrincipal: nsIPrincipal
    • aSelfURI: nsIURI
    • aReferrer: string
    • aInnerWindowId: number

    Returns void

  • Delegate method called by the service when sub-elements of the protected document are being loaded. Given a bit of information about the request, decides whether or not the policy is satisfied.

    Calls to this may trigger violation reports when queried, so this value should not be cached.

    aOriginalURIIfRedirect must be passed only if this loading is the result of a redirect. In this case, aOriginalURIIfRedirect must be the original URL.

    Parameters

    • aContentType: nsContentPolicyType
    • aCSPEventListener: nsICSPEventListener
    • aContentLocation: nsIURI
    • aOriginalURIIfRedirect: nsIURI
    • aSendViolationReports: bool
    • aNonce: string
    • aParserCreated: boolean

    Returns number

  • Returns the CSP in JSON notation.

    Returns string

  • Serialize the object implementing nsISerializable to aOutputStream, by writing each data member that must be recovered later to reconstitute a working replica of this object, in a canonical member and byte order, to aOutputStream.

    NB: a class that implements nsISerializable must also implement nsIClassInfo, in particular nsIClassInfo::GetClassID.

    Parameters

    • aOutputStream: nsIObjectOutputStream

    Returns void

Generated using TypeDoc