Skip to content

Commit b1bde5a

Browse files
committed
Only sanitize on windows
1 parent 9e06c04 commit b1bde5a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/package.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -395,30 +395,33 @@ export async function versionBump(options: IVersionBumpOptions): Promise<void> {
395395
}
396396
}
397397

398+
398399
// call `npm version` to do our dirty work
399400
const args = ['version', options.version];
400401

401-
if (options.commitMessage) {
402-
// Sanitize commit message due to possible shell injection on windows
403-
const sanitizedCommitMessage = sanitizeCommitMessage(options.commitMessage);
404-
if (sanitizedCommitMessage) {
405-
args.push('-m', sanitizedCommitMessage);
406-
}
402+
const isWindows = process.platform === 'win32';
403+
404+
const commitMessage = isWindows ? sanitizeCommitMessage(options.commitMessage) : options.commitMessage;
405+
if (commitMessage) {
406+
args.push('-m', commitMessage);
407407
}
408408

409409
if (!(options.gitTagVersion ?? true)) {
410410
args.push('--no-git-tag-version');
411411
}
412412

413-
const isWindows = process.platform === 'win32';
414413
const { stdout, stderr } = await promisify(cp.execFile)(isWindows ? 'npm.cmd' : 'npm', args, { cwd, shell: isWindows /* https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2 */ });
415414
if (!process.env['VSCE_TESTS']) {
416415
process.stdout.write(stdout);
417416
process.stderr.write(stderr);
418417
}
419418
}
420419

421-
function sanitizeCommitMessage(message: string): string | undefined {
420+
function sanitizeCommitMessage(message?: string): string | undefined {
421+
if (!message) {
422+
return undefined;
423+
}
424+
422425
// Allow alphanumeric, space, common punctuation, newline characters.
423426
// Specifically check for characters that might escape quotes or introduce shell commands.
424427
// Newlines are allowed, but backslashes (other than for newlines), backticks, and dollar signs are still checked.

0 commit comments

Comments
 (0)