[Fix] Use fileURLToPath for file:// URL parsing in artifact handler#194
Merged
[Fix] Use fileURLToPath for file:// URL parsing in artifact handler#194
Conversation
Contributor
|
Hi @samzong, DetailsInstructions for interacting with me using comments are available here. |
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.
Summary
Replace naive
url.replace('file://', '')with Node.js standardfileURLToPath()to correctly parsefile://URLs in theartifact:save-image-urlIPC handler, closing a path traversal vector.Type of change
[Fix]bug fixWhy is this needed?
url.replace('file://', '')strips the scheme but leaves the host component intact. A URL likefile://localhost/tmp/evil.pngbecomeslocalhost/tmp/evil.png, whichresolve()turns into a CWD-relative path — bypassing the workspace boundary check. This is a path traversal vulnerability.Additionally,
new URL(url).pathname(the obvious alternative) does not decode percent-encoded characters (%20stays%20) and produces wrong paths on Windows (/C:/pathinstead ofC:\path).fileURLToPathfromnode:urlhandles both correctly and is the Node.js canonical API for this conversion.What changed?
import { fileURLToPath } from 'node:url'resolve(url.replace('file://', ''))withresolve(fileURLToPath(url))Architecture impact
docs/architecture-invariants.md: noneLinked issues
N/A
Validation
pnpm lintpnpm testpnpm check:ui-contractpnpm check(full suite: lint + architecture + ui-contract + renderer-copy + i18n + dead-code + format + typecheck + test)pnpm buildCommands, screenshots, or notes:
Screenshots or recordings
No UI changes.
Release note
NONE.Checklist
[Feat],[Fix],[UI],[Docs],[Refactor],[Build], or[Chore]