Skip to content

fix: CSP worker-src blocking editor video/camera preview - #9

Merged
Alfredoalv13 merged 1 commit into
mainfrom
fix/csp-connect-worker-src
Jul 24, 2026
Merged

fix: CSP worker-src blocking editor video/camera preview#9
Alfredoalv13 merged 1 commit into
mainfrom
fix/csp-connect-worker-src

Conversation

@Alfredoalv13

Copy link
Copy Markdown
Owner

Summary

  • After a recording finished and the editor opened, the video and camera preview showed nothing at all (audio played, but no video/canvas rendering) - this is a regression from the original webSecurity/CSP hardening PR, not the recording pipeline itself.
  • Root cause: no worker-src was declared in the CSP, so Chromium fell back to script-src for the waveform/decode workers the editor creates from blob: URLs. script-src doesn't allow blob:, so worker creation threw a CSP violation, severe enough to abort the surrounding media-loading sequence entirely.
  • Fix: add an explicit worker-src 'self' blob: <allowed origins> directive.

A security note on scope

The console also showed connect-src violations for sidecar audio files (fetch('file://.../recording.system.wav') etc.). I initially widened connect-src to allow file: broadly to silence those too, but reverted that after checking RECORDINGS_DIR is already an allowed prefix for the proper getLocalMediaUrl() media-server path, and the sidecar-probing code (useTimelineAudioPeaks.ts) already retries per-candidate on any failure - so those specific file:// fallback fetches failing is harmless. Broadening connect-src to file: renderer-wide would have let any compromised renderer code (a bad extension, XSS) read arbitrary local files directly via fetch(), bypassing every path allowlist fixed in the original security review - to fix a symptom the worker-src fix alone already resolves.

Test plan

  • tsc --noEmit clean
  • npm test - 94/94 files, 817/817 tests passing
  • Verified in a debug build: loaded a known-good recording directly, confirmed every CSP violation is gone and the main video load no longer aborts (previously net::ERR_ABORTED)
  • Manual: record something, confirm the editor preview actually shows the video and camera feed

No worker-src was declared, so Chromium fell back to script-src for
the waveform/decode workers the editor spins up from blob: URLs -
and script-src doesn't allow blob:, so worker creation was blocked
outright with a CSP violation.

That block was severe enough to abort the surrounding media-loading
sequence, so after a recording the editor's preview showed no video
and no camera feed at all - this was a regression from the original
webSecurity/CSP hardening, not a problem with the recording pipeline
itself.

Note: the console also showed connect-src violations for sidecar
audio files (file:// fetches for possible .system.wav/.mic.m4a
tracks). I initially widened connect-src to allow file: broadly, but
reverted that - RECORDINGS_DIR is already an allowed prefix for the
proper getLocalMediaUrl()/media-server path (electron/ipc/project/manager.ts
isAllowedLocalReadPath), and the sidecar-probing code already retries
per-candidate on any failure (src/components/video-editor/timeline/hooks/useTimelineAudioPeaks.ts),
so those file:// fetches failing is harmless - they're a last-resort
fallback for when the media server itself is unavailable, not the
normal path. Broadening connect-src to file: renderer-wide would have
let any compromised renderer code (a bad extension, XSS) read
arbitrary local files directly via fetch(), bypassing every path
allowlist fixed in the original security review, to fix a symptom
that the worker-src fix alone already resolves.

Verified by loading a known-good recording directly in a debug build:
with only this change, every CSP violation is gone and the main video
load no longer aborts.
@Alfredoalv13
Alfredoalv13 merged commit eb993e6 into main Jul 24, 2026
1 check passed
@Alfredoalv13
Alfredoalv13 deleted the fix/csp-connect-worker-src branch July 24, 2026 01:50
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.

2 participants