Skip to content

Redact connection credentials from persisted command history - #291

Merged
Mike Krüger (mkrueger) merged 8 commits into
mainfrom
dev/mkrueger/fix/redact-history-secrets
Nov 5, 2026
Merged

Mike Krüger (mkrueger) merged 8 commits into
mainfrom
dev/mkrueger/fix/redact-history-secrets

Conversation

@mkrueger

Copy link
Copy Markdown
Collaborator

Summary

Prevent recognized connection credentials from being written to command history while preserving the command being executed.

  • Replace AccountKey, SharedAccessKey, ResourceToken, and recognized bearer/JWT/SAS signature values with [REDACTED] in history.
  • Mask existing entries on load and clean legacy on-disk entries during the next successful atomic history save, including merges from other writers.
  • Decode shell string literals when filtering escaped credential names and values so Unicode escapes and escaped quotes cannot expose keys.
  • Keep history filtering separate from broad diagnostic filtering so ordinary query predicates on fields such as token, password, and secret remain unchanged.
  • Cover encoded multiline history, deduplication, concurrent writers, failed-save retries, escaped credentials, and unchanged execution values.
  • Update history and MCP documentation. Changelog left unchanged.

User-visible behavior and limitations

Recalled key-based connections require a fresh key or Entra ID authentication. Existing backups and copies are not cleaned. Command echoes and output are not masked by history filtering, and arbitrary secrets under unrelated names may not be recognized.

Validation

  • App and test builds passed with zero warnings and errors.
  • Full offline regression suite: 5,104 passed, 6 skipped.
  • git diff --check passed.
Mask new and legacy history while preserving execution values and ordinary query predicates. Handle escaped credentials using decoded shell string literals.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

Credential redaction still allows complete secrets into persisted history through doubled-apostrophe strings and escaped object-property names, while token rewriting can also alter or invalidate recalled commands.

4 open issues
What changed in this PR

This PR adds credential filtering to Cosmos DB shell history while preserving the commands being executed. It also masks legacy entries when loaded and rewrites them during successful history saves.

Changes:

  • Add shared redaction logic with separate history and diagnostic filtering.
  • Cover history persistence, concurrent writers, save retries, escaped credentials, and unchanged execution values.
  • Document masked history, replay requirements, and security limitations.
File Description
README.md Summarizes history masking and replay limitations.
docs/​navigation.md Explains credential filtering, legacy cleanup, and history security.
docs/​mcp.md Clarifies history masking versus visible command echoes.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​ShellInterpreter.cs Applies filtering when recording and loading history.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​SecretRedactor.cs Introduces shared credential-redaction logic.
CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​DiagnosticLog.cs Delegates diagnostic filtering to the shared redactor.
CosmosDBShell.Tests/​Runtime/​SerializedExecutionTests.cs Adds history persistence and execution-preservation tests.
CosmosDBShell.Tests/​Runtime/​SecretRedactorTests.cs Tests credential masking, escaped literals, and unchanged ordinary commands.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: C#

C# / code-coverage/dotnet

main f6b1dd6 dev/mkrueger/fix/red... cbb6f12 +/-
74% 74% 0%
View coverage of the 6 most impacted files.
File main f6b1dd6 dev/mkrueger/fix/red... cbb6f12 +/-
D:\a\CosmosDBSh...iagnosticLog.cs 89% 88% -1%
D:\a\CosmosDBSh...orExpression.cs 87% 87% 0%
D:\a\CosmosDBSh...lInterpreter.cs 80% 80% 0%
D:\a\CosmosDBSh...onExpression.cs 73% 75% +2%
D:\a\CosmosDBSh...nsExpression.cs 87% 100% +13%
D:\a\CosmosDBSh...cretRedactor.cs 0% 99% +99%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 05, 2026 12:21 UTC

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

Critical redaction gaps expose plaintext credentials in saved history through multiline properties, interpolated expressions, and recognized credential variable assignments.

3 open issues
4 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Critical redaction gaps leave interpolated bearer tokens and parenthesized credential assignments exposed in saved history, and the assignment fallback also corrupts recalled syntax.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

High severity Redact grouped credential values without breaking assignments

CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​SecretRedactor.cs:59

For the valid assignment $AccountKey = ('example-key=='), the preceding ( prevents the string from being recognized as a credential value, leaving the complete key in saved history. The raw fallback masks only the opening parenthesis, also making the recalled assignment malformed. Track and redact complete value expressions for recognized credential assignments and properties, including grouped literals, and add a saved-history regression for this case.

High severity Mask interpolated bearer credentials completely

CosmosDBShell/​Azure.Data.Cosmos.Shell.Core/​SecretRedactor.cs:124

echo $"Bearer $('example-token')" is saved unchanged because the bearer pattern rejects $ at the start of the value; a literal prefix before the interpolation is masked only partially. Recognize bearer values with interpolation and mask the complete credential expression while preserving non-secret text. Add regression cases for both expression-only and mixed literal/interpolated values.

3 resolved since last review

Review effort: Balanced

…#291

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

A critical redaction flaw leaves complete credential values exposed in saved history when grouped credential properties appear inside interpolation expressions.

1 open issue
3 resolved since last review

Review effort: Balanced

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

Critical redaction gaps in interpolated string literals and compound assignments allow complete credential keys to remain in persisted history.

2 open issues
1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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.

🔵 Needs a closer look

Human assessment is needed because valid assignment and property syntax can bypass credential redaction and leave secret keys in persisted history.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 5, 2026 12:18

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.

🔵 Needs a closer look

Human assessment is needed because critical redaction gaps in valid shell and object assignments can leave complete credential keys on disk.

No open issues 🎉

Review effort: Balanced

@mkrueger
Mike Krüger (mkrueger) merged commit 0fba460 into main Nov 5, 2026
13 checks passed
@mkrueger
Mike Krüger (mkrueger) deleted the dev/mkrueger/fix/redact-history-secrets branch November 5, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants