Repository navigation
fix(feishu): support native interactive card payload sends - #72667
Conversation
🔒 Aisle Security AnalysisWe found 3 potential security issue(s) in this PR:
1. 🟠 Feishu native card sanitization allows attacker-controlled `ocf1` envelopes that execute arbitrary bot commands on click
Description
Downstream, This creates a gadget where an untrusted actor who can influence outbound payloads (e.g., via
When clicked, the bot will execute Vulnerable code paths:
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, ... });
}RecommendationTreat all Recommended fixes (pick one or combine):
// 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 },
});
}
These prevent a crafted 2. 🟡 Unescaped fallback text inserted into Feishu card markdown enabling mention/tag injection
DescriptionWhen building a native Feishu card, most user-controlled text is passed through 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
Vulnerable code: if (elements.length === 0) {
elements.push({
tag: "markdown",
content: renderMessagePresentationFallbackText({ text, presentation }),
});
}RecommendationEscape the fallback text before inserting it into Feishu card 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 3. 🟡 Feishu card button URL sanitization allows insecure http: links (insufficient URL validation)
Description
Implications when button URLs can be influenced by untrusted or semi-trusted sources (templates, upstream integrations, user-generated content):
Vulnerable code: const parsed = new URL(trimmed);
return parsed.protocol === "https:" || parsed.protocol === "http:" ? trimmed : undefined;RecommendationTighten the allowlist to enforce 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):
Analyzed PR: #72667 at commit Last updated on: 2026-04-27T16:59:45Z |
Greptile SummaryThis PR repairs the Feishu Confidence Score: 4/5Safe 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 AIThis 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 |
| return { tag: "markdown", content: block.text }; | ||
| } | ||
| if (block.type === "context") { | ||
| return { tag: "markdown", content: `<font color='grey'>${block.text}</font>` }; |
There was a problem hiding this 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.
| 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.db84935 to
e4e543d
Compare
|
ProjectClownfish follow-up: rebased this branch on current main and addressed the Feishu card review/security findings. Changes in the pushed head:
Remote Blacksmith validation passed: |
…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
…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
…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
…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
…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
…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
Summary
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.tspnpm check:changedProjectClownfish replacement details: