From 577ea5af154549608ca125207ae3e93476b7e630 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Thu, 18 Jun 2026 12:15:14 -0400 Subject: [PATCH] [security] add a strict Content-Security-Policy to the HTML entry points Defense-in-depth against XSS for a client that holds storage credentials in memory. The critical directive is a strict script-src: 'self' + the hash of the inline theme-bootstrap + the nostr-tools CDN fallbacks, with no 'unsafe-inline' or 'unsafe-eval' (verified no bundle uses eval/Function/wasm). This blocks injected script/object elements, inline handlers, and base-tag hijack, so an injected payload cannot run and read the in-memory storage master key, the signer, or DM plaintext. connect/img/media stay broad because relays, R2/S3 endpoints, and video/thumbnail URLs are user/content defined; worker-src allows blob: for the WebTorrent module worker. Applied to index.html and embed.html. Test (tests/csp-policy.test.mjs) locks the inline-script hash to script-src and asserts script-src stays strict (no unsafe-inline/eval) with object-src 'none' and base-uri 'self'. Co-Authored-By: Claude Opus 4.8 --- embed.html | 11 ++++ index.html | 19 +++++++ tests/csp-policy.test.mjs | 103 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 tests/csp-policy.test.mjs diff --git a/embed.html b/embed.html index eefea746..14464d7c 100644 --- a/embed.html +++ b/embed.html @@ -2,6 +2,17 @@ + + bitvid | Embed diff --git a/index.html b/index.html index 7672fb65..b392f603 100644 --- a/index.html +++ b/index.html @@ -2,6 +2,25 @@ + + bitvid | Decentralized Video Sharing diff --git a/tests/csp-policy.test.mjs b/tests/csp-policy.test.mjs new file mode 100644 index 00000000..6f3e1bea --- /dev/null +++ b/tests/csp-policy.test.mjs @@ -0,0 +1,103 @@ +// Regression test for the Content-Security-Policy on the HTML entry points. +// +// SCN-csp-script-src-locks-inline-hash: +// Given index.html / embed.html ship a CSP whose security depends on a strict +// script-src (no 'unsafe-inline'), +// When the inline bootstrap