security: remove .svg from load-html extension allowlist#1153
Open
garagon wants to merge 1 commit intogarrytan:mainfrom
Open
security: remove .svg from load-html extension allowlist#1153garagon wants to merge 1 commit intogarrytan:mainfrom
garagon wants to merge 1 commit intogarrytan:mainfrom
Conversation
SVG files can contain inline <script> tags, event handlers (onload, onclick), and <foreignObject> elements. When loaded via setContent(), JavaScript executes in an about:blank context with full fetch() access to localhost — including the gstack server itself. Attack vector: a malicious SVG placed in a project directory (via git clone, npm package, or download) gets loaded by the AI agent through load-html. The SVG's JavaScript modifies the DOM to inject prompt injection payloads that the agent reads on subsequent text/snapshot commands. SVG rendering is still available via `goto file://path/to/file.svg` which goes through validateNavigationUrl + validateReadPath with safe-dirs enforcement.
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.
Problem
load-htmlaccepts.svgfiles in its extension allowlist. SVG files can contain inline JavaScript that executes when loaded via Playwright'spage.setContent():What happens
.svglands in the project directory (via git clone, npm dependency, user download).load-html malicious.svg.setContent()renders the SVG in anabout:blankcontext. JavaScript executes.fetch()access tohttp://127.0.0.1:<port>— the gstack server itself. It can issue/commandrequests with the auth token (if discoverable) or modify the DOM to inject prompt injection payloads.textorsnapshoton the page and reads the injected content.SVG supports three JS execution vectors:
<script>blocks, event handler attributes (onload,onclick, etc.), and<foreignObject>embedding arbitrary HTML.Why this matters for the threat model
The gstack security stack (Confusion Protocol, hidden-element detection, ML classifier) defends against untrusted web content influencing the agent. But
load-htmltreats file content as trusted local HTML — it bypasses the Confusion Protocol for root tokens. A malicious SVG in a cloned repo gets the same trust level as the agent's own commands.Fix
Remove
.svgfromALLOWED_EXT. SVG rendering is still available throughgoto file://path/to/file.svg, which goes throughvalidateNavigationUrl+validateReadPathwith safe-dirs enforcement and loads in a properfile://origin (notabout:blank).Two lines changed in
write-commands.ts:.svgremoved from allowlistTest
New test case:
load-html rejects .svg files— writes a valid SVG to tmpdir, confirmsload-htmlthrows with "does not appear to be HTML."Test plan
bun test browse/test/commands.test.ts— 224/224 pass, 0 fail.svgrejection test passes.html/.htm/.xhtmltests still pass.txt) still passes