MDN self-hosted library · e01.org

SecurityPolicyViolationEvent: sample property

Reporting API

Open notebook · 1 cells web-api-instance-property upstream source

Reporting API

The sample read-only property of the SecurityPolicyViolationEvent interface is a string representing a sample of the resource that caused the Content Security Policy (CSP) violation.

This is only for script-src* and style-src* violations, when the corresponding Content-Security-Policy directive contains the 'report-sample' keyword. In addition, this will only be populated if the resource is an inline script, event handler, or style — external resources causing a violation will not generate a sample.

[!NOTE] Violation reports should be considered attacker-controlled data. The content of this field should be sanitized before storing or rendering.

Value

A string containing a sample of the resource that caused the violation, usually the first 40 characters, or the empty string.

Examples

document.addEventListener("securitypolicyviolation", (e) => {
  console.log(e.sample);
});

Specifications

Browser compatibility

See also

  • CSPViolationReport.sample