diff --git a/.env.example b/.env.example index 7032199fd4..3c1f741ebd 100644 --- a/.env.example +++ b/.env.example @@ -108,10 +108,18 @@ TRUST_PROXY=1 # Nonce-based CSP for the SPA HTML response. Off by default so existing # deployments are unaffected. Turn it on in report-only mode first, review the # violations your deployment actually produces, then set CSP_REPORT_ONLY=false. +# Only an explicit false/off/0/no enforces; anything unrecognized warns and stays +# report-only, so a typo cannot silently start blocking scripts. # CSP_ENABLED=false # CSP_REPORT_ONLY=true # CSP_REPORT_URI= +# The default policy accommodates what LibreChat actually loads at runtime: +# script-src 'wasm-unsafe-eval' HEIC image conversion compiles WebAssembly +# worker-src data: Monaco's loader bootstraps workers from data: +# Both are narrower than 'unsafe-eval'. Drop them via CSP_ADDITIONAL_DIRECTIVES +# only if your deployment uses neither the artifact code editor nor HEIC uploads. + # Add deployment-specific sources on top of LibreChat's defaults; they are # appended, never replacing them. Comma- or space-separated. Quote values # containing spaces. diff --git a/api/server/csp.spec.js b/api/server/csp.spec.js index b1de7a8fdf..2bf550be25 100644 --- a/api/server/csp.spec.js +++ b/api/server/csp.spec.js @@ -4,11 +4,17 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const mongoose = require('mongoose'); -/** Mirrors the SPA shell: an inline style, an inline script, and a bundled script. */ +/** + * Mirrors what a production `client/dist/index.html` actually contains: inline + * style, inline script, a module entry, and the module preloads Vite emits. + */ const INDEX_HTML = '