Skip to content

Commit 1f8b4fa

Browse files
committed
Content-Security-Policy: sandbox specification
1 parent f97e365 commit 1f8b4fa

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

middleware/policy.es

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ const
6161
// default-src fallback
6262
= Array.from (defaults)
6363

64+
, sandboxes // base-uri
65+
// default-src fallback
66+
= [/*
67+
allow-forms
68+
, allow-popups
69+
, allow-modals
70+
, allow-scripts
71+
, allow-same-origin
72+
, allow-presentation
73+
, allow-pointer-lock
74+
, allow-top-navigation
75+
, allow-orientation-lock
76+
, allow-popups-to-escape-sandbox
77+
*/]
78+
6479

6580
, directives = [
6681
// Reporting directives
@@ -80,7 +95,10 @@ const
8095

8196
// Document directives
8297
, `base-uri ${ bases.join ` ` }`
83-
// , `sandbox ${ sandboxes.join ` ` }`
98+
// `sandbox ...` is not supported in the <meta> element
99+
// or by the Content-Security-policy-Report-Only header field.
100+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/sandbox
101+
, `sandbox ${ sandboxes.join ` ` }`
84102
// , `plugin-types ${ plugins.join ` ` }`
85103

86104
// Navigation Directives

middleware/policy.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ test ("Content-Security-Policy: base-uri", async t => {
248248
})
249249

250250

251+
test ("Content-Security-Policy: sandbox", async t => {
252+
253+
const
254+
server = (new Server).serve ``
255+
256+
, response = await
257+
fetch ('http://localhost:8181/')
258+
259+
, policy = response.headers.get ('content-security-policy')
260+
261+
262+
t.ok ( policy.includes (`sandbox`) )
263+
264+
server.close ``
265+
t.end ()
266+
})
267+
268+
251269
test ("Content-Security-Policy: block-all-mixed-content", async t => {
252270

253271
const

0 commit comments

Comments
 (0)