Skip to content

Fix malformed secrets diagnostics and side-effect-free path lookup - #21323

Merged
David Pine (IEvangelist) merged 3 commits into
mainfrom
ievangelist-aspire-secrets-escaping-fix
Nov 4, 2026
Merged

David Pine (IEvangelist) merged 3 commits into
mainfrom
ievangelist-aspire-secrets-escaping-fix

Conversation

@IEvangelist

Copy link
Copy Markdown
Member

Description

Malformed secrets JSON currently blocks every aspire secret operation, including secret path, with an unexpected-error message. Users cannot even locate the environment store to repair it.

This change:

  • Makes secret path resolve the environment-specific location without parsing, importing, migrating, or initializing secrets. Existing environment filename casing is retained.
  • Reports invalid JSON with the affected file path, one-based line/byte position, and repair guidance. This covers environment stores, legacy user-secrets imports, and synthetic-ID migration sources/destinations.
  • Preserves malformed content and exits nonzero for data operations; it does not auto-escape, discard, or overwrite malformed secrets.
  • Adds focused regression coverage for Development/Production stores, legacy and synthetic stores, side-effect-free path lookup, empty stdout on failures, and valid backslash round trips. Updates output-contract documentation and regenerates localized resources.

Reproduction caveat: On Windows x64 with .NET SDK 10.0.403, both CLI 13.4.0+3f0998a95833d5fef96b3159d56b667889b71166 and latest stable 13.6.4+c89352703f78ae46de90fbf751ed8b52b77b89bf accept correctly escaped JSON containing server\\sql. All five commands reproduce the reported error only when the synthetic JSON contains the invalid escape server\sql. Both Aspire and dotnet user-secrets writers correctly escape and round-trip the value. This does not establish how the reporter's file reached its failing state, and this PR does not claim to fix valid-backslash corruption.

All reproduction used synthetic values and isolated stores. No application was started and no real secrets were read or changed. No new dependencies.

Fixes #21322

User-facing usage

aspire secret path --apphost .\AppHost.csproj --environment Production --non-interactive --nologo
aspire secret get ConnectionStrings:db --apphost .\AppHost.csproj --environment Production --non-interactive --nologo

Path lookup still succeeds if secrets are malformed. Data operations instead report a diagnostic like:

Secrets file '<secrets-file>' contains invalid JSON (line 1, byte position 46). Fix the JSON in this file and try again. In JSON strings, escape a backslash as '\\' (for example, 'server\\sql').

The diagnostic names the actual invalid file, including a legacy import or migration source when that is the failing file. secret path continues to print the canonical Aspire environment-store location, not the legacy import source.

Validation

  • .\restore.cmd — passed; installed repository-pinned SDK 11.0.100-rc.2.26504.105.
  • New regression tests against the unchanged implementation initially demonstrated the blocked path lookup and generic invalid-JSON failure.
  • Focused validation below — passed: 161, failed: 0, skipped: 3. The three skipped cases require Unix permissions and are inapplicable on Windows.
$env:MSBUILDTERMINALLOGGER='false'
dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class '*.SecretCommandTests' --filter-class '*.SecretStoreResolverTests' --filter-class '*.SecretsStoreTests' --filter-class '*.BaseCommandTests' --filter-not-trait 'quarantined=true' --filter-not-trait 'outerloop=true'
  • dotnet build src\Aspire.Cli\Aspire.Cli.csproj /t:UpdateXlf --no-restore -v:quiet — passed, 0 warnings/errors.
  • Built-CLI smoke check using dotnet exec-equivalent invocation of artifacts\bin\Aspire.Cli\Debug\net11.0\aspire.dll, with isolated malformed legacy secrets — passed: secret path exits 0 without importing; secret get exits 1 with actionable diagnostics on stderr, empty stdout, unchanged malformed content, and no canonical-store creation.
  • git diff --check — passed.
  • Full repository suite and non-Windows execution were not run.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Report invalid JSON with the secrets file location and repair guidance without changing its contents. Resolve environment secret paths without loading or migrating stores.

Fixes #21322

Co-authored-by: Copilot App <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21323

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21323"

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Secret deletion still bypasses the actionable diagnostic when malformed legacy JSON coexists with a valid canonical Development store.

1 open issue
1 file not reviewed
  • src/Aspire.Cli/Resources/SecretCommandStrings.Designer.cs: Generated file
What changed in this PR

This PR addresses #21322 by separating CLI secrets-path lookup from data loading and adding actionable diagnostics for malformed secrets JSON.

Changes:

  • Resolves secret path without loading, importing, migrating, or initializing secrets.
  • Adds file-specific JSON diagnostics with repair guidance and localization resources.
  • Adds regression coverage for malformed stores, side-effect-free lookup, and correctly escaped backslashes; documents the output contract.
File Description
tests/​Aspire.Cli.Tests/​Commands/​SecretCommandTests.cs Tests diagnostics, path lookup, and backslash round trips.
src/​Aspire.Cli/​Secrets/​InvalidSecretsFileException.cs Formats file-specific JSON errors.
src/​Aspire.Cli/​Secrets/​AspireSecretsStoreResolver.cs Separates path lookup and wraps parsing failures.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.zh-Hant.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.zh-Hans.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.tr.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.ru.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.pt-BR.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.pl.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.ko.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.ja.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.it.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.fr.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.es.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.de.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​xlf/​SecretCommandStrings.cs.xlf Adds diagnostic translation entry.
src/​Aspire.Cli/​Resources/​SecretCommandStrings.resx Defines diagnostic text and translator guidance.
src/​Aspire.Cli/​Resources/​SecretCommandStrings.Designer.cs Exposes the diagnostic resource.
src/​Aspire.Cli/​Commands/​SecretPathCommand.cs Uses path-only resolution.
src/​Aspire.Cli/​Commands/​BaseCommand.cs Handles invalid-secrets errors as command failures.
docs/​specs/​cli-output-formats.md Documents path lookup and malformed-JSON behavior.

Review effort: Balanced

@IEvangelist
David Pine (IEvangelist) enabled auto-merge (squash) October 26, 2026 19:37
Cover a valid canonical store coexisting with malformed legacy secrets and verify failed deletion preserves both files.

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrowly scoped changes have focused regression coverage, address the prior deletion-path feedback, and leave no unresolved blocking findings.

No open issues 🎉

1 resolved since last review
1 file not reviewed
  • src/Aspire.Cli/Resources/SecretCommandStrings.Designer.cs: Generated file

Review effort: Balanced

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

3 / 100 PR test projects · 4 PR jobs, from 21 changed files.

Selected PR test projects (3 / 100)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Infrastructure.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

📦 affected project Aspire.Cli
→ 1 test: Aspire.Cli.EndToEnd.Tests

🔧 src/Aspire.Cli/Resources/SecretCommandStrings.resx (changed source)
→ 1 directly: Infrastructure.Tests

🧪 tests/Aspire.Cli.Tests/Commands/SecretCommandTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Cli
extension-e2e • src/Aspire.Cli/Commands/BaseCommand.cs, src/Aspire.Cli/Commands/SecretDeleteCommand.cs, src/Aspire.Cli/Commands/SecretPathCommand.cs, src/Aspire.Cli/Resources/SecretCommandStrings.Designer.cs, src/Aspire.Cli/Resources/SecretCommandStrings.resx, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.cs.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.de.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.es.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.fr.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.it.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.ja.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.ko.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.pl.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.pt-BR.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.ru.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.tr.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.zh-Hans.xlf, src/Aspire.Cli/Resources/xlf/SecretCommandStrings.zh-Hant.xlf, src/Aspire.Cli/Secrets/AspireSecretsStoreResolver.cs, src/Aspire.Cli/Secrets/InvalidSecretsFileException.cs
• affected project Aspire.Cli
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli

Selection computed for commit d0930ef.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain to block approval.

No open issues 🎉

1 file not reviewed
  • src/Aspire.Cli/Resources/SecretCommandStrings.Designer.cs: Generated file

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@IEvangelist
David Pine (IEvangelist) merged commit 5e1904a into main Nov 4, 2026
412 of 416 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Nov 4, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #2051

Generated by PR Documentation Check · copilot · auto · 25 AIC · ⌖ 1.17 AIC · ⊞ 7.4K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#2051 targeting release/17.0.

Documented side-effect-free aspire secret path and invalid-JSON diagnostics for secrets files. Signals: cli_command_file_changed (SecretPathCommand.cs), cli_resource_strings_changed (SecretCommandStrings.resx), pr_body_has_cli_flag_mention, pr_body_has_user_facing_section. Files: aspire-secret-path.mdx, aspire-secret.mdx.

Note

This draft PR needs human review before merging.

Mitch Denny (mitchdenny) added a commit to microsoft/aspire.dev that referenced this pull request Nov 17, 2026
…cret path (#2051)

Documents changes from microsoft/aspire#21323

Author: ``@IEvangelist`` is the workflow actor; source PR author per the
PR metadata.

Targeting `release/17.0` based on the source PR milestone `17.0` (exact
match).

## Why
The source PR makes `aspire secret path` resolve the
environment-specific store without parsing/importing/migrating secrets,
and reports invalid JSON with file path, line/byte position, and repair
guidance. Triggered signals: `cli_command_file_changed`
(SecretPathCommand.cs), `cli_resource_strings_changed`
(SecretCommandStrings.resx), `pr_body_has_cli_flag_mention`,
`pr_body_has_user_facing_section`.

## Changes (updated pages)
- `reference/cli/commands/aspire-secret-path.mdx`: notes that the
command has no side effects and works with malformed secrets.
- `reference/cli/commands/aspire-secret.mdx`: new "Malformed secrets
files" section.

> Generated by [PR Documentation
Check](https://github.com/microsoft/aspire/actions/runs/41870873850) for
#21323 · copilot · auto · 25 AIC · ⌖ 1.17 AIC · ⊞ 7.4K ·
[◷](https://github.com/search?q=repo%3Amicrosoft%2Faspire.dev+%22gh-aw-workflow-id%3A+pr-docs-check%22&type=pullrequests)

<!-- gh-aw-agentic-workflow: PR Documentation Check, engine: copilot,
model: auto, id: 41870873850, workflow_id: pr-docs-check, run:
https://github.com/microsoft/aspire/actions/runs/41870873850 -->

<!-- gh-aw-workflow-id: pr-docs-check -->
<!-- gh-aw-workflow-call-id: microsoft/aspire/pr-docs-check -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: aspire secrets crashes on every operation when one of the already set secrets contains an escape character

3 participants