Repository navigation
fix: align claude-cli prompt hooks - #70625
Conversation
🔒 Aisle Security AnalysisWe found 3 potential security issue(s) in this PR:
1. 🟡 Unbounded session history loading for CLI prompt-build hooks can cause memory/CPU exhaustion
DescriptionIn
Vulnerable code: function loadCliPromptBuildMessages(sessionFile: string): unknown[] {
const entries = SessionManager.open(sessionFile).getEntries();
return entries.flatMap((entry) => (entry.type === "message" ? [entry.message as unknown] : []));
}
...
messages: loadCliPromptBuildMessages(params.sessionFile),RecommendationIntroduce explicit limits when loading session history for hook context. Options (can be combined):
function loadCliPromptBuildMessages(sessionFile: string, maxMessages = 100): unknown[] {
const entries = SessionManager.open(sessionFile).getEntries();
const msgs = entries
.filter((e) => e.type === "message")
.map((e) => e.message as unknown);
return msgs.slice(-maxMessages);
}
Also consider applying the same truncation/session-compaction logic used in the embedded runner path before invoking hooks. 2. 🟡 Potential sensitive data exposure via logging of hook errors in CLI prompt-build path
DescriptionIn
Vulnerable code: } catch (error) {
cliBackendLog.warn(`cli prompt-build hook preparation failed: ${String(error)}`);
}Because RecommendationAvoid logging raw Example fix: import { normalizeUnknownError } from "../infra/errors.js"; // or your local helper
} catch (error) {
const err = normalizeUnknownError(error);
cliBackendLog.warn("cli prompt-build hook preparation failed", {
errorName: err.name,
// avoid err.stack and avoid raw err.message if it may contain secrets
});
// Optionally, only in verbose/debug mode:
// cliBackendLog.debug("cli prompt-build hook preparation failed (details)", { stack: err.stack });
}If you need the message for troubleshooting, apply a redaction/scrubbing utility before emitting it (API keys/tokens, session keys, prompt text, file paths as appropriate). 3. 🟡 Origin metadata spoofing via messageChannel forwarded as messageProvider into CLI run hooks/MCP context
DescriptionThe CLI execution path now forwards untrusted message origin metadata (channel/provider) into both:
In
Vulnerable code (incorrect assignment): messageChannel: params.messageChannel,
...
messageProvider: params.messageChannel,This conflates two concepts (channel ID vs provider) and forwards a potentially attacker-controlled string into internal security-relevant context. Recommendation
Example fix: runCliAgent({
// ...
messageChannel: params.messageChannel,
messageProvider: params.messageProvider, // or undefined
});And before forwarding: import { resolveGatewayMessageChannel } from "../../utils/message-channel-normalize.js";
const safeChannel = resolveGatewayMessageChannel(params.messageChannel) ?? undefined;Only forward Analyzed PR: #70625 at commit Last updated on: 2026-04-23T14:39:19Z |
Greptile SummaryThis PR aligns the Confidence Score: 5/5Safe to merge — all findings are minor style issues. No P0 or P1 issues found. The hook integration logic is consistent with the embedded runner path, error handling is in place (try/catch around hook invocation), and the three execution sites each set the correct trigger value. The only issue is a duplicate import statement that should be merged. src/agents/cli-runner/prepare.ts (duplicate import lines 35-36) Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/cli-runner/prepare.ts
Line: 35-36
Comment:
**Duplicate import from the same module**
Both `resolvePromptBuildHookResult` and `resolveAttemptPrependSystemContext` are imported from `attempt.prompt-helpers.js` in separate statements. These should be merged into a single import to follow standard convention and avoid lint warnings.
```suggestion
import { resolveAttemptPrependSystemContext, resolvePromptBuildHookResult } from "../pi-embedded-runner/run/attempt.prompt-helpers.js";
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: align claude-cli prompt hooks" | Re-trigger Greptile |
| import { resolvePromptBuildHookResult } from "../pi-embedded-runner/run/attempt.prompt-helpers.js"; | ||
| import { resolveAttemptPrependSystemContext } from "../pi-embedded-runner/run/attempt.prompt-helpers.js"; |
There was a problem hiding this comment.
Duplicate import from the same module
Both resolvePromptBuildHookResult and resolveAttemptPrependSystemContext are imported from attempt.prompt-helpers.js in separate statements. These should be merged into a single import to follow standard convention and avoid lint warnings.
| import { resolvePromptBuildHookResult } from "../pi-embedded-runner/run/attempt.prompt-helpers.js"; | |
| import { resolveAttemptPrependSystemContext } from "../pi-embedded-runner/run/attempt.prompt-helpers.js"; | |
| import { resolveAttemptPrependSystemContext, resolvePromptBuildHookResult } from "../pi-embedded-runner/run/attempt.prompt-helpers.js"; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/cli-runner/prepare.ts
Line: 35-36
Comment:
**Duplicate import from the same module**
Both `resolvePromptBuildHookResult` and `resolveAttemptPrependSystemContext` are imported from `attempt.prompt-helpers.js` in separate statements. These should be merged into a single import to follow standard convention and avoid lint warnings.
```suggestion
import { resolveAttemptPrependSystemContext, resolvePromptBuildHookResult } from "../pi-embedded-runner/run/attempt.prompt-helpers.js";
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 51a115f515
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| }; | ||
|
|
||
| function loadCliPromptBuildMessages(sessionFile: string): unknown[] { | ||
| const entries = SessionManager.open(sessionFile).getEntries(); |
There was a problem hiding this comment.
Use active-branch history for CLI prompt hooks
loadCliPromptBuildMessages reads SessionManager.open(...).getEntries(), which returns messages from the whole transcript tree (including sibling branches created by compaction/rewrite flows), not just the active branch. In sessions that have branched, before_prompt_build/legacy hook callbacks will see stale or unrelated turns and can prepend incorrect context/system text, causing prompt mutations to diverge from the actual conversation state; this should use active-branch/session-context messages instead of full entry history.
Useful? React with 👍 / 👎.
51a115f to
303ce20
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5daf7ea34d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const hookMessageProvider = resolveOriginMessageProvider({ | ||
| originatingChannel: params.followupRun.originatingChannel, | ||
| provider: params.sessionCtx.Provider, | ||
| }); |
There was a problem hiding this comment.
Reuse queued messageProvider for CLI hook context
hookMessageProvider is recomputed from sessionCtx.Provider, but queued runs already resolve and persist the authoritative provider in followupRun.run.messageProvider (including cases where Provider/Surface diverge in get-reply-run.ts:699-705). When originatingChannel is unset, this can pass a different provider to CLI hooks/MCP than the one used for routing, so provider-specific prompt hooks run with the wrong channel context. Use the queued run.messageProvider as the source of truth (or at least fallback to it) instead of recomputing from sessionCtx.Provider alone.
Useful? React with 👍 / 👎.
5daf7ea to
3b5908a
Compare
3b5908a to
3de89da
Compare
|
Merged via squash.
Thanks @mbelinky! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3de89da38f
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const hookMessageProvider = resolveOriginMessageProvider({ | ||
| originatingChannel: params.followupRun.originatingChannel, | ||
| provider: params.sessionCtx.Provider, |
There was a problem hiding this comment.
Use live OriginatingChannel when resolving CLI hook context
This resolution drops origin-channel metadata whenever followupRun.originatingChannel is unset, even though the live template context can still provide sessionCtx.OriginatingChannel (the queue builder already handles this case by using ctx.OriginatingChannel ?? sessionCtx.OriginatingChannel in get-reply-run.ts). In those relayed-message sessions, CLI runs now send messageProvider/channelId as the provider fallback instead of the true origin channel, so channel-scoped prompt hooks and MCP routing can execute against the wrong channel.
Useful? React with 👍 / 👎.
* 'main' of https://github.com/openclaw/openclaw: (906 commits) docs(tools): restructure browser reference with tabs/accordions and trim redundant prose fix: tolerate post-update json in install smoke docs: expand Tencent Hy3 provider guide test: skip flaky live probe routes docs: add gateway diagnostics guide chore(release): update appcast for 2026.4.22 docs(plugins): trim skill-workshop headings and collapse example variants; tighten codex-harness guardian explainer fix: keep root memory uppercase (openclaw#70621) fix: restore bundled plugin SDK alias test: skip additional stale live probe routes docs: msteams restructure - Azure Bot Steps, sentence-case headings, grouped config build: update tsgo native preview docs: collapse Slack manifest duplication and trim noise bullets test: skip stale live probe routes docs: extract Matrix push rules runbook, table verify CLI, merge E2EE H3s docs: add GitHub API polling guidance fix: honor explicit CI timing run id ci: validate docs mdx before publish ci: remove runner caps after timing review fix: align claude-cli prompt hooks (openclaw#70625) ...
Merged via squash. Prepared head SHA: 3de89da Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
Merged via squash. Prepared head SHA: 3de89da Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
Merged via squash. Prepared head SHA: 3de89da Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
Merged via squash. Prepared head SHA: 3de89da Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
Merged via squash. Prepared head SHA: 3de89da Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
Merged via squash. Prepared head SHA: 3de89da Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
Merged via squash. Prepared head SHA: 3de89da Co-authored-by: mbelinky <[email protected]> Co-authored-by: mbelinky <[email protected]> Reviewed-by: @mbelinky
Summary
claudefirst and then wiring OpenClaw to the CLI backendTesting
OPENCLAW_VITEST_MAX_WORKERS=1 pnpm test:serial src/auto-reply/reply/agent-runner-execution.test.ts src/agents/cli-runner/prepare.test.ts src/agents/cli-runner.spawn.test.ts src/agents/command/attempt-execution.cli.test.tspnpm check:changed --staged