Skip to content

Skip signed PowerShell profiles instead of breaking them (fixes #161) - #171

Open
Lili离 (Uarz) wants to merge 1 commit into
microsoft:mainfrom
Uarz:fix/signed-powershell-profile-161
Open

Skip signed PowerShell profiles instead of breaking them (fixes #161)#171
Lili离 (Uarz) wants to merge 1 commit into
microsoft:mainfrom
Uarz:fix/signed-powershell-profile-161

Conversation

@Uarz

Copy link
Copy Markdown

Summary

Fixes #161.

When coreutils installs/refreshes, it injects a managed section into the user's PowerShell profile (src/pwsh-install.ps1Update-PowerShellProfile). If that profile is Authenticode-signed (e.g. the user runs under an AllSigned/RemoteSigned-with-signing setup), rewriting the file invalidates the signature, so PowerShell refuses to load the profile and the user's shell breaks.

As discussed in #161 (with Leonard Hecker (@lhecker)), the safe fix is to detect signed profiles and abort the injection rather than silently corrupt them.

Change

In Update-PowerShellProfile, before any read/strip/write, check the existing profile with Get-AuthenticodeSignature. If a signature is present (Status -ne 'NotSigned'), skip the file and emit a Write-Warning explaining why coreutils commands won't be available in that profile.

This applies uniformly to install / refresh / uninstall, so we never touch (and therefore never break) a signed profile. Untrusted / hash-mismatched signatures are also skipped, since modifying them only makes things worse; the user can re-sign manually after removing the section.

Validation

  • pwsh -NoProfile parse check of the edited script: 0 syntax errors.
  • Unsigned profile (Get-AuthenticodeSignatureNotSigned): not skipped (normal install/refresh proceeds) — regression guard passes.
  • Real signed profile (self-signed CodeSigningCert, signed via Set-AuthenticodeSignatureStatus = UnknownError, i.e. != NotSigned): skipped with the warning, signature preserved.

Behavior is unchanged for the overwhelming common case (unsigned profiles); only signed profiles are now protected.

Installing coreutils injects a managed section into the user's
PowerShell profile. If that profile is Authenticode-signed (e.g. under
an AllSigned execution policy), rewriting the file invalidates the
signature and the profile no longer loads, breaking the user's shell.

Detect signed profiles with Get-AuthenticodeSignature before writing:
when a signature is present (Status != NotSigned), skip the injection
for that profile and emit a warning instead of silently corrupting it.

Fixes microsoft#161
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.

Default install breaks signed powershell profiles

1 participant