--- 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-formsallow-modalsallow-orientation-lockallow-pointer-lockallow-popupswindow.open,target="_blank",showModalDialog)。如果未使用此关键字,则该功能将无提示失败。allow-popups-to-escape-sandboxallow-presentationallow-same-originallow-scriptsallow-top-navigationContent-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. |
{{Compat("http.headers.csp.sandbox")}}