Skip to content

Apply implicit-remoting command protections to resolved aliases - #28208

Merged
Justin Chung (jshigetomi) merged 2 commits into
masterfrom
175
Oct 16, 2026
Merged

Justin Chung (jshigetomi) merged 2 commits into
masterfrom
175

Conversation

@jshigetomi

Copy link
Copy Markdown
Collaborator

PR Summary

This pull request improves the handling of command aliases and skip-list checks during implicit remoting in PowerShell, ensuring that commands on the server's skip-list cannot be imported via aliases unless explicitly allowed. It also adds new tests to cover these scenarios.

PR Context

PR Checklist

@jshigetomi Justin Chung (jshigetomi) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 14, 2026
@azure-pipelines

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

@jshigetomi Justin Chung (jshigetomi) changed the title Fix the shadowing command bypass via alias for Import/Export-PSSession Apply implicit-remoting command restrictions to resolved aliases Oct 14, 2026
@jshigetomi
Justin Chung (jshigetomi) marked this pull request as ready for review October 14, 2026 21:44
@jshigetomi
Justin Chung (jshigetomi) requested a review from a team as a code owner October 14, 2026 21:44
Copilot AI balanced review requested due to automatic review settings October 14, 2026 21:44

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.

🟡 Changes recommended

The corrected resolved-name safety check needs a regression test for an alias targeting an unsafe command name.

1 open finding
What changed in this PR

This PR applies implicit-remoting import safeguards to alias targets, preventing aliases from bypassing command restrictions.

Changes:

  • Validates resolved command names for safety.
  • Applies server skip-list and local clobber checks to alias targets.
  • Adds tests for restrictions and prefix-based imports.
File Description
test/​powershell/​Modules/​Microsoft.PowerShell.Utility/​Implicit.Remoting.Tests.ps1 Adds alias restriction tests and updates clobber handling.
src/​Microsoft.PowerShell.Commands.Utility/​commands/​utility/​ImplicitRemotingCommands.cs Applies import safeguards to resolved alias targets.

🧠 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))
}

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the change IsSafeNameOrIdentifier was used only once and it threw if null or empty.
Now we always check for not null so we could do the check in IsSafeNameOrIdentifier.

Also here we don't check for empty but do the check below.

Should we move both checks to IsSafeNameOrIdentifier?

@jshigetomi Justin Chung (jshigetomi) changed the title Apply implicit-remoting command restrictions to resolved aliases Apply implicit-remoting command protections to resolved aliases Oct 16, 2026
@jshigetomi
Justin Chung (jshigetomi) merged commit fbb4fd5 into master Oct 16, 2026
37 of 38 checks passed
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