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.
This commit is contained in:
Ayumi Server
2026-04-27 15:49:56 +00:00
committed by Peter Steinberger
parent ed0b098d75
commit c1187109c8

View File

@@ -500,13 +500,10 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
handler: Parameters<typeof registerInternalHook>[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<string, unknown>).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 });