From c1187109c8fbec7381fd77e51c10421b23461384 Mon Sep 17 00:00:00 2001 From: Ayumi Server Date: Mon, 27 Apr 2026 15:49:56 +0000 Subject: [PATCH] fix: shallow-copy event to avoid mutating shared hook object Address review feedback on PR #72888. triggerInternalHook passes the same event reference to all handlers sequentially. Mutating evt.context leaks pluginConfig to subsequent handlers and causes cross-plugin overwrites. Shallow-copy event and context instead. --- src/plugins/registry.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/plugins/registry.ts b/src/plugins/registry.ts index 5b35259fed7..085e930151d 100644 --- a/src/plugins/registry.ts +++ b/src/plugins/registry.ts @@ -500,13 +500,10 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) { handler: Parameters[1]; }> = []; for (const event of normalizedEvents) { - // Wrap handler to inject pluginConfig into event context - // so plugins can access their configured pluginConfig at invocation time const wrappedHandler: typeof handler = async (evt) => { - if (evt.context && typeof evt.context === "object") { - (evt.context as Record).pluginConfig = pluginConfig; - } - return handler(evt); + // Shallow-copy to avoid mutating the shared event object + // passed to all handlers sequentially by triggerInternalHook + return handler({ ...evt, context: { ...evt.context, pluginConfig } }); }; registerInternalHook(event, wrappedHandler); nextRegistrations.push({ event, handler: wrappedHandler });