--- title: 'CSP: sandbox' slug: Web/HTTP/Headers/Content-Security-Policy/sandbox tags: - CSP - XSS防御 - http头 - 安全 translation_of: Web/HTTP/Headers/Content-Security-Policy/sandbox ---
The HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) sandbox
directive enables a sandbox for the requested resource similar to the {{HTMLElement("iframe")}} {{htmlattrxref("sandbox", "iframe")}} attribute. It applies restrictions to a page's actions including preventing popups, preventing the execution of plugins and scripts, and enforcing a same-origin policy.
CSP version | 1.1 / 2 |
---|---|
Directive type | {{Glossary("Document directive")}} |
This directive is not supported in the {{HTMLElement("meta")}} element or by the {{HTTPHeader("Content-Security-policy-Report-Only")}} header field. |
Content-Security-Policy: sandbox; Content-Security-Policy: sandbox <value>;
<value>
可以选择是以下值之一:
allow-forms
allow-modals
allow-orientation-lock
allow-pointer-lock
allow-popups
window.open
,target="_blank"
,showModalDialog
)。如果未使用此关键字,则该功能将无提示失败。allow-popups-to-escape-sandbox
allow-presentation
allow-same-origin
allow-scripts
allow-top-navigation
Content-Security-Policy: sandbox allow-scripts;
Specification | Status | Comment |
---|---|---|
{{specName("CSP 3.0", "#directive-sandbox", "sandbox")}} | {{Spec2('CSP 3.0')}} | No changes. |
{{specName("CSP 1.1", "#directive-sandbox", "sandbox")}} | {{Spec2('CSP 1.1')}} | Initial definition. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("http.headers.csp.sandbox")}}