/
index.md
87 lines (63 loc) · 2.71 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: "CSP: script-src-elem"
slug: Web/HTTP/Headers/Content-Security-Policy/script-src-elem
page-type: http-csp-directive
browser-compat: http.headers.Content-Security-Policy.script-src-elem
---
{{HTTPSidebar}}
The HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) **`script-src-elem`** directive specifies valid sources for JavaScript {{HTMLElement("script")}} elements.
This directive only specifies valid sources in `<script>` elements (both script requests and blocks).
It does not apply to other JavaScript sources that can trigger script execution, such as inline script event handlers (`onclick`), script execution methods [gated on the "unsafe-eval" check](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_eval_expressions), and [XSLT stylesheets](/en-US/docs/Web/XSLT).
(Valid sources can be specified for all JavaScript script sources using {{CSP("script-src")}}, or just for inline script handlers using {{CSP("script-src-attr")}}.)
<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">{{CSP("default-src")}} fallback</th>
<td>
Yes.
If this directive is absent, the user agent will look for the {{CSP("script-src")}} directive, and if both of them are absent, fall back to <code>default-src</code> directive.
</td>
</tr>
</tbody>
</table>
## Syntax
One or more sources can be allowed for the `script-src-elem` policy:
```http
Content-Security-Policy: script-src-elem <source>;
Content-Security-Policy: script-src-elem <source> <source>;
```
`script-src-elem` can be used in conjunction with {{CSP("script-src")}}:
```http
Content-Security-Policy: script-src <source>;
Content-Security-Policy: script-src-elem <source>;
```
### Sources
`<source>` can be any one of the values listed in [CSP Source Values](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources).
Note that this same set of values can be used in all {{Glossary("fetch directive", "fetch directives")}} (and a [number of other directives](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#relevant_directives)).
## Examples
### Violation case
Given this CSP header:
```http
Content-Security-Policy: script-src-elem https://example.com/
```
…the following script is blocked and won't be loaded or executed:
```html
<script src="https://not-example.com/js/library.js"></script>
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{HTTPHeader("Content-Security-Policy")}}
- {{HTMLElement("script")}}
- {{CSP("script-src")}}
- {{CSP("script-src-attr")}}