Skip to content

fix: resolve cmd.exe quoting and stdin issues in Invoke-MaskedProcess#110

Merged
petehauge merged 1 commit into
mainfrom
fix/logmasking-cmdexe-quoting
Jun 5, 2026
Merged

fix: resolve cmd.exe quoting and stdin issues in Invoke-MaskedProcess#110
petehauge merged 1 commit into
mainfrom
fix/logmasking-cmdexe-quoting

Conversation

@petehauge
Copy link
Copy Markdown
Collaborator

Summary

Fixes two Windows-specific bugs in Invoke-MaskedProcess (LogMasking.psm1) that caused integration test failures when the deploy scripts run az commands inside Start-Job.

Changes

1. Stdin redirect hang fix

RedirectStandardInput was $false, so child processes spawned inside Start-Job (which has no parent console) inherited a broken stdin handle. Python (the az CLI runtime) hung on startup waiting for stdin initialization.

Fix: Set RedirectStandardInput = $true and close stdin immediately after Start().

2. cmd.exe /c argument quoting fix

ArgumentList individually quotes each argument using C-runtime conventions, but cmd.exe /c has its own incompatible quoting rules:

  • Paths with spaces (C:\Program Files\...) broke because cmd.exe stripped individual quotes and split at the space → 'C:\Program' is not recognized
  • Metacharacters like parentheses in JMESPath queries (e.g., length(value[?name=='...'])) were interpreted as cmd.exe grouping operators → --output was unexpected at this time.

Fix: For the cmd.exe /c case, use the Arguments string property instead of ArgumentList, with each argument individually quoted inside an outer /c "..." wrapper. This ensures cmd.exe passes all content through as literals.

Testing

  • Verified az account show works inside Start-Job (previously hung indefinitely)
  • Verified arguments with spaces and parentheses pass through correctly
  • Full roundtrip integration test passes through publish phase

When Invoke-MaskedProcess runs inside Start-Job (a separate process),
two issues caused failures on Windows:

1. RedirectStandardInput was false, so child processes inherited a
   broken stdin handle from the job's consoleless process, causing
   Python (az CLI) to hang on startup. Fixed by redirecting stdin
   and closing it immediately.

2. ArgumentList individually quotes each argument, but cmd.exe /c
   has its own quoting rules that conflict. Paths with spaces
   (C:\Program Files\...) broke, and metacharacters like parentheses
   in JMESPath queries were interpreted as cmd.exe grouping operators.
   Fixed by using the Arguments string property with proper quoting
   for the cmd.exe /c case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread tests/integration/all-resource-types/modules/LogMasking.psm1
@petehauge petehauge merged commit 628c7b7 into main Jun 5, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants