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
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
