Sanitize package.json and prevent command injection in ABP CLI#25210
Merged
Sanitize package.json and prevent command injection in ABP CLI#25210
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens ABP CLI’s Node package operations by adding --ignore-scripts to npm/yarn install/add commands, reducing the risk of executing malicious lifecycle scripts from package.json (fixes #25209).
Changes:
- Add
--ignore-scriptstonpm installandyarnexecution inNpmHelper. - Add
--ignore-scriptstonpx yarn addcalls used when modifying projects. - Add
--ignore-scriptsto install flows inNpmPackagesUpdater.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Utils/NpmHelper.cs | Adds --ignore-scripts to npm/yarn helper commands. |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNpmPackageAdder.cs | Adds --ignore-scripts to yarn add when adding packages to projects. |
| framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater.cs | Adds --ignore-scripts to yarn/npm installs during update workflows. |
--ignore-scripts flag to npm/yarn commands in ABP CLI…l, and add version tests
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNpmPackageAdder.cs:82
versionPostfixusesversion != null, so an empty/whitespaceversion(which currently passesEnsureSafeVersion) becomes "@"/"@ ", producing an invalidyarn addcommand. Normalizeversion(trim + null if empty) or build the postfix with!string.IsNullOrWhiteSpace(version)so optional/empty versions behave correctly.
if (!File.ReadAllText(packageJsonFilePath).Contains($"\"{npmPackage.Name}\""))
{
var versionPostfix = version != null ? $"@{version}" : string.Empty;
ebicoglu
approved these changes
Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--ignore-scriptsflag to all npm/yarn install and add commands to prevent execution of potentially malicious lifecycle scripts frompackage.json.@scope/package-namepattern) before passing them to shell commands, preventing OS command injection via crafted dependency names (e.g.@abp/core && calc.exe).Fixes #25209