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 1188664 commit 9e06c04
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ export async function versionBump(options: IVersionBumpOptions): Promise<void> {
}
}

export function sanitizeCommitMessage(message: string): string | undefined {
function sanitizeCommitMessage(message: string): string | 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.
Expand All @@ -433,12 +433,12 @@ export function sanitizeCommitMessage(message: string): string | undefined {
}

// Make sure all backslashes are followed by 'n' to prevent shell injection
sanitizedMessage.split('').reduce((positions: number[], char: string, index: number) => {
for (let index = 0; index < sanitizedMessage.length; index++) {
const char = sanitizedMessage[index];
if (char === '\\' && sanitizedMessage[index + 1] !== 'n') {
throw new Error('Commit message contains potentially dangerous characters after initial sanitization.');
}
return positions;
}, []);
}

if (sanitizedMessage.length === 0) {
return undefined;
Expand Down

0 comments on commit 9e06c04

Please sign in to comment.