-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathexperimental_csp_allow_list_spec.ts
More file actions
116 lines (104 loc) · 3.9 KB
/
experimental_csp_allow_list_spec.ts
File metadata and controls
116 lines (104 loc) · 3.9 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import path from 'path'
import systemTests from '../lib/system-tests'
import Fixtures from '../lib/fixtures'
const e2ePath = Fixtures.projectPath('e2e')
const PORT = 3500
const onServer = function (app) {
app.get(`/csp_empty_style.css`, (req, res) => {
// instead of logging, check the color of the h1 inside csp_script_test.html to see if the h1 text color is purple to verify the script ran
res.sendFile(path.join(e2ePath, `static/csp_styles.css`))
})
app.get(`/csp_empty_script.js`, (req, res) => {
// log the host of the script to postMessage to verify if the script ran or not depending on the test
const script = `window.top.postMessage({ event: 'csp-script-ran', data: 'script src origin ${req.get('host')} script ran'}, '*')`
res.send(script)
})
app.get(`/csp_script_test.html`, (req, res) => {
const { csp } = req.query
res.setHeader('Content-Security-Policy', csp)
res.sendFile(path.join(e2ePath, `csp_script_test.html`))
})
}
// NOTE: 'navigate-to' is a CSP 3.0 feature and currently is not shipped with any major browser version. @see https://csplite.com/csp123/.
describe('e2e experimentalCspAllowList', () => {
systemTests.setup({
servers: [{
port: 4466,
onServer,
}],
settings: {
hosts: {
'*.foobar.com': '127.0.0.1',
},
e2e: {
allowCypressEnv: false,
},
},
})
describe('experimentalCspAllowList=true', () => {
systemTests.it('strips out [\'script-src-elem\', \'script-src\', \'default-src\', \'form-action\'] directives', {
browser: '!webkit', // TODO(webkit): fix+unskip
port: PORT,
spec: 'experimental_csp_allow_list_spec/with_allow_list_true.cy.ts',
snapshot: true,
expectedExitCode: 0,
config: {
videoCompression: false,
retries: 0,
experimentalCspAllowList: true,
},
})
systemTests.it('always strips known problematic directives and is passive with known working directives', {
browser: '!webkit', // TODO(webkit): fix+unskip
port: PORT,
spec: 'experimental_csp_allow_list_spec/with_allow_list_custom_or_true.cy.ts',
snapshot: true,
expectedExitCode: 0,
config: {
videoCompression: false,
retries: 0,
experimentalCspAllowList: true,
},
})
})
// NOTE: these tests do not 100% work in webkit and are problematic in CI with firefox.
describe('experimentalCspAllowList=[\'script-src-elem\', \'script-src\', \'default-src\', \'form-action\']', () => {
systemTests.it('works with [\'script-src-elem\', \'script-src\', \'default-src\'] directives', {
browser: ['chrome', 'electron'],
port: PORT,
spec: 'experimental_csp_allow_list_spec/with_allow_list_custom.cy.ts',
snapshot: true,
expectedExitCode: 0,
config: {
videoCompression: false,
retries: 0,
experimentalCspAllowList: ['script-src-elem', 'script-src', 'default-src'],
},
})
systemTests.it('always strips known problematic directives and is passive with known working directives', {
browser: ['chrome', 'electron'],
port: PORT,
spec: 'experimental_csp_allow_list_spec/with_allow_list_custom_or_true.cy.ts',
snapshot: true,
expectedExitCode: 0,
config: {
videoCompression: false,
retries: 0,
experimentalCspAllowList: ['script-src-elem', 'script-src', 'default-src', 'form-action'],
},
})
systemTests.it('works with [\'form-action\'] directives', {
// NOTE: firefox respects on form action, but the submit handler does not trigger a error
browser: ['chrome', 'electron'],
port: PORT,
spec: 'experimental_csp_allow_list_spec/form_action_with_allow_list_custom.cy.ts',
snapshot: true,
expectedExitCode: 1,
config: {
videoCompression: false,
retries: 0,
experimentalCspAllowList: ['form-action'],
},
})
})
})