T09 · Insecure Skill Coding Practices
- Location
scripts/lark-mention.mjs:19- Finding
Unescaped Lark Mention Markup Injection
- Content
View full analysis
`${m.name}` ).join(' '); ``` ### Technical Analysis The `sendMention` function interpolates caller-provided `open_id` and `name` values directly into Lark mention markup. Neither value is subjected to type validation, identifier-format validation, nor context-appropriate escaping. The `open_id` value is inserted into a quoted `user_id` attribute, while `name` is inserted into the markup body. Values containing quotation marks, angle brackets, or closing tags can therefore alter the generated markup structure. Depending on how the local bridge and Lark API parse the resulting message, crafted input may inject additional text or mention tags, spoof displayed member names, or cause the intended mention structure to be interpreted incorrectly. The parallel `mentions` array does not eliminate this risk because its values are also derived directly from the same untrusted member objects: ```javascript const mentions = members.map(m => ({ key: m.open_id, id: { open_id: m.open_id, id_type: 'open_id' }, name: m.name })); ``` ### Attack Path 1. An attacker gains control over, or influences, a caller-supplied entry in the `members` array. 2. The attacker supplies a crafted `open_id` containing an attribute terminator or a crafted `name` containing markup such as a closing `` tag and additional message content. 3. `sendMention` embeds these values verbatim into `fullText`. 4. The generated content is sent to the fixed local bridge at `http://localhost:18780/proactive`. 5. If the bridge or downstream Lark parser accepts the altered structure, the bot sends a manipulated message containing misleading text, malformed mentions, or unintended mention markup. Successful exploitation de ...[truncated 903 chars]- Remediation
View remediation
', '>') .replaceAll('"', '"') .replaceAll("'", '''); } const atTags = members.map(member => { const openId = validateOpenId(member.open_id); const name = escapeMarkupText(member.name); return `${name}`; }).join(' '); ``` 4. Prefer a structured bridge interface that accepts validated mention objects and constructs provider-specific markup internally. This reduces the number of components that manually generate security-sensitive markup. 5. Add tests covering quotation marks, angle brackets, closing tags, empty identifiers, non-string values, oversized input, and duplicate member identifiers. Verify that hostile input is either safely encoded or rejected before any network request is made. ]]>
