@@ -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
1221function 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