Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') and External Control of File Name or Path in @vitejs/devtools rpc
Clear and concise description of the problem
Summary
The vite:core:open-in-editor and vite:core:open-in-finder RPC handlers in @vitejs/devtools accept an arbitrary, unvalidated path argument from WebSocket RPC clients. A trusted (or auth-bypassed) client can supply paths outside the project root — including absolute paths or ../ traversals — to open arbitrary files in the user's editor or launch arbitrary URIs via the OS default handler. This constitutes a path traversal / arbitrary command target vulnerability.
Details The vulnerable code is in two files on main:
vitejs/devtools@main/packages/core/src/node/rpc/public
Both handlers forward the client-supplied path directly to launch-editor or the open package with no validation whatsoever. There is no check that the path resolves within the project root directory.
The open package (used by open-in-finder) is especially dangerous because it acts as a general-purpose URI launcher — it can open https:// URLs, custom URI schemes, or any file path via the OS default handler.
PoC
- Start the project using
EDITOR=CODE pnpm -C packages/core run play - Connect a WebSocket client to the devtools WS server (default port 7812)
- After authenticating (or with auth disabled via [VITE_DEVTOOLS_DISABLE_CLIENT_AUTH=true], send an RPC call:
const ctx = globalThis.__VITE_DEVTOOLS_CLIENT_CONTEXT__
// opens inside of project
await ctx.rpc.call('vite:core:open-in-editor', 'vite.config.ts')
// opens outside of project root directory
await ctx.rpc.call('vite:core:open-in-editor', '../../../../passwd')
// or
await ctx.rpc.call('vite:core:open-in-editor', '/etc/passwd')
- The file or URL will be opened without restriction on the host machine.
Suggested solution
it('rejects path traversal with ../', async () => {
const handler = getHandler() // handler from the vulnerable code
await expect(handler('../../etc/passwd')).rejects.toThrow(
'Path is outside the project root',
)
})
it('rejects absolute path outside project root', async () => {
const handler = getHandler()
await expect(handler('/etc/passwd')).rejects.toThrow(
'Path is outside the project root',
)
})
Alternative
No response
Additional context
No response
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guide.
- [x] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.