-
Notifications
You must be signed in to change notification settings - Fork 0
/
csp-hashed-scripts.html
51 lines (48 loc) · 1.78 KB
/
csp-hashed-scripts.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self' 'sha256-aPK+M1Ic/YyssLh6WKqbat5IIKD6wwh/hyWW5D53D9k=' 'strict-dynamic' 'unsafe-inline'; style-src 'self' 'unsafe-inline';"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSP with inline script hashes (with errors)</title>
</head>
<body>
<p>
Strict CSP policy, which should allow to load scripts from origin and execute
all hashed inline scripts with hashes, but it fails!
</p>
<code>
default-src 'self'; script-src 'self' 'sha256-aPK+M1Ic/YyssLh6WKqbat5IIKD6wwh/hyWW5D53D9k=' 'strict-dynamic' 'unsafe-inline';
</code>
<p>Tip: Open DevTools on the Console tab</p>
<a href="csp-hashed-scripts1.html">CSP with all script hashes & SRI page</a>
<br />
<a href="index.html">Simple CSP policy page</a>
<h2>Demo</h2>
<form action="#" style="width: 250px;">
<fieldset>
<legend>inline script</legend>
<span id="inline-script" style="color: red;">disabled</span>
</fieldset>
<fieldset>
<legend>/root-script.js</legend>
<span id="root-external-script" style="color: red;">disabled</span>
</fieldset>
<fieldset>
<legend>/folder/non-root-script.js</legend>
<span id="non-root-external-script" style="color: red;">disabled</span>
</fieldset>
</form>
<script>
const el = document.getElementById("inline-script");
el.innerText = "Ok";
el.style.color = "green";
console.log("inline script is allowed!");
</script>
<script src="root-script.js"></script>
<script src="folder/non-root-script.js"></script>
</body>
</html>