Repository navigation
fix(producer): trusted renders refuse outside-linked compositions unless --include-outside-files - #8024
Conversation
…ess --include-outside-files A sub-composition or entry file whose real file is outside the project is inlined into the render page, so its scripts run even though outside .js files are left out without the flag. The pre-flight now refuses it with a message naming --include-outside-files. — Rames Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vanceingalls
left a comment
There was a problem hiding this comment.
Approved at 82bf5fb. linksOutside realpaths both the project root and the file (realpathSync.native) and uses path.relative with ../absolute detection.
- Containment: a symlinked root (/tmp → /private/tmp) isn't falsely refused,
/projvs/proj-evilis handled, and Windows drive and case differences are covered. - Scope: the gate is
assetRoot === undefined, so untrusted renders are unchanged, andplan()shares the same compile stage.
Should-fix:
- Studio and benchmark renders:
studioServer.ts:696-717andbenchmark.ts:110-135callcompileForRenderwithoutincludeOutsideScripts. A Studio or benchmark render of a project with a linked outside scene is now refused, and the error points at a CLI flag those surfaces can't set. Either give them a way to opt in, or word the error for where it's raised. - TOCTOU: the known gap is cheap to narrow by repeating
linksOutsidewhere the file is actually read (resolveHtml,parseSubCompositions). - Wording: the error says "its scripts would run" even for a script-free file. Cosmetic.
miguel-heygen
left a comment
There was a problem hiding this comment.
Reviewed at 82bf5fb9. A trusted render without --include-outside-files now refuses a composition file whose real path is outside the project, before any of its markup is inlined. I checked every other way such a file could reach the render page and found none open.
Strengths
- The check is in the existing pre-flight (
htmlCompiler.ts:343-346), which already recurses, so a linked scene nested any number of levels down is named in the same error list as every other unusable scene. linksOutsideresolves both the project root and the file to real paths before comparing (outsideFile.ts:146,safePath.ts:37-44). A symlink, a..reference (whichresolveCompositionFilereturns when outside assets are allowed) and a symlinked project root all come out right.- Refusing instead of stripping scripts is the right call for the reason the body gives.
Other paths to the render page, checked at this head (Rule 2)
- An entry outside the project: the CLI refuses it before compile (
cli/src/utils/compositionEntry.ts:47), socompileForRenderonly gating entries inside the project is enough. - A sub-composition the runtime fetches itself (
core/src/runtime/compositionLoader.ts:732-799), or an outside.htmlin aniframe: the render file server refuses outside.html.COPIED_TYPE(outsideFile.ts:17) has notext/html, sooutsideAssetRefusalanswersfile_typeandfileServer.ts:851skips the file. - The received-files rule sets
assetRoot, so this check stays off andescapesAssetRootalready refuses.plan()and distributed renders go through the same compile stage. - Studio and benchmark renders: as Vance noted, they call
compileForRenderwithoutincludeOutsideScripts(cli/src/server/studioServer.ts:696-717,cli/src/commands/benchmark.ts:110-135). They now refuse a linked outside scene with a message naming a CLI flag they cannot pass. That fails closed, so it is not a blocker, but +1 to his should-fix.
Important
- The new
it.eachcovers a symlinked scene and a symlinked entry at the top level. Nothing pins the two other shapes this check claims to cover: a nested linked scene (one level down, through the pre-flight's recursion) and a plaindata-composition-src="../shared/scene.html"with no symlink. Two more rows in the same table would keep a later refactor of the recursion or ofresolveCompositionFilefrom silently dropping them.
Nit
- The entry error reads as a broken sentence:
Entry file ${htmlPath} ${OUTSIDE_COMPOSITION_NEEDS_FLAG}gives "Entry file /p/index.html it is outside the project and its scripts would run; ..." (htmlCompiler.ts:2247). Dropping the leading "it" from the shared text, or using "Entry file X is outside the project ..." here, fixes both call sites.
Also covered by Vance and not repeated: the window between the pre-flight check and the read, and "its scripts would run" on a script-free file.
Verdict: APPROVE
Reasoning: The refusal sits where every composition file is first examined, uses real paths on both sides, and I found no other route for outside markup into a trusted render; the gaps left are tests and wording, not leaks.
… in the received-render parity test The parity test checks that the render compiler reaches an outside file through a scene in a linked folder outside the project. Trusted renders now refuse that scene unless --include-outside-files is passed, so the helper passes it. — Rames Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What
In a trusted local render (
hyperframes render), a sub-composition or entry file whose real file is outside the project now stops the render before it starts, unless--include-outside-filesis passed. The error names the file and the flag. Untrusted renders already refused these files, and they still do.Behavior change: a shared scene linked in from outside the project used to render without the flag. Now it needs the flag, even when it has no scripts.
Why
Without the flag, a trusted local render leaves out
.jsfiles outside the project, so outside scripts don't run unless the person asks. A linked composition file got around that. Its HTML is inlined into the render page, so inline scripts and event handlers in that outside file ran anyway.Related work
Builds on the existing
--include-outside-filespolicy (OutsideFilePolicy,outsideAssetRefusalinpackages/producer/src/utils/paths.ts).How
Claude Opus 5.5
compileForRenderrefuses an entry file inside the project whose real path leads outside it. It checks before reading the file, and only when outside assets are allowed and scripts are not.assertSubCompositionsUsable, the pre-flight that already names every unusabledata-composition-src, takes the outside-file policy and reports such a sub-composition as "it is outside the project and its scripts would run; pass --include-outside-files to hyperframes render to run it". The check covers nested sub-compositions too, since the pre-flight recurses.plan()/ distributed planning go through the same compile stage, so the same refusal covers them.Why refuse instead of stripping scripts: a script stripper has to find every way HTML can run code:
<script>,on*attributes,javascript:URLs,srcdoc, SVG, and<template>content, which linkedom'squerySelectorAlldoes not see. Missing any of them puts the hole back. A refusal with a clear message has no such gap. Dropping the scene silently was also ruled out, because the pre-flight exists so a render never loses a scene without an error.Limit: the check runs once in the pre-flight.
parseSubCompositionsand the entry read don't repeat it, so a file swapped for an outside link after the pre-flight and before the read would still be inlined. Closing that needs the readers to check too. I left it out here to keep this change small.Test plan
outsideProjectAssets.test.ts, "trusted local renders still import outside files" no longer expects a linked outside scene to come in. A newit.eachover a symlinked scene and a symlinked entry checks that a trusted render and a trustedplan()both reject with the flag message, and that the render includes the scene once--include-outside-filesis set. Fails without the fix: both new cases fail against main'shtmlCompiler.tswith "promise resolved instead of rejecting". With the fix the file passes 17/17.packages/cli/src/utils/receivedRender.test.ts: the parity helper that checks the compiler reaches an outside file through a scene in a linked folder outside the project now passesincludeOutsideScripts: true, since that scene is refused without it. 57/57 pass (1 skipped).— Rames
🤖 Generated with Claude Code