security(gateway): route hook completion events to target agent session#73228
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟠 Unhandled exception in hook error path can crash process (DoS) via resolveMainSessionKeyFromConfig()
DescriptionIn
Vulnerable code: } catch (err) {
logHooks.warn(`hook agent failed: ${String(err)}`);
enqueueSystemEvent(`Hook ${safeName} (error): ${String(err)}` , {
sessionKey: hookEventSessionKey ?? resolveMainSessionKeyFromConfig(),
trusted: false,
});
}RecommendationAvoid calling Example fix: const fallbackSessionKey = "global"; // or a safe constant / already-known session key
let hookEventSessionKey: string | undefined;
void (async () => {
try {
const cfg = getRuntimeConfig();
hookEventSessionKey = resolveHookEventSessionKey({ cfg, agentId: value.agentId });
// ...
} catch (err) {
const sessionKeyForError = hookEventSessionKey ?? fallbackSessionKey;
enqueueSystemEvent(`Hook ${safeName} (error): ${String(err)}`, {
sessionKey: sessionKeyForError,
trusted: false,
});
}
})();If you need the real main session key, resolve it once in a safe place where errors can be propagated/handled (e.g., before spawning the async task), and store it in a variable. Analyzed PR: #73228 at commit Last updated on: 2026-04-28T03:50:40Z |
Greptile SummaryThis PR fixes event routing for hook completion and error system events: when a hook is dispatched with an explicit Confidence Score: 5/5Safe to merge — the change is focused, well-tested at both the unit and integration level, and introduces no new error paths. No P0 or P1 issues found. The implementation correctly scopes hookEventSessionKey before the awaited call so the fallback is only reachable on pre-assignment failure. The test mock fix (config/io.js) is a genuine correctness improvement. All assertions match the new routing behavior. No files require special attention. Reviews (1): Last reviewed commit: "security(gateway): route hook completion..." | Re-trigger Greptile |
Fixes #24693.
This repairs and validates the focused implementation from #68667 by @bluesky6868. The fix routes hook completion and error system events to the hook target agent's main session instead of the default agent session, preserving cross-agent isolation for hook summaries while keeping the no-agent fallback behavior.
ProjectClownfish should rebase or refresh the contributor branch if needed, verify the Greptile loadConfig feedback remains addressed, run Codex /review, address every finding, and run
pnpm check:changedbefore merge. Credit: original report by @abersonFAC in #24693; source PR and implementation by @bluesky6868 in #68667.ProjectClownfish replacement details:
fatal: unable to access 'https://github.com/security-for-ai-agent/openclaw.git/': The requested URL returned error: 403