fix(clientVars): stop mutating the shared plugin registry during sanitization#7587
Merged
JohnMcLear merged 1 commit intoether:developfrom Apr 23, 2026
Merged
Conversation
…tization
PadMessageHandler built the `pluginsSanitized` payload for clientVars by
aliasing `plugins.plugins` and then mutating each entry's `package` field
in place:
let pluginsSanitized: any = plugins.plugins;
Object.keys(plugins.plugins).forEach(function(element) {
const p: any = plugins.plugins[element].package;
pluginsSanitized[element].package = {name: p.name, version: p.version};
});
Because `pluginsSanitized` is a reference to `plugins.plugins`, the
assignment clobbered the server-side plugin registry. After the first
pad connection, every plugin's `package` object held only `{name,
version}` — `realPath`, `path`, and `location` were gone.
Minify.ts resolves `/static/plugins/ep_*/...` URLs via
`plugin.package.realPath`. Once the field disappeared, every subsequent
static asset request for a bundled plugin 500'd with:
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of
type string. Received undefined
at Object.join (node:path:1354:7)
at _minify (src/node/utils/Minify.ts:181:23)
Symptoms on Chromium: plugin CSS/JS assets fail to load (e.g.
/static/plugins/ep_font_size/static/css/size.css returns 500), so
plugins partially render or don't work at all. Firefox swallows the
resulting console errors quietly.
Fix: extract the sanitization into a pure helper `sanitizePluginsForWire`
that returns a fresh object graph and never touches the input. The
helper is covered by a new backend spec that:
* verifies the sanitized output has only {name, version} in `package`
* asserts the input registry's realPath/path/location survive the call
* runs the call repeatedly and confirms non-destructiveness
* mutates the returned copy and asserts the input is independent
Verified live with the dev server: before the fix, `/static/plugins/
ep_font_size/static/css/size.css` 500'd after visiting any pad; after
the fix it returns 200 both before and after pad connections.
Review Summary by QodoFix plugin registry mutation during clientVars sanitization
WalkthroughsDescription• Extract plugin sanitization into pure helper function • Prevent mutation of shared server-side plugin registry • Fix 500 errors on static plugin asset requests after pad connections • Add comprehensive test coverage for sanitization logic Diagramflowchart LR
A["Shared Plugin Registry"] -->|sanitizePluginsForWire| B["Fresh Sanitized Copy"]
B -->|{name, version}| C["Client Vars"]
A -->|realPath preserved| D["Minify.ts Asset Resolution"]
D -->|/static/plugins/...| E["200 OK Response"]
File Changes1. src/node/handler/PadMessageHandler.ts
|
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
PadMessageHandlerwas building thepluginsSanitizedpayload forclientVarsby aliasingplugins.pluginsand mutating each entry'spackagefield in place:Because
pluginsSanitizedwas a reference toplugins.plugins, the assignment clobbered the shared server-side plugin registry. After the first pad connection every plugin'spackageobject held only{name, version}— therealPath,path, andlocationfields were gone.Impact
Minify.tsresolves/static/plugins/ep_*/...URLs viaplugin.package.realPath. Once the field disappeared, every subsequent static asset request for a bundled plugin responded with HTTP 500:Observable symptoms:
/static/plugins/ep_font_size/static/css/size.cssreturns 500. Plugins partially or completely fail to render.ERR_INVALID_ARG_TYPEstack every time a static asset request hits a bundled plugin.Fix
Extract sanitization into a pure helper
sanitizePluginsForWirethat returns a fresh object graph and never touches the input. Replaces the aliasing + mutation pattern with a spread-based copy.Tests
New backend spec
sanitizePluginsForWire.tscovering:{name, version}inpackage.realPath,path,locationsurvive the call (regression of this bug).Test plan
tsc --noEmitclean in our code./static/plugins/ep_font_size/static/css/size.cssreturns 200 both before and after pad connections. Before the fix, the same request 500'd after the first pad visit.🤖 Generated with Claude Code