Skip to content

proposal(15): CSP + sandbox hardening#13

Open
christian-byrne wants to merge 1 commit intoComfy-Org:mainfrom
christian-byrne:proposal/csp-security
Open

proposal(15): CSP + sandbox hardening#13
christian-byrne wants to merge 1 commit intoComfy-Org:mainfrom
christian-byrne:proposal/csp-security

Conversation

@christian-byrne
Copy link

Proposal #15: CSP + Sandbox Hardening

Security audit and hardening for the Electron app. This PR includes both a detailed proposal document and a working proof-of-concept implementation.

What This PR Does

  1. Content Security Policy — Adds a strict CSP meta tag to index.html: script-src 'self' (no 'unsafe-inline'), default-src 'none', restrictive resource origins
  2. Inline Script Extraction — Moves the 69-line inline <script> block from index.html:253-322 to renderer/init.js, enabling strict CSP without 'unsafe-inline'
  3. Explicit Sandbox — Adds sandbox: true to both launcher and ComfyUI BrowserWindow configs (already default since Electron 20, but now explicit)
  4. URL Validationshell.openExternal now only allows http: and https: protocols, preventing file://, smb://, and custom protocol handler abuse
  5. Path Validationopen-path IPC handler now resolves to absolute paths

Security Audit Findings (see proposal for full details)

Finding Severity Status
No Content Security Policy HIGH ✅ Fixed
No explicit process sandbox MEDIUM ✅ Fixed
Unvalidated shell.openExternal MEDIUM ✅ Fixed
Unvalidated shell.openPath LOW ✅ Fixed
No Electron fuses MEDIUM 📋 Documented (build-time, future)
linkify() quote escaping gap LOW 📋 Documented

Files Changed

  • index.html — CSP meta tag + inline script → external file reference
  • renderer/init.jsNew — extracted initialization code
  • main.jssandbox: true on both BrowserWindow configs
  • lib/ipc.js — URL protocol validation + path resolution
  • .github/proposals/proposal-csp-security.md — Full security audit with IPC surface analysis, fuse recommendations, and migration roadmap

What's NOT in This PR (future work)

  • Electron fuses (@electron/fuses) — requires build pipeline integration
  • CSP headers for ComfyUI windows (they load http://127.0.0.1:PORT)
  • IPC sender validation (verify message origin webContents)

Dependencies

Proposal #1 (electron-vite) is listed as a dependency but this PR actually works standalone — the inline script extraction was done manually without needing a bundler.

Concerns

  • style-src 'unsafe-inline' is still needed because the codebase uses inline style attributes extensively. This is acceptable per Electron security guidelines.
  • The GrantFileProtocolExtraPrivileges fuse (future) needs testing since the app uses loadFile() to load index.html.

Security audit and hardening for the Electron app:

- Add strict Content Security Policy meta tag (script-src 'self', no unsafe-inline)
- Extract inline <script> block from index.html to renderer/init.js
- Add explicit sandbox: true to both launcher and ComfyUI BrowserWindows
- Validate shell.openExternal URLs (restrict to http/https protocols)
- Validate open-path targets (resolve to absolute paths)
- Add comprehensive security audit proposal with IPC surface analysis,
  severity ratings, fuse recommendations, and migration roadmap

See .github/proposals/proposal-csp-security.md for full details.

Amp-Thread-ID: https://ampcode.com/threads/T-019c7926-be08-704f-b583-1c5167315271
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant