Skip to content

fix(producer): scheme-prefixed media sources stay inside the project - #7851

Merged
michaelwang11394 merged 1 commit into
mainfrom
sec-media-scheme-src-1115
Nov 15, 2026
Merged

michaelwang11394 merged 1 commit into
mainfrom
sec-media-scheme-src-1115

Conversation

@michaelwang11394

Copy link
Copy Markdown
Contributor

What

Media sources that start with a URL scheme such as data: or blob: can no longer reach files outside the project when a render may not read outside files.

  • The outside-project media check (dropMediaOutsideProject) and the media type preflight now use the same remote test as the readers, isHttpUrl. Every other src is resolved to the file the readers would open and is checked against the project, compiled and download folders, with symlinks resolved.
  • The readers now refuse a local source outside those folders on their own: video frame extraction (extractAllVideoFrames), the audio mix (processCompositionAudio), and the HDR and video sound probes in the extract stage. A refused video reads as a missing source, and a refused audio track is reported as a source that was not found.
  • A new engine helper, isInsideAssetRoots, holds the containment check that the gate and the readers share.

Why

The check that leaves out media outside the project skipped any src starting with data:, blob:, about: or http(s): in any letter case. The readers only treat exact http:// and https:// URLs as remote, and they resolve everything else as a path. A source such as data:x/../../outside/clip.mp4 therefore passed the check, and path.join removed the scheme segment with the first .., so ffprobe and ffmpeg opened a file outside the project. This matters for renders that may not read outside files: render services, and CLI or Studio renders of a composition someone else sent.

Related work

Refs #7792. #7838 also edits videoFrameExtractor.ts; the two changes touch different steps and merge cleanly.

How

  • The gate and the preflight skip only what the readers download (isHttpUrl). Every other source goes through resolveProjectRelativeSrc and the shared containment check, so the preflight also sniffs a project file named behind a scheme.
  • isInsideAssetRoots uses the existing isSafePath check. A path that names no file passes when it is spelled inside a root, because nothing can be opened there. This covers a long inline data: URL, which the file system cannot name. Genuine inline media therefore reads as missing, as it does today, rather than as outside the project.
  • The extract stage and the audio stage pass the allowed folders to the readers unless allowOutsideProjectAssets is set. The plan audio path and the in-process render pass the job's setting through.

Projects whose media is inside the project, genuine data:, blob: and https:// sources, and renders that allow outside files behave as before.

Test plan

  • Unit tests added/updated

  • Manual testing performed

  • Documentation updated (if applicable)

  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

  • assetMediaType.test.ts: sources such as data:, DATA:, Blob:, about: and HTTP: followed by parent folders are dropped. Genuine inline, blob, remote and local sources are kept, including a long data: URL. The preflight sniffs a project file named behind data: or BLOB:.

  • outsideProjectAssets.test.ts: the in-process and Plan v2 renders drop scheme-prefixed sources that leave the project and never pass the outside file to ffprobe or ffmpeg. With the gate bypassed, frame extraction, the HDR probes, the video sound probes and the audio mix each refuse the outside source. Every spawned process is recorded to check this.

  • These tests fail on main and pass with this change.

  • tsc --noEmit passes for engine and producer. The related producer stage, plan and orchestrator suites and the engine mixer and extractor suites show no new failures.

…t folder

The outside-project media check skipped any src starting with data:, blob:,
about: or http(s): in any letter case, while the readers resolve everything
but exact http:// and https:// URLs as a local path. A src such as
data:x/../../outside/clip.mp4 passed the check and the readers opened the
file it named.

The check and the media type preflight now use the readers' remote test,
isHttpUrl, and check every other src with a shared containment helper,
isInsideAssetRoots. Frame extraction, the audio mix, and the HDR and video
sound probes also refuse a local source outside the project, compiled and
download folders on their own when outside files are not allowed.
@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 267 (base branch 267), smooth 108 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (8)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 13177f1efa96ea0f9f524efa91baf752842f44e5. APPROVE: I found nothing blocking. There are 3 nits and 2 pre-existing follow-ups below.

Need: yes, data:x/../../outside/clip.mp4 passed the outside-project gate while ffmpeg opened it as a path · Size: ok · Reuse: isSafePath (escapesAssetRoot lives in producer, which the engine can't import, so the new engine helper is justified) · Simpler: already minimal · Structure: fine (checked escapesAssetRoot, isSafePath, isWithinProjectRoot; no split)
Risk: low — narrows what the gate keeps; projects with inside media, real data:/blob:/https sources, and allowOutsideProjectAssets renders behave as before

What I checked

  • The gate and the readers now test sources the same way. The gate (assetMediaType.ts:111-113), the preflight (:171), extractAllVideoFrames (videoFrameExtractor.ts:2240-2257), processCompositionAudio (audioMixer.ts:1493-1514) and the extract-stage HDR and sound probes (extractVideosStage.ts:477,529,689-699) all do the same two things. They call isHttpUrl (urlDownloader.ts:1605, exact http:// or https:// only) to decide remote vs local. They resolve local sources with resolveProjectRelativeSrc(src, projectDir, compiledDir).
  • Probe on a real temp tree. The tree had a symlink inside the project pointing out. I ran the built resolveProjectRelativeSrc, isInsideAssetRoots and isHttpUrl on it.
    • Resolve outside and are refused: data:, DATA:, blob:, about: and HTTP: followed by ../..; data:x/../link/clip.mp4 through the symlink; file://; //abs; %2e%2e/; and ..%2f.
    • Resolve to missing files inside the project: http:/x, HTTP://h/x, http://h/x and \\?\….
    • A real 5 KB data: URL takes the ENAMETOOLONG fallback in isInsideAssetRoots and reads as missing, as on main.
  • Every spawn reachable from a composition src is covered.
    • The extractor, the audio mix and the extract-stage probes refuse on their own.
    • captureHdrResources, oversizedVideos, the passthrough layer and the preflight run after the gate with the same resolver.
    • The compiler probes and GIF/HEIC prep keep their existing escapesAssetRoot(projectDir) checks.
    • In-process and Plan v2 both pass allowOutsideProjectAssets through.
  • ffmpeg protocols. A src can't pick an ffmpeg protocol (concat:, subfile:, pipe:): every local input reaches ffmpeg as an absolute path. Playlist contents are checked by playlistLeavesItsFolder, and this PR extends that check to project files named behind a scheme.
  • Real data: media is never decoded or written to a temp file. It reads as source_missing / source_not_found, as before. Only HEIC images are decoded from data:, in memory, and that was already the case.
  • Tests (bunx vitest run in packages/producer):
    • At head, the PR's three test files pass 50/50.
    • With only the 8 non-test source files reverted to the merge base 88ffe087, 11 of 50 fail: the gate, the preflight sniff, in-process, Plan v2, each reader, and the audioStage config.
    • Engine audioMixer.test.ts and videoFrameExtractor.test.ts pass 228/228.

Nits (non-blocking)

  1. mediaAssetRoots builds the downloads folder from dirname(compiledDir) (assetMediaType.ts:97). Plan v2 mixes audio with finalCompiledDir (plan.ts:1656), which makes its downloads root planDir/downloads. Compile downloads into planDir/.plan-work/downloads. A path outside the roots is refused, never allowed, so this can only refuse too much. It has no effect today because localized media is copied into compiled. Building the roots from workDir, or passing them in, would keep the list honest.
  2. Add a small engine test for isInsideAssetRoots to pin the symlink-inside-a-root case and the ENAMETOOLONG fallback.
  3. The remaining /^https?:\/\//i checks (ffprobe.ts:389,451, videoShownBoxes.ts:25, videoFrameExtractor.ts:820) differ from isHttpUrl only in the safe direction: they skip the local read. Switching them to isHttpUrl would leave one remote test everywhere.

Pre-existing follow-ups (not this PR)

  • Local ffmpeg/ffprobe inputs get no -protocol_whitelist; urlInput.ts:35 covers only https inputs on render services. Adding -protocol_whitelist file on local inputs would be cheap defense in depth.
  • captureHdrResources, oversizedVideos and the passthrough layer rely on the gate alone. They use the same resolver, so they agree today. A reader-side check there would match the readers this PR hardened.

Review by Rames

@michaelwang11394
michaelwang11394 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit d8e36aa Nov 15, 2026
98 of 100 checks passed
@michaelwang11394
michaelwang11394 deleted the sec-media-scheme-src-1115 branch November 15, 2026 18:32
daedal-ping Bot pushed a commit to DaedalGames/hyperframes that referenced this pull request Nov 15, 2026
* chore: release v0.9.54

* chore: release v0.9.54 notes include heygen-com#7827, heygen-com#7825, heygen-com#7845, heygen-com#7848 and heygen-com#7849

* chore: release v0.9.54 notes include heygen-com#7853

* chore: release v0.9.54 notes include heygen-com#7851 and heygen-com#7855
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