diff --git a/changelog/unreleased/1091-dashboard-security-hardening.md b/changelog/unreleased/1091-dashboard-security-hardening.md new file mode 100644 index 000000000..c479096c7 --- /dev/null +++ b/changelog/unreleased/1091-dashboard-security-hardening.md @@ -0,0 +1,3 @@ +# Dashboard security hardening + +The dashboard now bundles its fonts instead of loading them from Google Fonts, so no page (the login page included) contacts a third-party host and the Content-Security-Policy no longer allows one. The dashboard's nginx no longer shows its version in headers or error pages, production images no longer ship the test mock service worker, and the file editor (Monaco 0.58.0) bundles a DOMPurify release with recent advisories fixed and no longer loads remote images in hovers. No action is needed when upgrading. [PR #1091](https://github.com/GameplanePanel/Gameplane/pull/1091) diff --git a/web/index.html b/web/index.html index e47bdafc3..f44651df0 100644 --- a/web/index.html +++ b/web/index.html @@ -125,12 +125,6 @@ } catch (e) { /* localStorage unavailable or corrupt — keep the en default */ } })(); - - -
diff --git a/web/nginx.conf.template b/web/nginx.conf.template index e73959b3f..e58b106b3 100644 --- a/web/nginx.conf.template +++ b/web/nginx.conf.template @@ -92,6 +92,11 @@ server { listen [::]:8080; server_name _; + # No nginx version in the Server header or on nginx's own error pages: + # those reach unauthenticated visitors, who must never learn versions + # (login privacy, AGENTS.md core rule 3). + server_tokens off; + # Matches the ingress's nginx.ingress.kubernetes.io/proxy-body-size (see # charts/gameplane/values.yaml, ingress.annotations). Without this, nginx's # compiled-in 1m default rejects dashboard file/mod uploads with 413. diff --git a/web/package-lock.json b/web/package-lock.json index 2b2525e10..0cdaca9a7 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -9,6 +9,8 @@ "version": "0.4.3", "dependencies": { "@bjorn3/browser_wasi_shim": "0.4.2", + "@fontsource/geist": "5.3.0", + "@fontsource/jetbrains-mono": "5.3.0", "@heroui/react": "3.2.7", "@heroui/styles": "3.2.7", "@monaco-editor/loader": "^1.7.0", @@ -24,7 +26,7 @@ "@xterm/xterm": "^6.0.0", "clsx": "^2.1.1", "lucide-react": "^1.76.0", - "monaco-editor": "0.57.0", + "monaco-editor": "0.58.0", "react": "^19.3.1", "react-aria": "^3.53.1", "react-aria-components": "^1.22.1", @@ -863,6 +865,24 @@ } } }, + "node_modules/@fontsource/geist": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource/geist/-/geist-5.3.0.tgz", + "integrity": "sha512-u03ftlfVwb05uijq2jGDJ03/HKGqMKaNFk7KOhkpBUex8+BhrAOfMs/XciJ2UUNUX9fEsZbZQld/RWMA2oFU7g==", + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, + "node_modules/@fontsource/jetbrains-mono": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/@fontsource/jetbrains-mono/-/jetbrains-mono-5.3.0.tgz", + "integrity": "sha512-fqDfB5I9f1p1TV486aUgB9t8zP84P0O1FtQR5Ol9vjwPy+S+EIGlVYm1cvj2W5shcZMTg2nZFdVMoH5wFu8a1A==", + "license": "OFL-1.1", + "funding": { + "url": "https://github.com/sponsors/ayuhito" + } + }, "node_modules/@formatjs/cli": { "version": "6.20.0", "resolved": "https://registry.npmjs.org/@formatjs/cli/-/cli-6.20.0.tgz", @@ -4623,6 +4643,12 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/@vscode/diff": { + "version": "0.0.2-145", + "resolved": "https://registry.npmjs.org/@vscode/diff/-/diff-0.0.2-145.tgz", + "integrity": "sha512-atPcmNrAU4B8OsbrmqYlHbZREt//m8z52o400YA8uuvq3Be5wnmIhLoLqhMum7Jv7kRC0FE+m3WAUbaZF681wg==", + "license": "MIT" + }, "node_modules/@xterm/addon-fit": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@xterm/addon-fit/-/addon-fit-0.11.0.tgz", @@ -6919,12 +6945,13 @@ } }, "node_modules/monaco-editor": { - "version": "0.57.0", - "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.57.0.tgz", - "integrity": "sha512-5BkI9KGoqrNvBGUe15/QlZq3OooZ8WLg1AxTpaqHRCP3HNpzPPZKE2EDz8M7c+VRmCeUw1Brp4cx/PWm3kI/5A==", + "version": "0.58.0", + "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.58.0.tgz", + "integrity": "sha512-Lj5hlfT4zdM5GSG9VxTHslWnwibGBvO6d9Mq/+9zmb1CkTZnib4+uAZUKl1zg+tMHRgY2OGax6hHKZNBtldR1g==", "license": "MIT", "dependencies": { - "dompurify": "3.4.15", + "@vscode/diff": "0.0.2-145", + "dompurify": "3.4.17", "marked": "14.0.0" } }, diff --git a/web/package.json b/web/package.json index 0a6d07241..c25b2182e 100644 --- a/web/package.json +++ b/web/package.json @@ -28,6 +28,8 @@ }, "dependencies": { "@bjorn3/browser_wasi_shim": "0.4.2", + "@fontsource/geist": "5.3.0", + "@fontsource/jetbrains-mono": "5.3.0", "@heroui/react": "3.2.7", "@heroui/styles": "3.2.7", "@monaco-editor/loader": "^1.7.0", @@ -43,7 +45,7 @@ "@xterm/xterm": "^6.0.0", "clsx": "^2.1.1", "lucide-react": "^1.76.0", - "monaco-editor": "0.57.0", + "monaco-editor": "0.58.0", "react": "^19.3.1", "react-aria": "^3.53.1", "react-aria-components": "^1.22.1", diff --git a/web/specs.md b/web/specs.md index 3bb3130dc..aab6ae003 100644 --- a/web/specs.md +++ b/web/specs.md @@ -48,6 +48,8 @@ These are CRD/API contracts; no new rollout controls or visual flow are defined. **Internal readiness:** Dashboard nginx returns 404 for `/readyz`, including query strings and normalized paths, before SPA routing or API proxying. Kubelet probes reach the API directly; public traffic cannot consume its database readiness slot. The nginx proxy smoke test checks rejection against a live upstream and confirms ordinary proxying still works. +**Browser hardening:** nginx sends the SPA shell with a build-generated `Content-Security-Policy` (`cspHeader` in `vite.config.ts`: inline boot scripts allowed only by hash, no third-party script, style or font hosts), `X-Frame-Options: DENY`, `nosniff`, `Referrer-Policy: no-referrer` and HSTS. Fonts (Geist, JetBrains Mono) are bundled from `@fontsource/*`, so no page, the login page included, loads a third-party stylesheet or tells a font CDN who visits. nginx runs with `server_tokens off`, so neither its `Server` header nor its own error pages carry a version. Production builds drop `public/mockServiceWorker.js` (`dropMockWorker` in `vite.config.ts`); only the E2E mock mode serves it. + **Pre-auth privacy:** The login page and any unauthenticated screen must not leak internal state: no hostnames, cluster names, server counts, version strings, user lists, or "user not found" errors. See docs/security.md "pre-auth privacy" and CLAUDE.md rule 3. **Cluster-bound WebSocket:** Server streams carry the open server's explicit cluster and namespace. Reconnects retain that target; leaving the server view closes its streams. Changing an infrastructure selection cannot retarget a stream. Pod logs and PTY attach use the target Kubernetes client; remote agent streams use the configured authenticated gateway and fail closed when unavailable. @@ -158,7 +160,7 @@ This rule was enforced by lint and review throughout the rebuild: any rebuilt fi **Appearance selection:** Two mechanisms work together to avoid theme flicker on page load: 1. **Boot script in `index.html`** (T053; extended by feature 016 — see "User Theme Customization" below): - - Runs as the first script in `` (before Google Fonts) + - Runs as the first script in `` (before any stylesheet) - Reads `localStorage.getItem("gameplane-theme-prefs")` first (feature 016 prefs cache, authoritative); the legacy `gameplane-theme` key (light/dark/system only) remains the fallback when the prefs cache is absent - Resolves system theme via `window.matchMedia("(prefers-color-scheme: dark)")` - Sets `document.documentElement.classList` (add/remove "dark" and "light") and `document.documentElement.dataset.theme`, plus `data-theme-preset` ("pink" | "legacy") and `data-theme-type` ("preset" | "custom_colors") diff --git a/web/src/main.tsx b/web/src/main.tsx index 687cd73ec..27ab26d62 100644 --- a/web/src/main.tsx +++ b/web/src/main.tsx @@ -7,6 +7,17 @@ import { RouterProvider as AriaRouterProvider } from "react-aria-components"; import { routeTree } from "@/router/tree"; import { createAriaNavigate, createAriaUseHref } from "@/lib/ariaRouter"; import { AppI18nProvider } from "@/lib/i18n/I18nProvider"; +// Fonts are bundled, not loaded from Google Fonts: a third-party stylesheet +// would run in the dashboard origin on every page, the login page included, +// and the CSP would have to allow it (see cspHeader in vite.config.ts). +// The weights match what the design uses (Geist 400-700, JetBrains Mono 400-600). +import "@fontsource/geist/400.css"; +import "@fontsource/geist/500.css"; +import "@fontsource/geist/600.css"; +import "@fontsource/geist/700.css"; +import "@fontsource/jetbrains-mono/400.css"; +import "@fontsource/jetbrains-mono/500.css"; +import "@fontsource/jetbrains-mono/600.css"; import "@/styles/globals.css"; const router = createRouter({ routeTree }); diff --git a/web/vite.config.ts b/web/vite.config.ts index 0c219726b..447449058 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -3,7 +3,7 @@ import type { Plugin } from "vite"; import react from "@vitejs/plugin-react"; import { execFileSync } from "node:child_process"; import { createHash } from "node:crypto"; -import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -73,8 +73,8 @@ function cspHeader(): Plugin { const policy = [ "default-src 'self'", ["script-src 'self'", ...hashes].join(" "), - "style-src 'self' 'unsafe-inline' https://fonts.googleapis.com", - "font-src 'self' data: https://fonts.gstatic.com", + "style-src 'self' 'unsafe-inline'", + "font-src 'self' data:", "img-src 'self' data: blob: https:", "connect-src 'self'", "worker-src 'self' blob:", @@ -92,6 +92,28 @@ function cspHeader(): Plugin { }; } +// dropMockWorker removes public/mockServiceWorker.js from production builds. +// Only the E2E mock mode (`vite --mode mock`, served by the dev server, which +// reads public/ directly) registers it; a production image that still served +// it would hand any script on the dashboard origin a ready-made service +// worker that answers the dashboard's own requests and outlives the page. +function dropMockWorker(): Plugin { + let outDir = ""; + let mode = ""; + return { + name: "gameplane-drop-mock-worker", + apply: "build", + configResolved(config) { + outDir = path.resolve(config.root, config.build.outDir); + mode = config.mode; + }, + closeBundle() { + if (mode === "mock") return; + rmSync(path.join(outDir, "mockServiceWorker.js"), { force: true }); + }, + }; +} + // API target for the dev server's proxy. Defaults to the standard local // process; Playwright live-mode points it at a kubectl port-forward by // setting GAMEPLANE_API_URL=http://localhost:18080 before spawning vite. @@ -112,7 +134,7 @@ export default defineConfig({ // The TS client and its worker load on the first script edit. Prebundle their // dependencies so Vite does not reload the dashboard and close that file. optimizeDeps: { include: ["vscode-languageserver-protocol/browser", "@bjorn3/browser_wasi_shim"] }, - plugins: [react(), i18nFixtures(), i18nPseudo(), cspHeader()], + plugins: [react(), i18nFixtures(), i18nPseudo(), cspHeader(), dropMockWorker()], preview: { headers: isolationHeaders }, worker: { format: "es" }, resolve: {