Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-updateallpackages-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@voltagent/core": patch
---

fix(core): add package name validation to updateAllPackages to prevent command injection
25 changes: 23 additions & 2 deletions packages/core/src/utils/update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,32 @@ export const updateAllPackages = async (
const packageManager = detectPackageManager(rootDir);

// 3. Prepare the package list for updating
const packagesToUpdate = updateCheckResult.updates
.filter((pkg) => pkg.type !== "latest")
const validPkgName = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;
const candidateUpdates = updateCheckResult.updates.filter((pkg) => pkg.type !== "latest");
const invalidNames = candidateUpdates
.map((pkg) => pkg.name)
.filter((name) => !validPkgName.test(name));
const packagesToUpdate = candidateUpdates
.filter((pkg) => validPkgName.test(pkg.name))
.map((pkg) => `${pkg.name}@latest`);

const logger = new LoggerProxy({ component: "update-checker" });

if (invalidNames.length > 0) {
// Surface filtered names so operators can investigate possible package.json
// tampering rather than just silently dropping them.
logger.warn("Skipping packages with invalid names (possible package.json tampering)", {
invalidNames,
});
}

if (packagesToUpdate.length === 0) {
return {
success: true,
message: "No packages to update after filtering invalid package names",
};
}

logger.info(`Updating ${packagesToUpdate.length} packages in ${rootDir}`);

// 4. Run the update command based on package manager
Expand Down
Loading