aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/http/headers/content-security-policy/worker-src
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/http/headers/content-security-policy/worker-src
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/http/headers/content-security-policy/worker-src')
-rw-r--r--files/zh-cn/web/http/headers/content-security-policy/worker-src/index.html92
1 files changed, 92 insertions, 0 deletions
diff --git a/files/zh-cn/web/http/headers/content-security-policy/worker-src/index.html b/files/zh-cn/web/http/headers/content-security-policy/worker-src/index.html
new file mode 100644
index 0000000000..538dfea028
--- /dev/null
+++ b/files/zh-cn/web/http/headers/content-security-policy/worker-src/index.html
@@ -0,0 +1,92 @@
+---
+title: 'CSP: worker-src'
+slug: Web/HTTP/Headers/Content-Security-Policy/worker-src
+translation_of: Web/HTTP/Headers/Content-Security-Policy/worker-src
+---
+<div>{{HTTPSidebar}}</div>
+
+<p>The HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) <code><strong>worker-src</strong></code> directive specifies valid sources for {{domxref("Worker")}}, {{domxref("SharedWorker")}}, or {{domxref("ServiceWorker")}} scripts.</p>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th scope="row">CSP version</th>
+ <td>3</td>
+ </tr>
+ <tr>
+ <th scope="row">Directive type</th>
+ <td>{{Glossary("Fetch directive")}}</td>
+ </tr>
+ <tr>
+ <th scope="row">Fallback</th>
+ <td>
+ <p>If this directive is absent, the user agent will first look for the {{CSP("child-src")}} directive, then the {{CSP("script-src")}} directive, then finally for the {{CSP("default-src")}} directive, when governing worker execution.</p>
+
+ <p>Chrome 59 and higher skips the {{CSP("child-src")}} directive.</p>
+
+ <p>Edge 17 skips the {{CSP("script-src")}} directive (<a href="https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/17415478/">bug</a>).</p>
+ </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Syntax">Syntax</h2>
+
+<p>One or more sources can be allowed for the <code>worker-src</code> policy:</p>
+
+<pre class="syntaxbox notranslate">Content-Security-Policy: worker-src &lt;source&gt;;
+Content-Security-Policy: worker-src &lt;source&gt; &lt;source&gt;;
+</pre>
+
+<h3 id="Sources">Sources</h3>
+
+<p>{{page("Web/HTTP/Headers/Content-Security-Policy/connect-src", "Sources")}}</p>
+
+<h2 id="Examples">Examples</h2>
+
+<h3 id="Violation_cases">Violation cases</h3>
+
+<p>Given this CSP header:</p>
+
+<pre class="brush: bash notranslate">Content-Security-Policy: worker-src https://example.com/</pre>
+
+<p>{{domxref("Worker")}}, {{domxref("SharedWorker")}}, {{domxref("ServiceWorker")}} are blocked and won't load:</p>
+
+<pre class="brush: html notranslate">&lt;script&gt;
+ var blockedWorker = new Worker("data:application/javascript,...");
+ blockedWorker = new SharedWorker("https://not-example.com/");
+ navigator.serviceWorker.register('https://not-example.com/sw.js');
+&lt;/script&gt;</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{specName("CSP 3.0", "#directive-worker-src", "worker-src")}}</td>
+ <td>{{Spec2('CSP 3.0')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("http.headers.csp.Content-Security-Policy.worker-src")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{HTTPHeader("Content-Security-Policy")}}</li>
+ <li><a href="/docs/Web/API/Web_Workers_API/Using_web_workers#Content_security_policy">CSP for Web Workers</a></li>
+ <li>{{domxref("Worker")}}, {{domxref("SharedWorker")}}, {{domxref("ServiceWorker")}}</li>
+</ul>