SecurityPolicyViolationEvent Class

The event fired when a content security policy is violated (https://w3c.github.io/webappsec-csp/#violation-events): at the element that caused the violation, else at the document or at the global object of the worker, when the violation is reported (https://w3c.github.io/webappsec-csp/#report-violation).

public sealed class SecurityPolicyViolationEvent : Event
Inheritance
Event SecurityPolicyViolationEvent

Constructors

NameDescription
SecurityPolicyViolationEvent(string, SecurityPolicyViolationEventInit?)Creates a security policy violation event with the given type and initialization dictionary.

SecurityPolicyViolationEvent(string, SecurityPolicyViolationEventInit?)

SecurityPolicyViolationEvent.cs

Creates a security policy violation event with the given type and initialization dictionary.

public SecurityPolicyViolationEvent(string type, SecurityPolicyViolationEventInit? eventInitDict = null)

Properties

NameDescription
BlockedUriGets the URL of the blocked resource (the URL of the request, not the URL of a redirect), without its fragment and credentials (only the scheme for a URL whose scheme is not HTTP(S)), or a keyword: inline, eval, wasm-eval, trusted-types-policy or trusted-types-sink.
ColumnNumberGets the column (1-based) of the script that caused the violation, or 0.
DispositionGets the disposition of the violated policy.
DocumentUriGets the URL of the document or worker whose policy is violated, without its fragment and credentials.
EffectiveDirectiveGets the name of the directive whose enforcement caused the violation (e.g. img-src when default-src applies to an image).
LineNumberGets the line (1-based) of the script that caused the violation, or 0.
OriginalPolicyGets the serialization of the violated policy.
ReferrerGets the referrer of the document whose policy is violated, without its fragment and credentials.
SampleGets the sample of the code or the value that caused the violation (e.g. the first 40 characters of an inline script), or the empty string.
SourceFileGets the URL of the script that caused the violation (stripped as SecurityPolicyViolationEvent.BlockedUri), or the empty string.
StatusCodeGets the HTTP status code of the response of the document or worker whose policy is violated.
ViolatedDirectiveGets the name of the violated directive: a historical alias of SecurityPolicyViolationEvent.EffectiveDirective.

Gets the URL of the blocked resource (the URL of the request, not the URL of a redirect), without its fragment and credentials (only the scheme for a URL whose scheme is not HTTP(S)), or a keyword: inline, eval, wasm-eval, trusted-types-policy or trusted-types-sink.

public string BlockedUri { get; }

Gets the column (1-based) of the script that caused the violation, or 0.

public uint ColumnNumber { get; }

Gets the URL of the document or worker whose policy is violated, without its fragment and credentials.

public string DocumentUri { get; }

Gets the name of the directive whose enforcement caused the violation (e.g. img-src when default-src applies to an image).

public string EffectiveDirective { get; }

Gets the line (1-based) of the script that caused the violation, or 0.

public uint LineNumber { get; }

Gets the serialization of the violated policy.

public string OriginalPolicy { get; }

Gets the referrer of the document whose policy is violated, without its fragment and credentials.

public string Referrer { get; }

Gets the sample of the code or the value that caused the violation (e.g. the first 40 characters of an inline script), or the empty string.

public string Sample { get; }

Gets the URL of the script that caused the violation (stripped as SecurityPolicyViolationEvent.BlockedUri), or the empty string.

public string SourceFile { get; }

Gets the HTTP status code of the response of the document or worker whose policy is violated.

public ushort StatusCode { get; }

Gets the name of the violated directive: a historical alias of SecurityPolicyViolationEvent.EffectiveDirective.

public string ViolatedDirective { get; }