-
-
Notifications
You must be signed in to change notification settings - Fork 17
Strengthen CSP by removing unsafe-inline and unsafe-eval from script-src #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
48c0fb1
7d74278
0d4849a
5bffd2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| // Flip Computing Limited - flipcomputing.com | ||
|
|
||
| import * as acorn from "acorn"; | ||
| import ManifoldInit from "manifold-3d"; | ||
| import * as walk from "acorn-walk"; | ||
| import HavokPhysics from "@babylonjs/havok"; | ||
| import * as BABYLON from "@babylonjs/core"; | ||
|
|
@@ -386,13 +387,6 @@ export const flock = { | |
| throw new Error("Code too long (max 100KB)"); | ||
| } | ||
|
|
||
| // Basic syntax check | ||
| try { | ||
| new Function(code); // Just check if it parses | ||
| } catch (e) { | ||
| throw new Error(`Syntax error: ${e.message}`); | ||
| } | ||
|
|
||
| // Optional: Warn about patterns (don't block) | ||
| const warnings = []; | ||
| if (/eval\s*\(/.test(code)) { | ||
|
|
@@ -670,19 +664,24 @@ export const flock = { | |
| sameOrigin: true, | ||
| }); | ||
|
|
||
| // --- load SES text in parent and inject inline into iframe (CSP allows inline) --- | ||
| const sesResp = await fetch( | ||
| "vendor/ses/lockdown.umd.min.js", | ||
| ); | ||
| if (!sesResp.ok) | ||
| throw new Error( | ||
| `Failed to fetch SES: ${sesResp.status}`, | ||
| ); | ||
| const sesText = await sesResp.text(); | ||
| const sesScript = doc.createElement("script"); | ||
| sesScript.type = "text/javascript"; | ||
| sesScript.text = sesText; | ||
| doc.head.appendChild(sesScript); | ||
| // Load SES lockdown via src= so the parent's script-src 'self' policy | ||
| // is satisfied — injecting inline text would require 'unsafe-inline'. | ||
| await new Promise((resolve, reject) => { | ||
| const sesScript = doc.createElement("script"); | ||
| sesScript.type = "text/javascript"; | ||
| sesScript.onload = resolve; | ||
| sesScript.onerror = () => | ||
| reject( | ||
| new Error( | ||
| "Failed to load SES lockdown", | ||
| ), | ||
| ); | ||
| sesScript.src = new URL( | ||
| "vendor/ses/lockdown.umd.min.js", | ||
| document.baseURI, | ||
| ).href; | ||
| doc.head.appendChild(sesScript); | ||
| }); | ||
|
Comment on lines
+667
to
+684
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify iframe CSP and SES external loading code paths
rg -n -C2 "const csp =|script-src|sesScript\\.src|lockdown\\.umd\\.min\\.js" flock.jsRepository: flipcomputing/flock Length of output: 1005 🏁 Script executed: #!/bin/bash
# Check CSP application context and SES script location
echo "=== Checking CSP context (around line 1176) ==="
sed -n '1170,1185p' flock.js
echo -e "\n=== Checking if vendor/ses/lockdown.umd.min.js exists ==="
find . -name "lockdown.umd.min.js" 2>/dev/null || echo "File not found in current search"
echo -e "\n=== Checking SES loading code context (around line 666) ==="
sed -n '660,690p' flock.jsRepository: flipcomputing/flock Length of output: 2720 🏁 Script executed: #!/bin/bash
# Check vendor directory and SES files
echo "=== Checking for vendor directory ==="
ls -la vendor/ 2>/dev/null || echo "vendor/ directory does not exist"
echo -e "\n=== Searching for any SES-related files ==="
find . -iname "*ses*" -o -iname "*lockdown*" 2>/dev/null | head -20
echo -e "\n=== Checking package.json for SES dependency ==="
grep -i "ses" package.json 2>/dev/null || echo "No SES mention in package.json"
echo -e "\n=== Checking if this code path is executed/tested ==="
rg -n "replaceSandboxIframe\|lockdown\(\)" flock.js | head -10Repository: flipcomputing/flock Length of output: 316 🏁 Script executed: #!/bin/bash
# Check where replaceSandboxIframe is defined and called
echo "=== Finding replaceSandboxIframe definition ==="
rg -n "replaceSandboxIframe\s*[=:(]" flock.js | head -5
echo -e "\n=== Checking SES npm package installation ==="
ls -la node_modules/ses 2>/dev/null | head -5 || echo "SES not in node_modules"
echo -e "\n=== Checking actual SES file locations ==="
find node_modules/ses -name "lockdown*" 2>/dev/null | head -10
echo -e "\n=== Checking if vendor is built/created elsewhere ==="
rg -n "vendor.*ses\|lockdown.*umd" --type js | head -10Repository: flipcomputing/flock Length of output: 382 CSP blocks the SES script load — add The iframe CSP at line 1176 is Add Minimal fix-const csp = `default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline' 'unsafe-eval'`;
+const csp = `default-src 'none'; style-src 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'`;Note: Verify the SES file path 🤖 Prompt for AI Agents |
||
|
|
||
| // lockdown the iframe realm | ||
| win.lockdown(); | ||
|
|
@@ -1258,7 +1257,17 @@ export const flock = { | |
| flock.abortController = new AbortController(); | ||
|
|
||
| try { | ||
| await flock.BABYLON.InitializeCSG2Async(); | ||
| // Pre-initialize manifold-3d here so we can pass the instances | ||
| // directly to InitializeCSG2Async, bypassing its _LoadScriptModuleAsync | ||
| // path which injects an inline <script type="module"> — blocked by CSP. | ||
| const manifoldWasm = await ManifoldInit({ | ||
| locateFile: (f) => "./wasm/" + f, | ||
| }); | ||
| manifoldWasm.setup(); | ||
| await flock.BABYLON.InitializeCSG2Async({ | ||
| manifoldInstance: manifoldWasm.Manifold, | ||
| manifoldMeshInstance: manifoldWasm.Mesh, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Error initializing CSG2:", error); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| window.dataLayer = window.dataLayer || []; | ||
| function gtag() { dataLayer.push(arguments); } | ||
| gtag('js', new Date()); | ||
| gtag('config', 'G-QCGT3X072N', { | ||
| client_storage: 'none', // Prevents setting cookies | ||
| anonymize_ip: true // Hides IP addresses for privacy | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.