Skip to content

Fix the shadowing command bypass via alias for Import/Export-PSSession - #28217

Open
Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
masterfrom
pssession-gh
Open

Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
masterfrom
pssession-gh

Conversation

@adityapatwardhan

Copy link
Copy Markdown
Member

PR Summary

This pull request enhances the behavior and test coverage of implicit remoting in PowerShell, specifically focusing on how command aliases and server-side skip-lists are handled during Import-PSSession. The main code changes refine the logic to prevent bypassing server-side restrictions via aliases, and the tests are expanded to validate these scenarios, including cases with and without command name prefixes.

Key improvements to command import logic:

  • Updated the logic in AddRemoteCommandMetadata (in ImplicitRemotingCommands.cs) to:
    • Ensure the skip-list and allowed command checks are correctly applied to both the original command and its resolved alias, especially when no prefix is specified, preventing shadowing or bypassing server-side restrictions.

Enhanced test coverage for alias and skip-list scenarios:

  • Added a new test suite in Implicit.Remoting.Tests.ps1 to verify:
    • Aliases cannot be used to import commands that are in the server skip-list, even with -AllowClobber.
    • The skip-list check is bypassed for resolved aliases when a prefix is specified, allowing such commands to be imported under a new name.
    • Existing commands are not shadowed by imported commands unless explicitly allowed.
  • Modified an existing test to include the AllowClobber parameter, ensuring the test accurately reflects scenarios where command clobbering is permitted.

PR Context

PR Checklist

Copilot AI balanced review requested due to automatic review settings October 14, 2026 23:08
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 14, 2026

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.

🟢 Approval recommended

Static review found no blocking issues; the remaining regression-test suggestion is non-blocking, and tests were not executed.

1 open finding
What changed in this PR

This PR strengthens implicit remoting by applying import restrictions to alias targets.

Changes:

  • Validates resolved alias names and prevents unintended command shadowing.
  • Applies server skip-list checks to alias targets when no prefix is supplied.
  • Adds alias regression tests and updates an existing test to allow clobbering explicitly.
File Description
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​Implicit.Remoting.Tests.ps1 Tests alias restrictions and prefixed imports.
src/​Microsoft.PowerShell.Commands.Utility/​commands/​utility/​ImplicitRemotingCommands.cs Checks resolved alias targets before import.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

}

if (resolvedCommandName != null && !IsSafeNameOrIdentifier(commandMetadata.Name))
if (resolvedCommandName is not null && !IsSafeNameOrIdentifier(resolvedCommandName))
@iSazonov

Copy link
Copy Markdown
Collaborator

Duplicates #28208

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants