Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): strip backticks from a push name used in a mention
Yudhi Armyndharisf2015816fc2b
diff --git a/dashboard/src/components/chats/MessageBody.test.ts b/dashboard/src/components/chats/MessageBody.test.tsindex 0edb9c649..7f1107917 100644--- a/dashboard/src/components/chats/MessageBody.test.ts+++ b/dashboard/src/components/chats/MessageBody.test.ts@@ -76,3 +76,16 @@ test('a mention inside *bold* renders bold with the <bdi> as a child, not literaassert.equal(container.querySelector('strong')?.textContent, 'Reminder @Ravi at 10');assert.ok(container.querySelector('strong bdi'), 'the mention sits inside the bold element');});++test('a backtick in a push name cannot pair with one in the body and hand the name tail to Linkify', () => {+ const names = buildMentionNameMap([+ { author: '[email protected]', chatName: 'a`evil.com' },+ { author: '[email protected]', chatName: '`x`evil.com/login' },+ ]);+ for (const body of ['` look @6281112345', 'please ask @6281112346 about it']) {+ const { container } = rtl.render(createElement(MessageBody, { text: resolveMentions(body, names) }));+ assert.equal(container.querySelectorAll('a').length, 0, body);+ assert.equal(container.querySelectorAll('bdi').length, 1, body);+ rtl.cleanup();+ }+});diff --git a/dashboard/src/utils/chatMessages.ts b/dashboard/src/utils/chatMessages.tsindex e00f34058..00e4eb678 100644--- a/dashboard/src/utils/chatMessages.ts+++ b/dashboard/src/utils/chatMessages.ts@@ -126,8 +126,10 @@ export function buildMentionNameMap(messages: Pick<ChatMessage, 'author' | 'chatif (!m.author || !m.chatName) continue;const local = m.author.split('@')[0].split(':')[0];// A push name is sender-controlled: strip the span delimiters so a name cannot close its own- // mention early and hand its tail back to Linkify and the format parser.- const name = m.chatName.replace(MENTION_DELIMITERS, '').trim();+ // mention early and hand its tail back to Linkify and the format parser. Backticks go too:+ // parseMessageBody peels code before it sees a mention span, so one in the name would pair+ // with another backtick and split the span the same way.+ const name = m.chatName.replace(MENTION_DELIMITERS, '').replace(/`/g, '').trim();// Rows are ascending by time, so the last write is the participant's current push name.if (name && !blankMentionName(name) && /^\d+$/.test(local)) map.set(local, name);}