Skip to content

fix(feishu): back off failed streaming card starts - #71444

Merged
vincentkoc merged 1 commit into
mainfrom
fix-feishu-streaming-400-latency
Apr 25, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix-feishu-streaming-400-latency

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • add a short per-account backoff after Feishu streaming-card start fails, so HTTP 400 setups fall back to normal cards without retrying every message
  • expose Feishu streaming/render-mode controls in the plugin manifest schema
  • add regression coverage for the backoff and recovery path

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.ts
  • OPENCLAW_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.ts
  • OPENCLAW_LOCAL_CHECK=0 OPENCLAW_VITEST_FS_MODULE_CACHE=0 pnpm check:changed currently fails in unrelated extensions/qa-lab/web/src/main.ts on ./styles.css type declarations; this branch touches only Feishu/changelog files.

@vincentkoc vincentkoc self-assigned this Apr 25, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review April 25, 2026 06:37
@aisle-research-bot

aisle-research-bot Bot commented Apr 25, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 2 potential security issue(s) in this PR:

# Severity Title
1 🟠 High Configurable Feishu domain allows SSRF and credential exfiltration to attacker-controlled host
2 🔵 Low Log injection risk via untrusted error message in Feishu streaming start failure log
1. 🟠 Configurable Feishu `domain` allows SSRF and credential exfiltration to attacker-controlled host
Property Value
Severity High
CWE CWE-918
Location extensions/feishu/src/streaming-card.ts:76-85

Description

The Feishu extension allows configuring domain as an arbitrary URI (in openclaw.plugin.json). That domain is then used to construct API base URLs and to configure the Feishu/Lark SDK domain.

Impact if an attacker can influence plugin configuration (or if config is sourced from an untrusted location):

  • SSRF / internal network access: requests will be made to the configured host.
  • Credential exfiltration: Feishu app secret and derived tenant access token are sent to that host.
  • Bypasses SSRF guard intent: fetchWithSsrFGuard is configured to allow exactly the hostname parsed from the user-provided domain, so the guard does not prevent requests to attacker-chosen hosts.

Vulnerable code paths:

  • createFeishuClient() passes domain directly into the SDK client configuration.
  • streaming-card.ts sends app_secret to ${domain}/open-apis/auth/v3/... and allowlists new URL(domain).hostname.

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) },

Recommendation

Do not allow arbitrary domains unless you fully trust the configuration source.

Mitigations (pick one, preferably multiple):

  1. Hard allowlist approved API hosts, even for “private deployment”, or require an explicit opt-in flag for custom domains.
  2. Enforce HTTPS and restrict hostnames/IPs (block localhost, RFC1918, link-local, metadata IPs, and direct IP literals) before using the domain.
  3. Do not derive SSRF-guard allowlists from user input. Instead, validate the domain against an allowlist and then use that validated value.

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 fetchWithSsrFGuard policies.

2. 🔵 Log injection risk via untrusted error message in Feishu streaming start failure log
Property Value
Severity Low
CWE CWE-117
Location extensions/feishu/src/reply-dispatcher.ts:326-330

Description

The Feishu reply dispatcher logs streaming start failures by interpolating String(error) directly into the log message.

  • error can originate from network/SDK failures (FeishuStreamingSession.start()), which may incorporate remote-provided strings (for example API msg fields) or other untrusted text.
  • Because the error string is not sanitized/normalized, it may contain newline characters or log formatting sequences.
  • This enables log injection / log forging (CWE-117): an attacker who can influence the upstream error text could create misleading multi-line log entries, potentially obscuring security-relevant events.

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)}`,
);

Recommendation

Sanitize error text before logging to prevent log injection and reduce accidental leakage.

  • Strip/replace CR/LF and other control characters from error strings
  • Prefer structured logging fields (error name/message) rather than interpolating unknown objects

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 String(error).


Analyzed PR: #71444 at commit 255bb7e

Last updated on: 2026-04-25T06:39:43Z

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: S maintainer Maintainer-authored PR labels Apr 25, 2026
@greptile-apps

greptile-apps Bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a per-account 60-second backoff after Feishu streaming-card start() failures (e.g. HTTP 400), so messages fall back to normal cards without retrying the expensive startup path on every message. It also extends the plugin manifest schema to expose renderMode, streaming, and other account-level fields that were previously undeclared, and updates the test to assert both the backoff window and post-expiry recovery.

Confidence Score: 4/5

Safe 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 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.

---

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

Comment on lines +56 to +58
export function clearFeishuStreamingStartBackoffForTests() {
streamingStartBackoffUntilByAccount.clear();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

@vincentkoc
vincentkoc merged commit 4df0e10 into main Apr 25, 2026
95 of 97 checks passed
@vincentkoc
vincentkoc deleted the fix-feishu-streaming-400-latency branch April 25, 2026 06:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feishu] Streaming card fails with HTTP 400, causing ~2-3s delay per message

1 participant