Skip to content

Commit b5e51aa

Browse files
Merge pull request #367 from crabnebula-dev/fix/csp-settings
fix: csp settings
2 parents 451287d + 6e68dca commit b5e51aa

File tree

5 files changed

+74
-97
lines changed

5 files changed

+74
-97
lines changed

clients/web/csp.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,43 @@ import {
66
WASM_UNSAFE_EVAL,
77
UNSAFE_EVAL,
88
} from "csp-header";
9+
import { env, argv } from "node:process";
10+
import { readFile, writeFile } from "node:fs/promises";
911

1012
export function generateCSP(isDev = false) {
13+
const FATHOM_HOST = env.VITE_FATHOM_URL
14+
? new URL(env.VITE_FATHOM_URL).host
15+
: undefined;
16+
1117
return getCSP({
1218
reportUri: isDev
1319
? ""
1420
: "https://o4506303762464768.ingest.sentry.io/api/4506303812272128/security/?sentry_key=57614e75ac5f8c480aed3a2dd1528f13",
1521
directives: {
1622
"default-src": [SELF],
1723
"frame-src": [SELF],
18-
"script-src": isDev ? [SELF, UNSAFE_EVAL] : [SELF, WASM_UNSAFE_EVAL],
19-
"style-src": isDev ? [SELF, UNSAFE_INLINE] : [SELF],
24+
"script-src": isDev
25+
? [SELF, UNSAFE_EVAL, FATHOM_HOST].filter(Boolean)
26+
: [SELF, WASM_UNSAFE_EVAL, FATHOM_HOST].filter(Boolean),
27+
"style-src": [SELF, UNSAFE_INLINE],
2028
"connect-src": [SELF, "127.0.0.1", "127.0.0.1:*", "ws://localhost:5173/"],
21-
"img-src": [SELF],
29+
"img-src": [SELF, FATHOM_HOST].filter(Boolean),
2230
"object-src": [NONE],
2331
},
2432
});
2533
}
2634

27-
console.log(generateCSP());
35+
if (argv.includes("-i")) {
36+
readFile("./netlify.toml", "utf-8").then((toml) =>
37+
writeFile(
38+
"./netlify.toml",
39+
toml.replace(
40+
/Content-Security-Policy-Report-Only=[^\n]+/,
41+
`Content-Security-Policy-Report-Only="${generateCSP()}"`,
42+
),
43+
"utf-8",
44+
).then(() => console.log("Updated CSP headers in netlify.toml")),
45+
);
46+
} else {
47+
console.log(generateCSP());
48+
}

clients/web/index.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,8 @@
1111
id="app"
1212
class="grid bg-navy-700 bg-opacity-70 grid-rows-[var(--header-height),calc(100vh-calc(var(--header-height)+var(--footer-height))),var(--footer-height)] h-screen"
1313
></div>
14-
<div
15-
style="
16-
z-index: -10;
17-
position: absolute;
18-
inset: 0px;
19-
opacity: 0.5;
20-
overflow: hidden;
21-
"
22-
>
23-
<img style="width: 100%; height: 100%" src="/bg.webp" aria-hidden />
14+
<div class="z-[-10] absolute inset-0 opacity-50 overflow-hidden">
15+
<img class="w-full h-full" src="/bg.webp" aria-hidden />
2416
</div>
2517
<!-- this one is handled by Vite. No need for subpath-->
2618
<script type="module" src="/src/render-client.tsx"></script>

clients/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"scripts": {
1010
"proto": "protoc --ts_out src/lib/proto --proto_path ../../crates/wire/proto ../../crates/wire/proto/common.proto ../../crates/wire/proto/instrument.proto ../../crates/wire/proto/logs.proto ../../crates/wire/proto/spans.proto ../../crates/wire/proto/tauri.proto ../../crates/wire/proto/sources.proto ../../crates/wire/proto/meta.proto ../../crates/wire/proto/health.proto",
1111
"dev": "pnpm proto --experimental_allow_proto3_optional && vite",
12+
"prebuild": "node csp.js -i",
1213
"build": "pnpm proto && vite build",
1314
"preview": "pnpm proto && vite preview",
1415
"format": "prettier --write --cache .",
@@ -23,7 +24,6 @@
2324
},
2425
"devDependencies": {
2526
"@protobuf-ts/protoc": "^2.9.4",
26-
"@sentry/netlify-build-plugin": "^1.1.1",
2727
"@shikijs/transformers": "^1.12.1",
2828
"@solidjs/testing-library": "^0.8.9",
2929
"@testing-library/jest-dom": "^6.4.8",

clients/web/pnpm-lock.yaml

Lines changed: 45 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clients/web/src/components/calls/detail-pane/traces/popover/tool-tip/row.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { type JSXElement, Show } from "solid-js";
33
export function Row(props: { title: string; children?: JSXElement }) {
44
return (
55
<tr class="grid grid-cols-2 text-left">
6-
<th style={{ "grid-column": props.children ? "" : "span 2" }}>
7-
{props.title}
8-
</th>
6+
<th class={props.children ? "" : "col-span-2"}>{props.title}</th>
97
<Show when={props.children}>
108
<td>{props.children}</td>
119
</Show>

0 commit comments

Comments
 (0)