-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(update): validate package names in updateAllPackages #1357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,12 @@ export type PackageUpdateInfo = { | |
| */ | ||
| type PackageManager = "npm" | "pnpm" | "yarn" | "bun"; | ||
|
|
||
| const NPM_PACKAGE_NAME_REGEX = | ||
| /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/; | ||
|
|
||
| const isValidPackageName = (packageName: string): boolean => | ||
| NPM_PACKAGE_NAME_REGEX.test(packageName); | ||
|
|
||
| /** | ||
| * Detects the package manager being used in the project | ||
| */ | ||
|
|
@@ -334,8 +340,16 @@ export const updateAllPackages = async ( | |
| // 3. Prepare the package list for updating | ||
| const packagesToUpdate = updateCheckResult.updates | ||
| .filter((pkg) => pkg.type !== "latest") | ||
| .filter((pkg) => isValidPackageName(pkg.name)) | ||
| .map((pkg) => `${pkg.name}@latest`); | ||
|
|
||
| if (packagesToUpdate.length === 0) { | ||
| return { | ||
| success: false, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This new Prompt for AI agents |
||
| message: "No valid packages available for updating", | ||
| }; | ||
|
Comment on lines
+346
to
+350
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Line 346 introduces a new 🧰 Tools🪛 ast-grep (0.44.0)[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec. (detect-child-process-typescript) 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| const logger = new LoggerProxy({ component: "update-checker" }); | ||
| logger.info(`Updating ${packagesToUpdate.length} packages in ${rootDir}`); | ||
|
|
||
|
|
@@ -410,10 +424,8 @@ export const updateSinglePackage = async ( | |
| } | ||
|
|
||
| // Command injection protection - only allow valid NPM package names | ||
| const isValidPackageName = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test( | ||
| packageName, | ||
| ); | ||
| if (!isValidPackageName) { | ||
| const isPackageNameValid = isValidPackageName(packageName); | ||
| if (!isPackageNameValid) { | ||
| return { | ||
| success: false, | ||
| message: `Invalid package name: ${packageName}`, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: Package name regex allows leading dashes, permitting argument injection
Prompt for AI agents