Repository navigation
fix(plugins): avoid doctor crash on legacy interactive state - #70135
Conversation
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟠 Global mutable plugin interactive state exposed via globalThis[Symbol.for(...)] enables cross-plugin tampering
Description
Because
Even though the code attempts to “hydrate” legacy shapes, it still trusts any Vulnerable behavior example (attacker plugin code): const k = Symbol.for('openclaw.pluginInteractiveState');
const st = (globalThis as any)[k];
st.interactiveHandlers.set('telegram:payments', { /* attacker handler */ });
st.callbackDedupe.clear();RecommendationAvoid exposing mutable security-relevant state via the global symbol registry. Options (choose based on architecture constraints):
let state: InteractiveState | undefined;
function getState(): InteractiveState {
state ??= createInteractiveState();
return state;
}
Additionally:
Analyzed PR: #70135 at commit Last updated on: 2026-04-22T11:19:03Z |
Greptile SummaryThis PR fixes a Confidence Score: 5/5Safe to merge; the crash fix is correct and all data structures are preserved through hydration. No P0 or P1 issues. The single P2 (unconditional re-hydration allocating a new wrapper object on every getState() call) does not affect correctness — Maps, Sets, and the dedupe cache are all preserved by reference across hydration calls. src/plugins/interactive-state.ts — the getState() short-circuit optimization is worth a follow-up but is not blocking. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/plugins/interactive-state.ts
Line: 56-68
Comment:
**`getState()` hydrates on every call, not just for legacy shapes**
The current implementation calls `hydrateInteractiveState` whenever `existing !== undefined`, including for already-valid `InteractiveState` objects. This means every invocation of `getState()` allocates a new wrapper object and writes it back to `globalStore` — even on paths like `claimPluginInteractiveCallbackDedupe` that call `getState()` on every interactive callback. `clearPluginInteractiveHandlersState()` alone triggers three separate hydrations since it calls `getState()` three times.
A short-circuit that skips re-hydration when the stored value is already fully shaped would avoid the repeated allocation:
```ts
function getState() {
const globalStore = globalThis as Record<PropertyKey, unknown>;
const existing = globalStore[PLUGIN_INTERACTIVE_STATE_KEY];
if (existing !== undefined) {
const s = existing as Partial<InteractiveState>;
if (s.interactiveHandlers instanceof Map && s.inflightCallbackDedupe instanceof Set && s.callbackDedupe) {
return existing as InteractiveState;
}
const hydrated = hydrateInteractiveState(existing);
globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = hydrated;
return hydrated;
}
const created = createInteractiveState();
globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = created;
return created;
}
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(plugins): hydrate legacy interactive..." | Re-trigger Greptile |
| function getState() { | ||
| const globalStore = globalThis as Record<PropertyKey, unknown>; | ||
| const existing = globalStore[PLUGIN_INTERACTIVE_STATE_KEY]; | ||
| if (existing !== undefined) { | ||
| const hydrated = hydrateInteractiveState(existing); | ||
| globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = hydrated; | ||
| return hydrated; | ||
| } | ||
|
|
||
| const created = createInteractiveState(); | ||
| globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = created; | ||
| return created; | ||
| } |
There was a problem hiding this comment.
getState() hydrates on every call, not just for legacy shapes
The current implementation calls hydrateInteractiveState whenever existing !== undefined, including for already-valid InteractiveState objects. This means every invocation of getState() allocates a new wrapper object and writes it back to globalStore — even on paths like claimPluginInteractiveCallbackDedupe that call getState() on every interactive callback. clearPluginInteractiveHandlersState() alone triggers three separate hydrations since it calls getState() three times.
A short-circuit that skips re-hydration when the stored value is already fully shaped would avoid the repeated allocation:
function getState() {
const globalStore = globalThis as Record<PropertyKey, unknown>;
const existing = globalStore[PLUGIN_INTERACTIVE_STATE_KEY];
if (existing !== undefined) {
const s = existing as Partial<InteractiveState>;
if (s.interactiveHandlers instanceof Map && s.inflightCallbackDedupe instanceof Set && s.callbackDedupe) {
return existing as InteractiveState;
}
const hydrated = hydrateInteractiveState(existing);
globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = hydrated;
return hydrated;
}
const created = createInteractiveState();
globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = created;
return created;
}Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugins/interactive-state.ts
Line: 56-68
Comment:
**`getState()` hydrates on every call, not just for legacy shapes**
The current implementation calls `hydrateInteractiveState` whenever `existing !== undefined`, including for already-valid `InteractiveState` objects. This means every invocation of `getState()` allocates a new wrapper object and writes it back to `globalStore` — even on paths like `claimPluginInteractiveCallbackDedupe` that call `getState()` on every interactive callback. `clearPluginInteractiveHandlersState()` alone triggers three separate hydrations since it calls `getState()` three times.
A short-circuit that skips re-hydration when the stored value is already fully shaped would avoid the repeated allocation:
```ts
function getState() {
const globalStore = globalThis as Record<PropertyKey, unknown>;
const existing = globalStore[PLUGIN_INTERACTIVE_STATE_KEY];
if (existing !== undefined) {
const s = existing as Partial<InteractiveState>;
if (s.interactiveHandlers instanceof Map && s.inflightCallbackDedupe instanceof Set && s.callbackDedupe) {
return existing as InteractiveState;
}
const hydrated = hydrateInteractiveState(existing);
globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = hydrated;
return hydrated;
}
const created = createInteractiveState();
globalStore[PLUGIN_INTERACTIVE_STATE_KEY] = created;
return created;
}
```
How can I resolve this? If you propose a fix, please make it concise.c6fd0a9 to
bdcda8c
Compare
|
Landed via temp rebase onto main.\n\n- Gate: pnpm lint && pnpm build && pnpm test\n- Land commit: bdcda8c\n- Merge commit: 8778521\n\nLocal note: repo-wide gate hit existing unrelated type failures in untouched files src/agents/pi-embedded-runner/compact.ts and src/agents/pi-embedded-runner/run/attempt.ts, so I validated the PR with scoped coverage (
RUN v4.1.4 /Users/guti/projects/openclaw/copy-1 Test Files 1 passed (1) |
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
… dream sessions, drop malformed artifacts (openclaw#70135, openclaw#118500, openclaw#66358, openclaw#101953)
…w#70135) * fix(plugins): hydrate legacy interactive state * fix(plugins): avoid doctor crash on legacy interactive state (openclaw#70135) (thanks @ngutman)
Summary
openclaw doctorcould crash withCannot read properties of undefined (reading 'clear')while clearing plugin interactive handler state.openclaw updateruns doctor post-install, so this turned a successful package update into an error path for affected installs.openclaw.pluginInteractiveStateshapes before clearing state, and always rebind callback dedupe from the dedicated global dedupe cache symbol.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
Root Cause (if applicable)
globalThis[Symbol.for("openclaw.pluginInteractiveState")]object shape. Legacy/partial state objects could therefore be missingcallbackDedupeorinflightCallbackDedupe, andclearPluginInteractiveHandlersState()then called.clear()onundefined.Regression Test Plan (if applicable)
src/plugins/interactive.test.tsopenclaw.pluginInteractiveStateobject that only hasinteractiveHandlersshould be hydrated before clear, and interactive callback dedupe should still work afterward.User-visible / Behavior Changes
openclaw doctorandopenclaw updateno longer crash on this legacy partial interactive-state shape.Diagram (if applicable)
N/A
Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
Steps
globalThis[Symbol.for("openclaw.pluginInteractiveState")]with a legacy partial object that only containsinteractiveHandlers.clearPluginInteractiveHandlers().Expected
Actual
Cannot read properties of undefined (reading 'clear').Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
.clear()crash locally by seeding a legacy partial interactive state object before the fix.pnpm test src/plugins/interactive.test.tsafter the fix.openclaw update/openclaw doctorend-to-end in a Debian containerReview Conversations
If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoRisks and Mitigations
callbackDedupeduring hydration could discard an unexpected nonstandard object stored under the legacy state key.pnpm test src/plugins/interactive.test.ts; attemptedpnpm check:changedfailed only in untouched filessrc/agents/pi-embedded-runner/compact.tsandsrc/agents/pi-embedded-runner/run/attempt.ts.