Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/1091-dashboard-security-hardening.md
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 0 additions & 6 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,6 @@
} catch (e) { /* localStorage unavailable or corrupt — keep the en default */ }
})();
</script>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap"
rel="stylesheet"
/>
</head>
<body class="bg-background text-fg font-sans">
<div id="root"></div>
Expand Down
5 changes: 5 additions & 0 deletions web/nginx.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 32 additions & 5 deletions web/package-lock.json

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

4 changes: 3 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion web/specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 `<head>` (before Google Fonts)
- Runs as the first script in `<head>` (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")
Expand Down
11 changes: 11 additions & 0 deletions web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
30 changes: 26 additions & 4 deletions web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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:",
Expand All @@ -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.
Expand All @@ -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: {
Expand Down
Loading