Skip to content
Source
Sign inSign up
TanStack/devtools

fix(devtools-bundler-core): validate package and import names from the event bus #545

MergedAlemTuzlakmerged 1 commit intomain fromrefs/pull/545/headmerged by AlemTuzlak View on GitHub

AlemTuzlakcommented

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

  • installPackage now 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 execFile and an args array, with no shell.
  • On Windows, the package managers are .cmd shims that start only through a shell. Node 24 also warns (DEP0190) about execFile with args and shell: true. So Windows keeps exec, and the pattern rejects all cmd.exe operators (& | < > ( ) % ! and quotes).
  • transformAndInject writes pluginImport.importName from 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 run in packages/devtools-bundler-core: 213 tests pass, on Windows. Linux CI runs the execFile branch.
  • The new tests mock exec and execFile, so no test runs a real command. Before the fix, all 11 installPackage cases and the import name case failed.
  • eslint, tsc, and prettier --check in packages/devtools-bundler-core: pass.
  • I did not run the full pnpm test:pr.

Manual test

  1. Run the PoC script from #464 against a Vite app with devtools().
  2. Before this fix: the marker file /tmp/tanstack-devtools-vite-pwn exists.
  3. After this fix: the dev server logs Invalid package name, and no marker file exists.
  4. 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. 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.md
      • packages/devtools-bundler-core/src/inject-plugin.test.ts
      • packages/devtools-bundler-core/src/inject-plugin.ts
      • packages/devtools-bundler-core/src/package-manager.test.ts
      • packages/devtools-bundler-core/src/package-manager.ts
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Autopilot is currently an internal CodeRabbit preview.


      Thanks 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
      Comment `@coderabbitai help` to get the list of available commands.
    2. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit b39cb1b633b42fd7aad6e7295f6319a9970a5258

      CommandStatusDurationResult
      nx run-many --target=test:e2e --parallel=1 --pr...✅ Succeeded1m 3sView ↗
      nx affected --targets=test:eslint,test:sherif,t...✅ Succeeded58sView ↗
      nx run-many --targets=build --exclude=examples/...✅ Succeeded8sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-02 13:59:47 UTC

    3. More templates

      @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@545

      commit: b39cb1b

    4. AlemTuzlak merged thisd018c4c

    5. AlemTuzlak closed this

Sign in to join this conversation.