-
Notifications
You must be signed in to change notification settings - Fork 739
Fix CLI crash when user input contains Spectre markup characters #12919
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
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12919Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12919" |
a9763f8 to
7b423f4
Compare
…aracters Co-authored-by: mitchdenny <[email protected]>
7b423f4 to
8dc8506
Compare
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.
Pull Request Overview
This PR fixes a security vulnerability where user input containing Spectre Console markup characters ([, ]) could crash the CLI when rendered in prompts and success messages. The fix applies .EscapeMarkup() to user-provided values before they are displayed as default values in prompts or included in formatted messages.
Key Changes
- Added markup escaping for all user-provided default values in prompts across the CLI
- Added markup escaping for paths in success messages
- Included comprehensive test coverage validating the fix
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/Aspire.Cli/Commands/NewCommand.cs |
Escapes project name and output path default values in prompts to prevent markup parsing crashes |
src/Aspire.Cli/Templating/DotNetTemplateFactory.cs |
Escapes output path in success message and adds required using Spectre.Console |
src/Aspire.Cli/Commands/PipelineCommandBase.cs |
Escapes all input.Value references used as default values across 6 prompt call sites for publish/deploy operations |
src/Aspire.Cli/Projects/ProjectUpdater.cs |
Escapes directory path in NuGet config prompt default value |
tests/Aspire.Cli.Tests/Commands/NewCommandTests.cs |
Adds test validating that project names with markup characters don't crash the CLI |
| }; | ||
|
|
||
| // Capture what default value is passed for the output path | ||
| // The path passed to this callback is the unescaped version |
Copilot
AI
Nov 18, 2025
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.
The comment states "The path parameter passed to the callback contains the unescaped markup characters", but this is misleading. The PromptForOutputPath method receives the unescaped path, escapes it internally, and then passes the escaped version to the interaction service. The callback captures the unescaped path because it's called with the original parameter before escaping happens inside the implementation.
| // The path passed to this callback is the unescaped version | |
| // The path parameter passed to this callback is the unescaped version; | |
| // escaping is handled internally by PromptForOutputPath before passing the value to the interaction service. |
| Assert.Equal(0, exitCode); | ||
|
|
||
| // Verify that the default output path was derived from the project name with markup characters | ||
| // The path parameter passed to the callback contains the unescaped markup characters |
Copilot
AI
Nov 18, 2025
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.
The comment states "The path parameter passed to the callback contains the unescaped markup characters", but this is misleading. The comment should clarify that the callback receives the original unescaped path parameter, which is then escaped internally before being displayed as a default value in the prompt.
| // The path parameter passed to the callback contains the unescaped markup characters | |
| // The callback receives the original unescaped path parameter; escaping is performed internally before displaying as the default value in the prompt. |
Description
The CLI crashes when user input contains Spectre Console markup characters (e.g.,
[,]). This occurs when these characters appear in project names, paths, or other prompts and are passed unescaped to Spectre.Console's markup renderer.Changes
Escape user input before rendering
NewCommand.cs: Escape project name and output path in prompt defaultsDotNetTemplateFactory.cs: Escape output path in success messagesPipelineCommandBase.cs: Escape allinput.Valuein publish/deploy prompts (6 call sites)ProjectUpdater.cs: Escape directory path in NuGet config promptsTest coverage
NewCommandEscapesMarkupInProjectNameAndOutputPathtest validating prompts handle markup characters without crashingAll escaping uses Spectre.Console's
EscapeMarkup()extension method, which converts[→[[and]→]].Fixes #(issue to be linked)
Checklist
<remarks />and<code />elements on your triple slash comments?doc-ideatemplatebreaking-changetemplatediagnostictemplateOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.