Skip to content

Commit

Permalink
💄
Browse files Browse the repository at this point in the history
  • Loading branch information
benibenj committed May 2, 2024
1 parent b1bde5a commit f6eb247
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,18 @@ function sanitizeCommitMessage(message?: string): string | undefined {
return undefined;
}

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

// Replace any unsafe characters found by the unsafeRegex
// Remove any unsafe characters found by the unsafeRegex
const sanitizedMessage = message.replace(unsafeRegex, '');

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

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

0 comments on commit f6eb247

Please sign in to comment.