Repository navigation
Conversation
An SVG Source or Result opened directly from Studio ran its scripts in the Studio origin, where the same-origin mutation guard admits writes to the project Source. Mark material, Result, Surface preview and storyboard responses with a sandbox CSP and nosniff so they stay inert as documents while <img>, <video> and <audio> use is unchanged.
Vite serves any file under server.fs.allow at /@fs/<absolute path>, and the author workspace is on that list, so a workspace SVG or HTML file opened there still ran in the Studio origin. Mark workspace files reached through /@fs or /@id (outside node_modules) with the same sandbox CSP and nosniff headers as material and Results. Allow downloads in the sandbox so a Result video opened in its own tab can still be saved from its native controls; scripts stay disabled. Cover Range and HEAD responses and the Result route in the inert-media test.
SanHsien
added a commit
to SanHsien/hypit
that referenced
this pull request
Nov 7, 2026
…i#460-hypit-ai#474; advance watermarks No PR was merged upstream, so nothing was cherry-picked: 11 PRs = 5 defer (hypit-ai#464 hypit-ai#466 hypit-ai#467 hypit-ai#469 hypit-ai#471, pinned in monitored) + 6 not applicable; 5 issues = 1 defer (hypit-ai#473) + 4 not applicable. hypit-ai#464 npm pin is moot because the fork gates publish jobs to upstream (b641cce). ROADMAP row updated with the deferred items. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
SanHsien
added a commit
to SanHsien/hypit
that referenced
this pull request
Nov 7, 2026
…of upstream PR hypit-ai#471) Ported before upstream merge: project bytes with an active media type (SVG) opened as a top-level document ran scripts in the Studio origin and passed the same-origin mutation guard. inertMedia() adds a sandbox CSP and nosniff to the material, Result, Surface-preview and storyboard responses, and a middleware does the same for workspace files Vite serves through /@fs and /@id. Tests fail without each half and pass with it. Replace with upstream's version once hypit-ai#471 is merged. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #478
Problem
Studio serves project bytes from its own origin:
/__studio/material/<res>(authored Sources such asmedia:Image),/__studio/artifact?build=&output=(Results),/__studio/surface-previewand/__studio/storyboard/<res>. These responses take theircontent-typefrom the Source or Result.media:Imageacceptsmedia-type="image/svg+xml", and the build library'sisMediacheck (^(image|video|audio)/) also letsimage/svg+xmlthrough. None of these responses sets a CSP ornosniff.When someone opens an SVG like that directly (for example with "Open image in new tab" on a Studio preview), its
<script>runs as a document in the Studio origin. From there it passesallowsStudioMutation, because Host is localhost, Origin is the same origin andSec-Fetch-Siteissame-origin. It can then:/__studio/session, the library and feedback comments;PUT /__studio/sourceto rewrite the project's SVML/SVRun files;POST /__studio/mutation,PUT /__studio/artifact-nameandPOST /__studio/feedback.Impact
Medium. Stored XSS in the local Studio origin, triggered by an SVG asset taken from an untrusted source (a downloaded logo, a shared template project, a Result). It needs the victim to open the material URL as a top-level document. Resource ids are random UUIDs, so a third-party site can't easily guess the URL and navigate to it.
Reproduction (on origin/main)
<media:Image id="logo" src="./evil.svg" media-type="image/svg+xml"/>used by avisual:Clip.evil.svgcontains<script>fetch('/__studio/session').then(r=>r.text()).then(t=>document.title='PWNED '+t.length)</script>.hypit studio --run main.svrun --project .http://localhost:5179/__studio/material/<res>(the id appears in/__studio/session) in Chrome.PWNED 37681. From that document,fetch('/__studio/source', {method:'PUT', body:'{}'})returns 400 (body validation), not 403. So the origin guard accepts the request.Fix
A small
inertMedia()helper setsContent-Security-Policy: sandbox allow-downloadsandX-Content-Type-Options: nosniffon the material, Result, Surface preview and storyboard responses. Opened as documents, they get an opaque origin with scripts disabled (allow-downloadsonly lets native video/audio controls save the file; withoutallow-scriptsno script runs). Used through<img>,<video>and<audio>they behave as before./__studio/visual.htmlis left alone because it is the intended scripted preview.Raw workspace files through
/@fsStudio's Vite server lists the author workspace in
server.fs.allow, so/@fs/<absolute workspace path>served the same files raw (e.g.evil.svgasimage/svg+xml,evil.htmlastext/html) in the Studio origin with no CSP, at a more guessable URL. Nothing in the Studio UI loads workspace files that way (material goes through/__studio/material), but the workspace can't simply be dropped fromfs.allow: it is also the default package root, where Studio and its dependencies resolve throughnode_modules. Instead,studioPluginregisters a middleware ahead of Vite's own/@fsand transform middlewares that applies the sameinertMedia()headers to/@fsand/@idrequests for paths inside the workspace root, except undernode_modules. Vite's module serving for Studio's UI is unchanged.Tests
packages/studio/test/inert-media.test.tsstarts a real Vite server withstudioPlugin, laid out like Studio (Vite root is the Studio package, the workspace is only infs.allow), on a project that contains an SVGmedia:Image. It checks that:/__studio/artifact) carries the same headers on 200, 206 and HEAD;/@fs/<workspace>/logo.svgand/@fs/<workspace>/evil.htmlare refused or carry the sandbox CSP (without the middleware the SVG is served with status 200 and no CSP, so the test fails);/src/ui/main.tsis still served normally without the CSP.A second unit test checks which request URLs are treated as workspace files (workspace paths via
/@fsand/@idyes;node_modules, paths outside the workspace and Studio routes no).pnpm install --frozen-lockfile,pnpm check: pass.pnpm test: 1149 tests, 1126 pass, 0 fail (23 skipped by environment gates).