added CSP
This commit is contained in:
parent
dc30ebb35e
commit
3a79fd4488
2 changed files with 39 additions and 17 deletions
|
@ -3,6 +3,9 @@ import { VitePWA } from 'vite-plugin-pwa'
|
|||
|
||||
export default defineConfig({
|
||||
vite: {
|
||||
html: {
|
||||
cspNonce: 'KAAS_IS_AWESOME',
|
||||
},
|
||||
plugins: [
|
||||
VitePWA({
|
||||
mode: 'development',
|
||||
|
|
|
@ -4,13 +4,16 @@ import { installIntoGlobal } from "iterator-helpers-polyfill";
|
|||
|
||||
installIntoGlobal();
|
||||
|
||||
export default createHandler(() => (
|
||||
export default createHandler(({ nonce }) => {
|
||||
return (
|
||||
<StartServer
|
||||
document={({ assets, children, scripts }) => (
|
||||
document={({ assets, children, scripts }) => {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
||||
<meta property="csp-nonce" nonce={nonce} />
|
||||
{assets}
|
||||
</head>
|
||||
<body>
|
||||
|
@ -18,6 +21,22 @@ export default createHandler(() => (
|
|||
{scripts}
|
||||
</body>
|
||||
</html>
|
||||
)}
|
||||
/>
|
||||
));
|
||||
);
|
||||
}} />
|
||||
);
|
||||
}, event => {
|
||||
const nonce = crypto.randomUUID();
|
||||
const base = `'self' 'nonce-${nonce}'`;
|
||||
|
||||
const policies = {
|
||||
default: base,
|
||||
connect: `${base} ws://localhost:*`,
|
||||
style: `'self' data: https://fonts.googleapis.com 'unsafe-inline'`,
|
||||
// style: `${base} data: https://fonts.googleapis.com`,
|
||||
font: `${base} https://*.gstatic.com`,
|
||||
} as const;
|
||||
|
||||
event.response.headers.append('Content-Security-Policy', Object.entries(policies).map(([p, v]) => `${p}-src ${v}`).join('; '))
|
||||
|
||||
return { nonce };
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue