mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:10:45 +00:00
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:
committed by
Peter Steinberger
parent
ed0b098d75
commit
c1187109c8
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user