From 1ac50b6addc8bd6a1f173d7bdac0cb29aaab8253 Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Sat, 7 Mar 2026 09:36:59 -0500 Subject: [PATCH] security(H1): add Content Security Policy Add CSP in two layers: 1. Meta tag in index.html (works for all builds) 2. HTTP header via Electron session API (defense-in-depth) Policy: script-src 'self' blocks XSS from loading external scripts or executing inline scripts. style-src allows 'unsafe-inline' for Vue's style injection. connect-src allows ws/wss/http/https for configurable relay and API endpoints. Co-Authored-By: Claude Opus 4.6 --- apps/machine/electron/main.ts | 14 +++++++++++++- apps/machine/index.html | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/machine/electron/main.ts b/apps/machine/electron/main.ts index e3085d3..51f8bbe 100644 --- a/apps/machine/electron/main.ts +++ b/apps/machine/electron/main.ts @@ -6,7 +6,7 @@ * HAL hardware drivers run here (Node.js environment). */ -import { app, BrowserWindow, ipcMain } from 'electron' +import { app, BrowserWindow, ipcMain, session } from 'electron' import path from 'node:path' import fs from 'node:fs' import { fileURLToPath } from 'node:url' @@ -280,6 +280,18 @@ ipcMain.handle('hal:cleanup', async () => { // App lifecycle app.whenReady().then(() => { + // Enforce Content Security Policy via HTTP headers (defense-in-depth alongside meta tag) + session.defaultSession.webRequest.onHeadersReceived((details, callback) => { + callback({ + responseHeaders: { + ...details.responseHeaders, + 'Content-Security-Policy': [ + "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' ws: wss: http: https:; img-src 'self' data: blob:; font-src 'self'; frame-src 'none'; object-src 'none'", + ], + }, + }) + }) + initDatabase() // Seed cassettes from env/preset if DB table is empty. diff --git a/apps/machine/index.html b/apps/machine/index.html index b1d2992..cc57859 100644 --- a/apps/machine/index.html +++ b/apps/machine/index.html @@ -4,6 +4,20 @@ + + Lamassu ATM