Skip to content

Commit 9fecab2

Browse files
committed
fix: escape markdown in commit messages per CodeRabbit review
Signed-off-by: cheese-cakee <farzanaman99@gmail.com>
1 parent 0237597 commit 9fecab2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

.github/scripts/bot-verified-commits.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ function sanitizeString(input) {
88
return input.replace(/\p{Cc}/gu, '').trim();
99
}
1010

11+
// Escapes markdown special characters and breaks @mentions to prevent injection
12+
// Required per CodeRabbit review: commit messages are user-controlled and can cause
13+
// markdown injection or unwanted @mentions that spam teams
14+
function sanitizeMarkdown(input) {
15+
return sanitizeString(input)
16+
.replace(/[`*_~[\]()]/g, '\\$&') // Escape markdown special chars
17+
.replace(/@/g, '@\u200b'); // Break @mentions with zero-width space
18+
}
19+
1120
// Validates URL format and returns fallback if invalid
1221
function sanitizeUrl(input, fallback) {
1322
const cleaned = sanitizeString(input);
@@ -156,7 +165,7 @@ function buildVerificationComment(
156165
const commitList = unverifiedCommits.length
157166
? unverifiedCommits.slice(0, maxDisplay).map(c => {
158167
const sha = c.sha?.substring(0, 7) || 'unknown';
159-
const msg = sanitizeString(c.commit?.message?.split('\n')[0] || 'No message').substring(0, 50);
168+
const msg = sanitizeMarkdown(c.commit?.message?.split('\n')[0] || 'No message').substring(0, 50);
160169
return `- \`${sha}\` ${msg}`;
161170
}).join('\n')
162171
: (truncated ? '- Unable to enumerate commits due to pagination limit.' : '');

0 commit comments

Comments
 (0)