fix(devtools-bundler-core): validate package and import names from the event bus #545
An unauthenticated event bus message can run shell commands on the dev server: installPackage puts the package name from the event into a shell string. This PR accepts only valid npm package names and runs the package manager without a shell on macOS and Linux. It also rejects a plugin import name that is not a JavaScript identifier, because that name is written into the user's source file as code.
🎯 Changes#
installPackagenow checks the name against an npm package pattern with an optional version (@scope/name@^1.2.3). The pattern allows no shell syntax and no leading-, so a name cannot become a CLI flag.- On macOS and Linux, the package manager runs with
execFileand an args array, with no shell. - On Windows, the package managers are
.cmdshims that start only through a shell. Node 24 also warns (DEP0190) aboutexecFilewith args andshell: true. So Windows keepsexec, and the pattern rejects allcmd.exeoperators (& | < > ( ) % !and quotes). transformAndInjectwritespluginImport.importNamefrom the same events into the devtools file (import { ${importName} } ...). It now must match/^[A-Za-z_$][\w$]*$/.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Testing#
Commands run
vitest runinpackages/devtools-bundler-core: 213 tests pass, on Windows. Linux CI runs theexecFilebranch.- The new tests mock
execandexecFile, so no test runs a real command. Before the fix, all 11installPackagecases and the import name case failed. eslint,tsc, andprettier --checkinpackages/devtools-bundler-core: pass.- I did not run the full
pnpm test:pr.
Manual test
- Run the PoC script from #464 against a Vite app with
devtools(). - Before this fix: the marker file
/tmp/tanstack-devtools-vite-pwnexists. - After this fix: the dev server logs
Invalid package name, and no marker file exists. - Install a plugin from the devtools marketplace. It still installs and gets added to the devtools file.
How this PR makes testing easy
package-manager.test.ts covers injection payloads and valid names. inject-plugin.test.ts covers an import name with code in it.
Linked issues#
Refs #464. This PR stops the shell injection. The event bus still accepts unauthenticated requests, so a request can still install any valid npm package (and its install scripts). An allowlist or a per-server token can close that in a follow-up.
Risk / rollback#
Low. A package spec with characters outside the npm name pattern (for example a git URL) is now rejected. The marketplace sends only registry names. To undo, revert this PR.
🤖 Generated with Claude Code
- 1
View your CI Pipeline Execution ↗ for commit b39cb1b633b42fd7aad6e7295f6319a9970a5258
Command Status Duration Result nx run-many --target=test:e2e --parallel=1 --pr...✅ Succeeded 1m 3s View ↗ nx affected --targets=test:eslint,test:sherif,t...✅ Succeeded 58s View ↗ nx run-many --targets=build --exclude=examples/...✅ Succeeded 8s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-02 13:59:47UTCMore templates
- @tanstack/devtools-example-angular-a11y-devtools
- @tanstack/devtools-example-angular-basic
- @tanstack/devtools-example-angular-panel
- ssr
- @tanstack/devtools-example-angular-with-devtools
- @tanstack/devtools-example-preact-basic
- @tanstack/devtools-custom-devtools-preact
- @tanstack/react-devtools-a11y-example
- @tanstack/devtools-example-react-basic
- start-repro
- @tanstack/devtools-custom-devtools
- tanstack-start-example-counter
- @tanstack/devtools-example-react-https
- start
- start-cloudflare
- start-nitro
- @tanstack/devtools-example-react-time-travel
- @tanstack/solid-devtools-a11y-example
- @tanstack/devtools-example-solid-basic
- @tanstack/devtools-example-devtools-ui
- @tanstack/devtools-example-solid-start
- @tanstack/query-example-vue-basic
@tanstack/angular-devtools
npm i https://pkg.pr.new/@tanstack/angular-devtools@545@tanstack/devtools
npm i https://pkg.pr.new/@tanstack/devtools@545@tanstack/devtools-a11y
npm i https://pkg.pr.new/@tanstack/devtools-a11y@545@tanstack/devtools-bundler-core
npm i https://pkg.pr.new/@tanstack/devtools-bundler-core@545@tanstack/devtools-client
npm i https://pkg.pr.new/@tanstack/devtools-client@545@tanstack/devtools-rspack
npm i https://pkg.pr.new/@tanstack/devtools-rspack@545@tanstack/devtools-ui
npm i https://pkg.pr.new/@tanstack/devtools-ui@545@tanstack/devtools-utils
npm i https://pkg.pr.new/@tanstack/devtools-utils@545@tanstack/devtools-vite
npm i https://pkg.pr.new/@tanstack/devtools-vite@545@tanstack/devtools-webmcp
npm i https://pkg.pr.new/@tanstack/devtools-webmcp@545@tanstack/devtools-event-bus
npm i https://pkg.pr.new/@tanstack/devtools-event-bus@545@tanstack/devtools-event-client
npm i https://pkg.pr.new/@tanstack/devtools-event-client@545@tanstack/preact-devtools
npm i https://pkg.pr.new/@tanstack/preact-devtools@545@tanstack/react-devtools
npm i https://pkg.pr.new/@tanstack/react-devtools@545@tanstack/solid-devtools
npm i https://pkg.pr.new/@tanstack/solid-devtools@545@tanstack/svelte-devtools
npm i https://pkg.pr.new/@tanstack/svelte-devtools@545@tanstack/vue-devtools
npm i https://pkg.pr.new/@tanstack/vue-devtools@545commit:
b39cb1bAlemTuzlak merged thisd018c4c
AlemTuzlak closed this
🎉 This PR has been released!
Thank you for your contribution!
Sign in to join this conversation.
Warning
Review limit reached#
You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.
Next included review available in 4 minutes.
Check out review usage here.
View limit details
Limit details: You’ve used all 4 included reviews currently available.
Learn how review limits work.
Review configuration:
⚙️ Run configuration
Configuration used: Repository: TanStack/devtools/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
68dc22cd-e21b-403c-b6c8-a9144b0ddd62📥 Commits
Reviewing files that changed from the base of the PR and between afa01fec1751308eb5f60e737e408f2fc34e669a and b39cb1b633b42fd7aad6e7295f6319a9970a5258.
📒 Files selected for processing (5)
.changeset/validate-install-package.mdpackages/devtools-bundler-core/src/inject-plugin.test.tspackages/devtools-bundler-core/src/inject-plugin.tspackages/devtools-bundler-core/src/package-manager.test.tspackages/devtools-bundler-core/src/package-manager.tsThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share