Skip to content

fix(feishu): support native interactive card payload sends - #72667

Merged
vincentkoc merged 3 commits into
mainfrom
clownfish/ghcrawl-156608-autonomous-smoke
Apr 27, 2026
Merged

vincentkoc merged 3 commits into
mainfrom
clownfish/ghcrawl-156608-autonomous-smoke

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

  • Repair the Feishu sendPayload/native card path from feat(feishu): implement sendPayload for interactive card support #47891 so outgoing Feishu interactive cards can be sent through the channel adapter.
  • Keep text/media fallback behavior intact, including local media handling, thread replies, and chunking limits.
  • Address hydrated review-bot findings before merge and validate with pnpm check:changed.

Credit

This carries forward the contributor work from @Horacehxw in #47891. Thanks @Horacehxw for the original implementation path.

Linked Issues

Validation

  • pnpm -s vitest run extensions/feishu/src/outbound.test.ts
  • pnpm check:changed

ProjectClownfish replacement details:

@aisle-research-bot

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

Copy link
Copy Markdown

🔒 Aisle Security Analysis

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

# Severity Title
1 🟠 High Feishu native card sanitization allows attacker-controlled ocf1 envelopes that execute arbitrary bot commands on click
2 🟡 Medium Unescaped fallback text inserted into Feishu card markdown enabling mention/tag injection
3 🟡 Medium Feishu card button URL sanitization allows insecure http: links (insufficient URL validation)
1. 🟠 Feishu native card sanitization allows attacker-controlled `ocf1` envelopes that execute arbitrary bot commands on click
Property Value
Severity High
CWE CWE-94
Location extensions/feishu/src/outbound.ts:131-156

Description

sanitizeNativeFeishuCardButton() preserves any caller-supplied button value object as long as value.oc === "ocf1", without validating the envelope fields (k, a, q, c, etc.).

Downstream, handleFeishuCardAction() treats any structured envelope with envelope.k === "quick" as an executable command and dispatches it via dispatchSyntheticCommand().

This creates a gadget where an untrusted actor who can influence outbound payloads (e.g., via payload.channelData.feishu.card / interactiveCard) can craft a card button value such as:

  • {"oc":"ocf1","k":"quick","q":"/reset"}

When clicked, the bot will execute /reset (or any other command handled by the bot), bypassing intended UI/action constraints and potentially any higher-level authorization expectations.

Vulnerable code paths:

  • Outbound: caller-supplied card button values are passed through if they merely claim ocf1.
  • Inbound: envelope.k === "quick" directly controls command execution, without an allowlist on envelope.a or binding to expected context (user/chat/expiry/session).

Vulnerable code (outbound sanitization):

if (isRecord(button.value) && button.value.oc === "ocf1") {
  rendered.value = button.value;
}

Vulnerable code (inbound execution gate):

if (envelope.a === FEISHU_APPROVAL_CONFIRM_ACTION || envelope.k === "quick") {
  const command = envelope.q?.trim();
  ...
  await dispatchSyntheticCommand({ ..., command, ... });
}

Recommendation

Treat all payload.channelData.feishu.card content as untrusted and never pass through opaque ocf1 envelopes.

Recommended fixes (pick one or combine):

  1. Strictly re-wrap button values during sanitization (ignore caller-supplied value objects entirely) and only generate envelopes via createFeishuCardInteractionEnvelope():
​// in sanitizeNativeFeishuCardButton
​// do NOT copy through button.value
if (typeof button.value === "string" && button.value.trim()) {
  rendered.value = createFeishuCardInteractionEnvelope({
    k: "quick",
    a: "feishu.payload.button",
    q: button.value,
    c: { u: expectedOpenId, h: expectedChatId, e: Date.now() + 5 * 60_000 },
  });
}
  1. Enforce an allowlist in handleFeishuCardAction() so only known actions can trigger command dispatch, e.g. require envelope.a === "feishu.payload.button" (and/or a small set of actions) before accepting k === "quick".

  2. Bind envelopes to context (c.u, c.h, expiry c.e, and optionally a session key) for all quick interactions, and reject envelopes missing these fields.

These prevent a crafted ocf1 object from turning into an arbitrary command execution trigger when a user clicks a card button.

2. 🟡 Unescaped fallback text inserted into Feishu card markdown enabling mention/tag injection
Property Value
Severity Medium
CWE CWE-79
Location extensions/feishu/src/outbound.ts:331-335

Description

When building a native Feishu card, most user-controlled text is passed through escapeFeishuCardMarkdownText() before being placed into markdown elements. However, if no elements are produced (e.g., because all blocks were filtered out / produced no valid elements), the code falls back to renderMessagePresentationFallbackText() and inserts its returned string directly into a markdown card element without escaping.

This creates an injection path where attacker-controlled content (e.g., button labels/placeholders/options included in the fallback text) can contain Feishu card markup such as <at id="...">...</at> or other supported tags/constructs, leading to:

  • Unexpected mentions/pings (social engineering / notification spam)
  • Rendered arbitrary Feishu-markup content inside the card

Vulnerable code:

if (elements.length === 0) {
  elements.push({
    tag: "markdown",
    content: renderMessagePresentationFallbackText({ text, presentation }),
  });
}

Recommendation

Escape the fallback text before inserting it into Feishu card markdown elements.

if (elements.length === 0) {
  elements.push({
    tag: "markdown",
    content: escapeFeishuCardMarkdownText(
      renderMessagePresentationFallbackText({ text, presentation }),
    ),
  });
}

Additionally, consider adding a regression test where all blocks are filtered out (e.g., only buttons with unsafe URLs and no value) and the fallback includes an <at ...> sequence, asserting it is rendered as &lt;at ...&gt; in the card.

3. 🟡 Feishu card button URL sanitization allows insecure http: links (insufficient URL validation)
Property Value
Severity Medium
CWE CWE-20
Location extensions/feishu/src/outbound.ts:110-118

Description

resolveSafeFeishuButtonUrl is used to accept/forward button URLs into native Feishu interactive cards. It currently allows both https: and http: schemes.

Implications when button URLs can be influenced by untrusted or semi-trusted sources (templates, upstream integrations, user-generated content):

  • Downgrade/MITM risk: http: links can be intercepted or modified in transit, enabling phishing or content injection.
  • Weak URL policy: while some dangerous schemes are rejected via the protocol allowlist, the current policy does not enforce transport security or apply any host restrictions (e.g., localhost/private ranges) if those are part of your product security requirements.

Vulnerable code:

const parsed = new URL(trimmed);
return parsed.protocol === "https:" || parsed.protocol === "http:" ? trimmed : undefined;

Recommendation

Tighten the allowlist to enforce https: only (and optionally add host-based restrictions if required).

Example (HTTPS-only):

function resolveSafeFeishuButtonUrl(url: string | undefined): string | undefined {
  const trimmed = url?.trim();
  if (!trimmed) return undefined;

  let parsed: URL;
  try {
    parsed = new URL(trimmed);
  } catch {
    return undefined;
  }

  if (parsed.protocol !== "https:") return undefined;
  return parsed.toString();
}

Optional hardening (depending on requirements):

  • Reject localhost, .local, and private IP ranges (RFC1918/loopback/link-local)
  • Consider allowing only an explicit domain allowlist if buttons should only point to known services

Analyzed PR: #72667 at commit e4e543d

Last updated on: 2026-04-27T16:59:45Z

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

greptile-apps Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR repairs the Feishu sendPayload / native interactive card path by adding sendPayload and renderPresentation to feishuOutbound in outbound.ts and wiring them through channel.ts. Text/media fallbacks, comment-thread routing, and chunking limits are preserved, and a comprehensive test suite covers the new code paths.

Confidence Score: 4/5

Safe to merge; both findings are non-blocking style suggestions with no functional impact on the happy path.

Only P2 findings: one for unescaped string interpolation in the context block renderer and one for a missing ?? 'blue' fallback on resolveFeishuCardTemplate. All core logic — card building, comment-target fallback, media sequencing, and channel wiring — is correct and well-tested.

extensions/feishu/src/outbound.ts lines 139 and 199–207

Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/feishu/src/outbound.ts
Line: 139

Comment:
**Unescaped content interpolated into Feishu markdown tag**

`block.text` is inserted directly inside `<font color='grey'>...</font>` without escaping. If the text contains `</font>`, it breaks out of the tag and injects arbitrary Feishu card markdown/HTML tags into the rendered card. While this content typically originates from trusted internal sources, a stray `</font>` in the context text (e.g. from a code-block or user-supplied label) would corrupt the card rendering and could cause unexpected tag injection in Feishu's renderer.

```suggestion
    return { tag: "markdown", content: `<font color='grey'>${block.text.replaceAll("</font>", "\\</font>")}</font>` };
```

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/outbound.ts
Line: 199-207

Comment:
**`resolveFeishuCardTemplate` result used without fallback**

Unlike `sendStructuredCardFeishu` which does `resolveFeishuCardTemplate(template) ?? "blue"`, the call here has no fallback. If `resolveFeishuCardTemplate` returns `undefined` (e.g. for an unrecognised tone value or a future tone added before this switch is updated), the card header will carry `template: undefined`, which may cause the Feishu API to reject the card or render with no colour. Adding `?? "blue"` matches the convention used everywhere else in `send.ts`.

```suggestion
  const template =
    resolveFeishuCardTemplate(
      presentation?.tone === "danger"
        ? "red"
        : presentation?.tone === "warning"
          ? "orange"
          : presentation?.tone === "success"
            ? "green"
            : "blue",
    ) ?? "blue";
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(clownfish): address review for ghcra..." | Re-trigger Greptile

Comment thread extensions/feishu/src/outbound.ts Outdated
return { tag: "markdown", content: block.text };
}
if (block.type === "context") {
return { tag: "markdown", content: `<font color='grey'>${block.text}</font>` };

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 Unescaped content interpolated into Feishu markdown tag

block.text is inserted directly inside <font color='grey'>...</font> without escaping. If the text contains </font>, it breaks out of the tag and injects arbitrary Feishu card markdown/HTML tags into the rendered card. While this content typically originates from trusted internal sources, a stray </font> in the context text (e.g. from a code-block or user-supplied label) would corrupt the card rendering and could cause unexpected tag injection in Feishu's renderer.

Suggested change
return { tag: "markdown", content: `<font color='grey'>${block.text}</font>` };
return { tag: "markdown", content: `<font color='grey'>${block.text.replaceAll("</font>", "\\</font>")}</font>` };
Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/feishu/src/outbound.ts
Line: 139

Comment:
**Unescaped content interpolated into Feishu markdown tag**

`block.text` is inserted directly inside `<font color='grey'>...</font>` without escaping. If the text contains `</font>`, it breaks out of the tag and injects arbitrary Feishu card markdown/HTML tags into the rendered card. While this content typically originates from trusted internal sources, a stray `</font>` in the context text (e.g. from a code-block or user-supplied label) would corrupt the card rendering and could cause unexpected tag injection in Feishu's renderer.

```suggestion
    return { tag: "markdown", content: `<font color='grey'>${block.text.replaceAll("</font>", "\\</font>")}</font>` };
```

How can I resolve this? If you propose a fix, please make it concise.

Comment thread extensions/feishu/src/outbound.ts Resolved
@vincentkoc vincentkoc added the clawsweeper Tracked by ClawSweeper automation label Apr 27, 2026
@vincentkoc
vincentkoc force-pushed the clownfish/ghcrawl-156608-autonomous-smoke branch from db84935 to e4e543d Compare April 27, 2026 16:57
@vincentkoc

Copy link
Copy Markdown
Member Author

ProjectClownfish follow-up: rebased this branch on current main and addressed the Feishu card review/security findings.

Changes in the pushed head:

  • escaped generated Feishu card markdown/context text before wrapping it in card markdown tags
  • dropped unsafe non-http(s) button URLs
  • normalized caller-supplied native Feishu cards instead of passing arbitrary card payloads through unchanged
  • added the missing card template fallback to blue

Remote Blacksmith validation passed: pnpm test:serial extensions/feishu/src/outbound.test.ts (28 tests).

@vincentkoc
vincentkoc merged commit 2161b46 into main Apr 27, 2026
66 checks passed
@vincentkoc
vincentkoc deleted the clownfish/ghcrawl-156608-autonomous-smoke branch April 27, 2026 18:02
@clawsweeper clawsweeper Bot mentioned this pull request May 1, 2026
8 of 25 tasks
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…72667)

* fix(feishu): support native interactive card payload sends

* fix(clownfish): address review for ghcrawl-156608-autonomous-smoke (1)

* fix(feishu): harden native card payload rendering
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
…72667)

* fix(feishu): support native interactive card payload sends

* fix(clownfish): address review for ghcrawl-156608-autonomous-smoke (1)

* fix(feishu): harden native card payload rendering
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…72667)

* fix(feishu): support native interactive card payload sends

* fix(clownfish): address review for ghcrawl-156608-autonomous-smoke (1)

* fix(feishu): harden native card payload rendering
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…72667)

* fix(feishu): support native interactive card payload sends

* fix(clownfish): address review for ghcrawl-156608-autonomous-smoke (1)

* fix(feishu): harden native card payload rendering
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
…72667)

* fix(feishu): support native interactive card payload sends

* fix(clownfish): address review for ghcrawl-156608-autonomous-smoke (1)

* fix(feishu): harden native card payload rendering
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…72667)

* fix(feishu): support native interactive card payload sends

* fix(clownfish): address review for ghcrawl-156608-autonomous-smoke (1)

* fix(feishu): harden native card payload rendering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu clawsweeper Tracked by ClawSweeper automation maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant