Repository navigation
Conversation
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.
Summary
Both
load-html --from-file <payload.json>(browse/src/write-commands.ts) andpdf --from-file <payload.json>(browse/src/meta-commands.ts) read thepayload file straight through
fs.readFileSync()without any pathvalidation. The direct
load-html <file>path next to it (in the samefunction, ~60 lines below) runs every caller-supplied path through
validateReadPath()so reads stay confined toSAFE_DIRECTORIES(
cwd,TEMP_DIR). The parity gap means--from-fileis aread-anywhere escape hatch for any caller that can pick the payload
path.
This PR brings the shortcut flags up to the same policy.
Root cause (same shape as R3 F002 / F008)
The recent security audits keep finding the same pattern: a defense
exists on the primary path and is missing from a sibling shortcut.
validateNavigationUrlran ongotobut not ondownload/scrape(tracked in security: gate download + scrape through validateNavigationUrl (SSRF) #1029).markHiddenElementsran fortextbut not for 10 otherDOM-reading commands (tracked in security: extend hidden-element detection to every DOM-reading channel #1032).
Here:
validateReadPathruns forload-html <file>but not forload-html --from-file <payload>orpdf --from-file <payload>.Same class of miss, same class of fix.
The gap
browse/src/write-commands.ts(load-html), before this PR:browse/src/meta-commands.ts(pdf), before this PR:Threat model
An attacker-influenced caller (MCP tool call whose arguments come from
agent context that can be prompt-injected) picks an arbitrary
--from-filepath. Even when the JSON parse later fails on a targetthat isn't valid JSON with an
html/ PDF-options field, the file hasalready been read into process memory and error shapes can leak
presence/permissions. In tightened deployments where
SAFE_DIRECTORIESis the trust boundary between project files and the user's home, the
shortcut flags silently skip that boundary.
Severity is LOW on its own (defense-in-depth for the policy; no direct
content exfil channel on a typical target). Bundling it is cheap.
Fix
Add
validateReadPath(path.resolve(payloadPath))beforereadFileSyncin both sites, with a
SAFE_DIRECTORIES-aware error message thatmatches the direct-path branch so operators and agents see a consistent
error shape.
Test plan
New file:
browse/test/from-file-path-validation.test.ts(pattern matchesbrowse/test/path-validation.test.tsandbrowse/test/content-security.test.ts).validateReadPathprecedesreadFileSyncin theload-html --from-filebranch.validateReadPathprecedesreadFileSyncinparsePdfFromFile().SAFE_DIRECTORIESin thethrown error so the UX matches the direct path.
bun test -- browse/test/from-file-path-validation.test.ts browse/test/path-validation.test.ts browse/test/content-security.test.ts browse/test/adversarial-security.test.ts— 81 pass / 0 fail.Risk
validateReadPathis already imported inwrite-commands.ts; themeta-commands.tschange adds two symbols to an existing import. Nonew dependencies.
path.resolve+ onerealpathSyncper--from-filecall (same cost as the direct path).
outside
SAFE_DIRECTORIESwill now see thePath must be within: ...error with guidance to copy the payload into cwd or
TEMP_DIR. Samebehavior the direct
load-html <file>path has had sincepath-security.tslanded.Notes
Flagged during an ongoing security parity audit. Happy to rebase on
request or split into two PRs (one per file) if that is easier to
review.