Skip to content

Commit

Permalink
add a straightforward guard to turn this off if we need to
Browse files Browse the repository at this point in the history
Signed-off-by: John Cowen <[email protected]>
  • Loading branch information
johncowen committed Jan 23, 2025
1 parent 47347c5 commit 4f6988a
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions packages/kuma-gui/vite.plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ export const kumaIndexHtmlVars = (): Plugin => {
transformIndexHtml: (template) => interpolate(template, htmlVars),
}
}
const server = (template: string = './index.html', vars: Partial<KumaHtmlVars> = {}) => async (server: PreviewServer | ViteDevServer) => {
const server = (
template: string = './index.html',
vars: Partial<KumaHtmlVars> = {},
csp: boolean = true,
) => async (server: PreviewServer | ViteDevServer) => {
server.middlewares.use('/', async (req, res, next) => {
const url = req.originalUrl || ''
const baseGuiPath = vars.baseGuiPath || '/gui'
Expand Down Expand Up @@ -67,16 +71,19 @@ const server = (template: string = './index.html', vars: Partial<KumaHtmlVars> =
}).filter(([_, value]) => typeof value !== 'undefined')),
} satisfies KumaHtmlVars,
)
res.setHeader('Content-Security-Policy', [
"default-src 'self'",
"script-src 'self'",
"script-src-elem 'self'",
"img-src 'self' data: ",
"style-src 'self' 'unsafe-inline'",
// in production connect-src would use kuma's environment variable for
// setting the location of the HTTP API (or just use the default)
"connect-src 'self' localhost:5681 https://kuma.io",
].join(';'))
if (csp) {
res.setHeader('Content-Security-Policy', [
"default-src 'self'",
"script-src 'self'",
"script-src-elem 'self'",
"img-src 'self' data: ",
"style-src 'self' 'unsafe-inline'",
// in production connect-src would use kuma's environment variable for
// setting the location of the HTTP API (or just use the default)
"connect-src 'self' localhost:5681 https://kuma.io",
].join(';'))
}

res.end(body)
} else {
next()
Expand Down

0 comments on commit 4f6988a

Please sign in to comment.