Repository navigation
fix(feishu): back off failed streaming card starts - #71444
Conversation
🔒 Aisle Security AnalysisWe found 2 potential security issue(s) in this PR:
1. 🟠 Configurable Feishu `domain` allows SSRF and credential exfiltration to attacker-controlled host
DescriptionThe Feishu extension allows configuring Impact if an attacker can influence plugin configuration (or if config is sourced from an untrusted location):
Vulnerable code paths:
Vulnerable code: // client.ts
return domain.replace(/\/+$/, ""); // Custom URL for private deployment
...
domain: resolveDomain(domain),// streaming-card.ts
url: `${resolveApiBase(creds.domain)}/auth/v3/tenant_access_token/internal`,
body: JSON.stringify({ app_id: creds.appId, app_secret: creds.appSecret }),
policy: { allowedHostnames: resolveAllowedHostnames(creds.domain) },RecommendationDo not allow arbitrary domains unless you fully trust the configuration source. Mitigations (pick one, preferably multiple):
Example validation: function validateFeishuDomain(domain?: string): string {
if (!domain || domain === "feishu") return "https://open.feishu.cn";
if (domain === "lark") return "https://open.larksuite.com";
const u = new URL(domain);
if (u.protocol !== "https:") throw new Error("domain must be https");
// allowlist for private deployments (example)
const allowed = new Set(["open.feishu.cn", "open.larksuite.com", "feishu.mycorp.example"]);
if (!allowed.has(u.hostname)) throw new Error("unapproved domain hostname");
return u.origin;
}Then use the validated origin for both SDK config and 2. 🔵 Log injection risk via untrusted error message in Feishu streaming start failure log
DescriptionThe Feishu reply dispatcher logs streaming start failures by interpolating
Vulnerable code: params.runtime.error?.(
`feishu[${account.accountId}]: streaming start failed; using non-streaming card fallback for ${
STREAMING_START_FAILURE_BACKOFF_MS / 1000
}s: ${String(error)}`,
);RecommendationSanitize error text before logging to prevent log injection and reduce accidental leakage.
Example: function toSingleLineLogValue(value: unknown): string {
const s = value instanceof Error ? (value.message || value.name) : String(value);
return s.replace(/[\r\n\t\0]/g, " ").slice(0, 2000);
}
params.runtime.error?.(
`feishu[${account.accountId}]: streaming start failed; fallback ${
STREAMING_START_FAILURE_BACKOFF_MS / 1000
}s: ${toSingleLineLogValue(error)}`,
);If stack traces are needed, log them separately via a controlled/structured field, not via Analyzed PR: #71444 at commit Last updated on: 2026-04-25T06:39:43Z |
Greptile SummaryThis PR adds a per-account 60-second backoff after Feishu streaming-card Confidence Score: 4/5Safe to merge — logic is correct, backoff is properly scoped per account, and regression tests validate both the suppression window and recovery. No P0 or P1 issues found. The two P2 comments are minor style concerns (test helper export and a redundant delete). The backoff state machine, fallback path, and test assertions are all correct. No files require special attention. Prompt To Fix All With AIThis is a comment left during a code review.
Path: extensions/feishu/src/reply-dispatcher.ts
Line: 56-58
Comment:
**Test helper exported from production module**
`clearFeishuStreamingStartBackoffForTests` is exported directly from the production module. This leaks test infrastructure into the public API of `reply-dispatcher.ts` and will appear in any IDE auto-complete or barrel re-exports. A common mitigation is to only expose it via a conditional or a separate `*-test-utils` companion file.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: extensions/feishu/src/reply-dispatcher.ts
Line: 323
Comment:
**Redundant delete on successful start**
`streamingStartBackoffUntilByAccount.delete(account.accountId)` on the success path is always a no-op: `isStreamingStartBackedOff` only allows `startStreaming` to proceed after it has already deleted the entry (expired) or when no entry exists at all. The line is harmless but misleading — a reader might think success can race with an active backoff entry, which it can't by construction.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(feishu): back off failed streaming c..." | Re-trigger Greptile |
| export function clearFeishuStreamingStartBackoffForTests() { | ||
| streamingStartBackoffUntilByAccount.clear(); | ||
| } |
There was a problem hiding this comment.
Test helper exported from production module
clearFeishuStreamingStartBackoffForTests is exported directly from the production module. This leaks test infrastructure into the public API of reply-dispatcher.ts and will appear in any IDE auto-complete or barrel re-exports. A common mitigation is to only expose it via a conditional or a separate *-test-utils companion file.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/feishu/src/reply-dispatcher.ts
Line: 56-58
Comment:
**Test helper exported from production module**
`clearFeishuStreamingStartBackoffForTests` is exported directly from the production module. This leaks test infrastructure into the public API of `reply-dispatcher.ts` and will appear in any IDE auto-complete or barrel re-exports. A common mitigation is to only expose it via a conditional or a separate `*-test-utils` companion file.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| header: cardHeader, | ||
| note: cardNote, | ||
| }); | ||
| streamingStartBackoffUntilByAccount.delete(account.accountId); |
There was a problem hiding this comment.
Redundant delete on successful start
streamingStartBackoffUntilByAccount.delete(account.accountId) on the success path is always a no-op: isStreamingStartBackedOff only allows startStreaming to proceed after it has already deleted the entry (expired) or when no entry exists at all. The line is harmless but misleading — a reader might think success can race with an active backoff entry, which it can't by construction.
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/feishu/src/reply-dispatcher.ts
Line: 323
Comment:
**Redundant delete on successful start**
`streamingStartBackoffUntilByAccount.delete(account.accountId)` on the success path is always a no-op: `isStreamingStartBackedOff` only allows `startStreaming` to proceed after it has already deleted the entry (expired) or when no entry exists at all. The line is harmless but misleading — a reader might think success can race with an active backoff entry, which it can't by construction.
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: 255bb7e13c
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| !streamingEnabled || | ||
| streamingStartPromise || | ||
| streaming || | ||
| isStreamingStartBackedOff(account.accountId) |
There was a problem hiding this comment.
Key streaming-start backoff by destination
The new backoff gate is keyed only by account.accountId, but streaming.start(...) is destination-specific because it uses chatId; a single HTTP 400 from one bad/unsupported chat now suppresses streaming-card starts for all other chats on the same account for 60 seconds. This broadens a per-target failure into cross-chat degradation. Consider scoping the backoff key to the receive target (for example accountId + chatId or equivalent) so healthy chats are unaffected.
Useful? React with 👍 / 👎.
Summary
Fixes #56981
Validation
OPENCLAW_LOCAL_CHECK=0 OPENCLAW_VITEST_FS_MODULE_CACHE=0 pnpm test extensions/feishu/src/reply-dispatcher.test.ts extensions/feishu/src/config-schema.test.ts extensions/feishu/setup-entry.test.tsOPENCLAW_LOCAL_CHECK=0 OPENCLAW_VITEST_FS_MODULE_CACHE=0 pnpm test src/plugins/bundled-plugin-metadata.test.ts src/config/bundled-channel-config-runtime.test.ts src/config/load-channel-config-surface.test.tsOPENCLAW_LOCAL_CHECK=0 OPENCLAW_VITEST_FS_MODULE_CACHE=0 pnpm check:changedcurrently fails in unrelatedextensions/qa-lab/web/src/main.tson./styles.csstype declarations; this branch touches only Feishu/changelog files.