Skip to content

Harden credential & secret handling (v1.121.10)#78

Merged
TheAbider merged 2 commits into
masterfrom
fix/credential-secret-hardening
Jul 1, 2026
Merged

Harden credential & secret handling (v1.121.10)#78
TheAbider merged 2 commits into
masterfrom
fix/credential-secret-hardening

Conversation

@TheAbider

Copy link
Copy Markdown
Owner

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)

  • Generated password no longer leaks to the transcript (HIGH). New-StrongPassword deliberately 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-level Out-Default, re-echoing it to the console and into the just-resumed on-disk transcript. It no longer returns the plaintext.
  • Clipboard auto-clear reliably runs (LOW). The 60s clear Timer was created with no rooted reference ($null = New-Object …Timer); an unreferenced System.Threading.Timer is 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)

  • CF-Access-Client-Secret entered hidden (LOW). It was collected with a plain Read-Host that echoes the secret to the console (→ transcript). Now Read-Host -AsSecureString, marshalled to the plaintext the header needs with the BSTR zero-freed in a finally. (The client Id is not a secret and is unchanged.)

Verified clean (no changes)

  • The generator already uses RNGCryptoServiceProvider (no entropy weakness).
  • The RADIUS (netsh), Azure Arc (azcmagent), and SIEM (agent config) secrets flagged by the finders were refuted — those tools require the secret in that form, and it's handled as safely as they allow.

Verification

  • New Section 197 (7 asserts). Full suite 5315/5315; PSSA 0 (project settings). Monolithic rebuilt, parse check passed. Version stamps → 1.121.10.

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

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

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.
@TheAbider TheAbider merged commit ffb09d9 into master Jul 1, 2026
6 checks passed
@TheAbider TheAbider deleted the fix/credential-secret-hardening branch July 1, 2026 13:28
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.

1 participant