Skip to content

Validate remote module names before Import-Module - #28401

Open
Justin Chung (jshigetomi) wants to merge 2 commits into
PowerShell:masterfrom
jshigetomi:242bp
Open

Justin Chung (jshigetomi) wants to merge 2 commits into
PowerShell:masterfrom
jshigetomi:242bp

Conversation

@jshigetomi

@jshigetomi Justin Chung (jshigetomi) commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

PR Summary

PR Context

PR Checklist

  • PR has a meaningful title
  • Summarized changes
  • Existing files retain their copyright headers
  • This PR is ready to merge
  • Breaking changes
    • None
  • User-facing changes
    • Not Applicable
  • Testing - New and feature
    • N/A or can only be tested interactively

@jshigetomi
Justin Chung (jshigetomi) requested a review from a team as a code owner November 11, 2026 19:12
Copilot AI balanced review requested due to automatic review settings November 11, 2026 19:12
@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) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Nov 11, 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.

🟡 Changes recommended

The new module-name validation lacks regression coverage for invalid names and platform-specific handling, leaving its error behavior and prevention of local proxy-file creation unverified.

1 open issue
What changed in this PR

Adds protective validation before Import-Module -PSSession uses remote module names to construct local proxy-module paths.

Changes:

  • Rejects null/empty names, path separators, ./.., and colons on Windows.
  • Reports an error and skips rejected modules before constructing local paths.
File Description
src/​System.Management.Automation/​resources/​Modules.resx Adds the error message for rejected module names.
src/​System.Management.Automation/​engine/​Modules/​ImportModuleCommand.cs Validates remote module names before local path construction.

Review effort: Balanced

Version remoteModuleVersion,
PSSession psSession)
{
if (string.IsNullOrEmpty(remoteModuleName) || remoteModuleName.IndexOfAny(s_pathTraversalChars) >= 0 || remoteModuleName is "." or "..")
@jshigetomi Justin Chung (jshigetomi) changed the title Protect remote module import paths by validating module names Validate remote module names before Import-Module constructs local paths Nov 11, 2026
@jshigetomi Justin Chung (jshigetomi) changed the title Validate remote module names before Import-Module constructs local paths Validate remote module names before Import-Module Nov 11, 2026
['\\', '/'];
#else
['\\', '/', ':'];
#endif

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.

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.

3 participants