Skip to content

Commit 1f73037

Browse files
authored
fix(browser): cleanup frame-ancestors from CSP header at coverage middleware (#8941)
1 parent 865073c commit 1f73037

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/browser/src/node/plugin.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ export default (parentServer: ParentBrowserProject, base = '/'): Plugin[] => {
7979
single: true,
8080
dev: true,
8181
setHeaders: (res) => {
82+
const csp = res.getHeader('Content-Security-Policy')
83+
if (typeof csp === 'string') {
84+
// add frame-ancestors to allow the iframe to be loaded by Vitest,
85+
// but keep the rest of the CSP
86+
res.setHeader(
87+
'Content-Security-Policy',
88+
csp.replace(/frame-ancestors [^;]+/, 'frame-ancestors *'),
89+
)
90+
}
8291
res.setHeader(
8392
'Cache-Control',
8493
'public,max-age=0,must-revalidate',

0 commit comments

Comments
 (0)