Skip to content

Commit

Permalink
web: update & move csp to svelte.config.js
Browse files Browse the repository at this point in the history
ough
  • Loading branch information
wukko committed Sep 18, 2024
1 parent 52599dd commit 026cb63
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@types/fluent-ffmpeg": "^2.1.25",
"@types/node": "^20.14.10",
"compare-versions": "^6.1.0",
"dotenv": "^16.0.1",
"eslint": "^8.57.0",
"glob": "^10.4.5",
"mdsvex": "^0.11.2",
Expand Down
21 changes: 0 additions & 21 deletions web/src/routes/_headers/+server.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
import env from "$lib/env";

const allowedScriptOrigins = [
"'self'",
"challenges.cloudflare.com",
env.PLAUSIBLE_HOST ? env.PLAUSIBLE_HOST : ""
]

export async function GET() {
const CSP = {
"connect-src": ["*"],
"default-src": ["'self'"],

"script-src": allowedScriptOrigins,
"script-src-attr": allowedScriptOrigins,
"frame-src": ["challenges.cloudflare.com"],
}

const _headers = {
"/*": {
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
"Content-Security-Policy":
Object.entries(CSP).map(
([directive, values]) => `${directive} ${values.join(' ')}`
).flat().join("; "),
}
}

Expand Down
43 changes: 38 additions & 5 deletions web/svelte.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import adapter from '@sveltejs/adapter-static';
import { mdsvex } from 'mdsvex';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { sveltePreprocess } from 'svelte-preprocess';
import "dotenv/config";
import adapter from "@sveltejs/adapter-static";

import { mdsvex } from "mdsvex";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
import { sveltePreprocess } from "svelte-preprocess";

/** @type {import('@sveltejs/kit').Config} */
const config = {
Expand Down Expand Up @@ -46,6 +48,37 @@ const config = {
precompress: false,
strict: true
}),
csp: {
mode: "hash",
directives: {
"connect-src": ["*"],
"default-src": ["none"],

"font-src": ["self"],
"style-src": ["self", "unsafe-inline"],
"img-src": ["self", "data:"],
"manifest-src": ["self"],
"worker-src": ["self"],

"object-src": ["none"],
"frame-src": [
"self",
"challenges.cloudflare.com"
],

"script-src": [
"self",
"wasm-unsafe-eval",
"challenges.cloudflare.com",

// eslint-disable-next-line no-undef
process.env.WEB_PLAUSIBLE_HOST ? process.env.WEB_PLAUSIBLE_HOST : "",

// hash of the theme preloader in app.html
"sha256-g67gIjM3G8yMbjbxyc3QUoVsKhdxgcQzCmSKXiZZo6s=",
]
}
},
env: {
publicPrefix: 'WEB_'
},
Expand Down

0 comments on commit 026cb63

Please sign in to comment.