Skip to content

Commit f6eb247

Browse files
committed
💄
1 parent b1bde5a commit f6eb247

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/package.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -422,20 +422,18 @@ function sanitizeCommitMessage(message?: string): string | undefined {
422422
return undefined;
423423
}
424424

425-
// Allow alphanumeric, space, common punctuation, newline characters.
426-
// Specifically check for characters that might escape quotes or introduce shell commands.
427-
// Newlines are allowed, but backslashes (other than for newlines), backticks, and dollar signs are still checked.
425+
// Check for characters that might escape quotes or introduce shell commands.
426+
// Don't allow: ', ", `, $, \ (except for \n)
428427
const unsafeRegex = /(?<!\\)\\(?!n)|['"`$]/g;
429428

430-
// Replace any unsafe characters found by the unsafeRegex
429+
// Remove any unsafe characters found by the unsafeRegex
431430
const sanitizedMessage = message.replace(unsafeRegex, '');
432431

433432
// Additional check to make sure nothing potentially dangerous is still in the string
434433
if ([`'`, `"`, '`', '$'].some(char => sanitizedMessage.includes(char))) {
435434
throw new Error('Commit message contains potentially dangerous characters after initial sanitization.');
436435
}
437436

438-
// Make sure all backslashes are followed by 'n' to prevent shell injection
439437
for (let index = 0; index < sanitizedMessage.length; index++) {
440438
const char = sanitizedMessage[index];
441439
if (char === '\\' && sanitizedMessage[index + 1] !== 'n') {

0 commit comments

Comments
 (0)