fix(feishu): neutralize untrusted mentions

Forge text is untrusted and can contain at-all tags.
Neutralize mentions in card bodies and footers before rendering.
This commit is contained in:
翅膀 committed 2026-10-23 23:23:19 +08:00
1 parent 4c1ec472af
commit e850ec3c14
1 file changed
+12 -2
+12 -2
View File
@@ -26,8 +26,18 @@ function colorToTemplate(color?: number): FeishuTemplate {
return "blue";
}
/**
* Text from the forge (titles, bodies, names) is anyone's to write: an
* `<at id=all></at>` in an issue title would make the bot notify the whole
* chat. The card never mentions anyone itself, so every `<at` tag is broken
* up (a zero-width space after `<`) and shows as text.
*/
function noMentions(content: string): string {
return content.replace(/<(\/?)(at)\b/gi, "<\u200b$1$2");
}
function mdText(content: string): { tag: "lark_md"; content: string } {
return { tag: "lark_md", content: cap(content, MAX_MARKDOWN) };
return { tag: "lark_md", content: cap(noMentions(content), MAX_MARKDOWN) };
}
function divMarkdown(content: string): { tag: "div"; text: { tag: "lark_md"; content: string } } {
@@ -92,7 +102,7 @@ export function renderNeutralMessage(message: NeutralMessage): Record<string, un
if (elements.length) elements.push({ tag: "hr" });
elements.push({
tag: "note",
elements: [{ tag: "lark_md", content: cap(meta.join(" · "), MAX_NOTE) }],
elements: [{ tag: "lark_md", content: cap(noMentions(meta.join(" · ")), MAX_NOTE) }],
});
}