Repository navigation
fix(discord): keep mention labels literal in text substitution - #130778
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
steipete
marked this pull request as ready for review
August 27, 2026 07:16
Contributor
Author
|
Merged via squash.
|
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Discord inbound mention substitution passes user-controlled display names as the replacement string to
String.prototype.replace, which interprets$sequences. Any message mentioning a user whose name contains a$pattern gets silently corrupted before it reaches the agent, channel history, and reply/forward context:$$(e.g.big$$money) renders asbig$money;$'duplicates the trailing half of the message;$`duplicates the leading half;$&reinserts the raw<@id>markup — a mild injection vector, since a mentioned user's name can rewrite other people's message text as the agent sees it.The same site rendered
@undefinedwhen a mention payload carried neitherglobalNamenorusername.Why This Change Was Made
resolveDiscordMentions(message-text.ts) is the shared projection used by the message body, history entries, and reply/forward context, so the corruption propagated everywhere Discord text is read. The fix keeps the label literal by using a replacer callback (() =>@${label}``) and falls back to the user ID for nameless users, matching the existing@idconventions in `message-forwarded.ts:112` and `format.ts:38`. Sibling channels are unaffected: Slack strips mentions with a static replacement and Telegram mentions are already plain text; a repo-wide sweep found this to be the only dynamic-regex + templated-replacement site in the channel plugins. The defect exists in shipped stable `v2026.6.1`.Production LOC: +2/−2 (net 0); tests +26.
User Impact
Discord messages mentioning users with
$sequences in their names now reach the agent verbatim, and a crafted display name can no longer duplicate or rewrite message content. Nameless mention payloads render as@<id>instead of@undefined.Evidence
$$→$collapse, and@undefined.<@id>/<@!id>markup, repeated mentions, all four active$substitution patterns, and absent/empty names; 6 fail on pre-fix code, 25/25 pass post-fix (node scripts/run-vitest.mjs extensions/discord/src/monitor/message-text, re-run green after rebase onto latestorigin/main).