Skip to content

fix(devtools): continue hardening the RPC surface - #1049

Merged
antfu merged 1 commit into
v3from
fix/devtools-rpc-hardening
Jul 29, 2026
Merged

fix(devtools): continue hardening the RPC surface#1049
antfu merged 1 commit into
v3from
fix/devtools-rpc-hardening

Conversation

@antfubot

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #1039. That PR added the dev auth token to openInEditor, updateOptions and clearOptions; this one brings the rest of the RPC surface (all reachable over the Vite HMR WebSocket) in line with the same model, and hardens the transport itself.

Changes

Serialization

  • Require structured-clone-es >=2.0.1 via the catalog and a tree-wide resolutions override, so every copy in the dev-server process (including transitive ones) uses the version whose deserializer allowlists the constructors it will instantiate.
  • Add onGeneralError to the server RPC channel so a frame that fails to deserialize is dropped rather than surfacing as an unhandled rejection.

Consistent token checks (mirroring restartNuxt, storage writes, etc.)

  • enableTimeline — now requires the token before rewriting nuxt.config and restarting.
  • customTabAction — now requires the token before invoking a custom tab's launch action handler.
  • getServerRuntimeConfig — now requires the token; it exposes runtimeConfig merged with env vars.

Reduced unauthenticated exposure

  • getServerConfig — strips private runtimeConfig from this eagerly-read, unauthenticated payload (keeps public/app).
  • requestForAuth — always derives the origin server-side instead of trusting a client-supplied value.

Transport

  • The RPC channel now only accepts same-origin WebSocket connections (a small, unit-tested helper), while leaving Vite's HMR socket itself untouched so HMR keeps working.

Notes

  • Client callers pass the token via the existing ensureDevAuthToken() flow; behaviour for already-authenticated sessions is unchanged.
  • Tests added for the deserializer safety invariant and the origin check. lint, vue-tsc typecheck, unit tests, and the full build all pass.

This PR was created with the help of an agent.

Follow-up to the dev auth token work, covering the rest of the RPC surface
reachable over the HMR WebSocket:

- structured-clone-es: require >=2.0.1 (catalog + tree-wide override) so the
  deserializer allowlists constructors, and add onGeneralError on the server
  channel so a frame it now rejects is dropped instead of crashing dev.
- enableTimeline, customTabAction, getServerRuntimeConfig: require the dev
  auth token (config write + restart, custom-tab action handler, and
  runtimeConfig/env exposure respectively).
- getServerConfig: strip private runtimeConfig from this unauthenticated,
  eagerly-read payload (keeps public/app).
- requestForAuth: always derive the origin server-side rather than trusting a
  client-supplied one.
- RPC channel: only accept same-origin WebSocket connections, leaving the HMR
  socket itself untouched.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying nuxt-devtools with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4e3962f
Status: ✅  Deploy successful!
Preview URL: https://0de16c48.nuxt-devtools.pages.dev
Branch Preview URL: https://fix-devtools-rpc-hardening.nuxt-devtools.pages.dev

View logs

@antfu
antfu merged commit 7f072dc into v3 Jul 29, 2026
6 checks passed
@antfu
antfu deleted the fix/devtools-rpc-hardening branch July 29, 2026 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants