Harden credential & secret handling (v1.121.10)#78
Merged
Conversation
Fixes from an adversarial audit of password generation, SecureString hygiene, and secret-leak sinks. 22-Password.ps1: - New-StrongPassword no longer returns the generated plaintext. The sole caller used it as a bare statement, streaming the password to top-level Out-Default, which re-echoed it to the console AND into the just-resumed on-disk transcript -- defeating the Stop-Transcript display mitigation the function performs. It's shown once via [Console]::WriteLine and never leaves the function. - Keep the clipboard auto-clear Timer rooted (script scope). An unreferenced System.Threading.Timer is GC-eligible immediately and its finalizer cancels the pending callback, so the advertised 60s clipboard clear could silently never run, leaving the plaintext in the clipboard / Win+V history. 56-OperationsMenu.ps1: - Collect the FileServer CF-Access-Client-Secret with Read-Host -AsSecureString and marshal it with a zero-freed BSTR, instead of a plain Read-Host that echoes the secret to the console (and thus the transcript). Audit also confirmed the generator already uses RNGCryptoServiceProvider, and that the RADIUS/VPN/SIEM/Azure-Arc secrets required in plaintext by their native tools (netsh, azcmagent, agent config) are handled as safely as those tools permit. Tests: Section 197 (7 asserts); 5315/5315 passing. PSSA 0. Monolithic + version stamps -> 1.121.10.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The initial fix removed New-StrongPassword's plaintext return outright, which broke the Password.Tests.ps1 Pester tests that capture the value to verify length/complexity/ uniqueness. Gate the return behind an explicit -PassThru switch instead: the interactive menu action calls it WITHOUT -PassThru (so the password still never streams to Out-Default / the transcript), while tests and programmatic callers opt in and handle the value. - 22-Password.ps1: add [switch]$PassThru; return the plaintext only when set. - Password.Tests.ps1: pass -PassThru at the call sites that assert on the value. - Run-Tests.ps1 Section 197: assert the return is -PassThru-guarded and the menu caller does not opt in. Structural 5317/5317; full Pester 312/312; monolithic re-synced.
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.
Fixes from an adversarial audit of credential & secret handling (password generation, SecureString hygiene, secret-leak sinks, shared secrets). Verified findings only.
Password generator (
22-Password.ps1)New-StrongPassworddeliberately pauses transcription to display the password off-log via[Console]::WriteLine, then resumes it — but it also returned the plaintext. The sole caller uses it as a bare statement, so the value streamed to top-levelOut-Default, re-echoing it to the console and into the just-resumed on-disk transcript. It no longer returns the plaintext.Timerwas created with no rooted reference ($null = New-Object …Timer); an unreferencedSystem.Threading.Timeris GC-eligible immediately and its finalizer cancels the callback, so the clear could silently never fire (leaving the password in the clipboard / Win+V history). It's now held in a script-scope field (prior timer disposed on regen).Settings editor (
56-OperationsMenu.ps1)Read-Hostthat echoes the secret to the console (→ transcript). NowRead-Host -AsSecureString, marshalled to the plaintext the header needs with the BSTR zero-freed in afinally. (The client Id is not a secret and is unchanged.)Verified clean (no changes)
RNGCryptoServiceProvider(no entropy weakness).Verification