-
Notifications
You must be signed in to change notification settings - Fork 0
/
csp-hashed-scripts1.html
51 lines (48 loc) · 2.16 KB
/
csp-hashed-scripts1.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-njl7zxiKalRhsBLsWOUobG2Oj/tPLHj1uypL4dOi1K8=' 'sha256-EeTNsJLV3kvLLMz7pxGfvh9u0JY8icKG5KjWnb8IZbQ=' '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 all script hashes & SRI (without errors)</title>
</head>
<body>
<p>
Strict CSP policy, which should allow to load scripts from origin and execute
all hashed inline scripts with hashes and SRI and it works (but not for FireFox - throw it out)!
</p>
<code>
default-src 'self'; script-src 'self' 'sha256-njl7zxiKalRhsBLsWOUobG2Oj/tPLHj1uypL4dOi1K8=' 'sha256-EeTNsJLV3kvLLMz7pxGfvh9u0JY8icKG5KjWnb8IZbQ=' 'sha256-aPK+M1Ic/YyssLh6WKqbat5IIKD6wwh/hyWW5D53D9k=' 'strict-dynamic' 'unsafe-inline';
</code>
<p>Tip: Open DevTools on the Console tab</p>
<a href="csp-hashed-scripts.html">CSP with inline script hashes 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" integrity="sha256-njl7zxiKalRhsBLsWOUobG2Oj/tPLHj1uypL4dOi1K8="></script>
<script src="folder/non-root-script.js" integrity="sha256-EeTNsJLV3kvLLMz7pxGfvh9u0JY8icKG5KjWnb8IZbQ="></script>
</body>
</html>