Harden against command/script injection#24
Merged
Merged
Conversation
Preview link: https://netcoretoolservice-pr-24.azurewebsites.net/api/new
|
Member
Author
|
Note: The vulnerable Microsoft.OpenAPI version can be ignored; it is a dev-only dependency that will auto-resolve once the next ASP.NET patch is released. |
TimHess
approved these changes
Jul 7, 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.
Harden NewController against argument injection (RCE)
An advisory identified two unauthenticated RCE paths in
NewController, both rooted in the same cause: user-supplied route and query values were interpolated directly into subprocess argument strings without input validation.UseShellExecute=falseprevents shell metacharacter injection but not argument injection.Attack 1 — subcommand injection via
{template}:GET /api/new/install%20<AttackerPkg>runsdotnet new install <AttackerPkg>, bypassing theEnableSensitiveEndpointsgate.Attack 2 — RCE via
--allow-scripts=yes(chained):After Attack 1 installs a template with a RunScript post-action,
GET /api/new/<shortname>?options=allow-scripts=yesexecutes that post-action as the service account.Changes
src/NetCoreToolService/Controllers/NewController.csTemplateShortNameRegex([GeneratedRegex]):^\.?[a-zA-Z0-9][a-zA-Z0-9\-_\.]*$Allows all built-in
dotnet new listshort names (including.gitattributes,global.json,steeltoe-webapi). Blocks spaces, leading dashes, path separators, and all other injection characters. Called inGetTemplateProjectandGetTemplateHelpbefore any subprocess call.NuGetPackageIdRegex([GeneratedRegex]):^[A-Za-z0-9_][A-Za-z0-9\.\-]*$Follows the official NuGet naming rules (first char: letter/digit/underscore; subsequent chars: letters/digits/dots/dashes only). Called in
InstallTemplatesandUninstallTemplatesafter theEnableSensitiveEndpointsgate.BlockedOptionNames(HashSet<string>,OrdinalIgnoreCase):allow-scripts,add-source,force,dry-run,no-update-check,interactive,project.IsValidOptionNameadditionally enforces^[a-zA-Z][a-zA-Z0-9\-]*$on every option key. Both checks are applied inParseOptionsto the key=value branch and the switch branch before any option is appended to the command line.GetTemplateProjectreturns 400 whenParseOptionssetsinvalidOptionName.test/NetCoreToolService.Test/Controllers/NewControllerTest.csNew
[Theory]tests covering each injection vector:GetTemplateProject_InjectedTemplateName_Should_Return_BadRequestGetTemplateHelp_InjectedTemplateName_Should_Return_BadRequestGetTemplateProject_BlockedOrInvalidOption_Should_Return_BadRequestInstallTemplates_InvalidNuGetId_Should_Return_BadRequestUninstallTemplates_InvalidNuGetId_Should_Return_BadRequest