Skip to content

Improve validation for Copy-Item -FromSession - #28006

Merged
Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
anamnavi:copy-item
Sep 11, 2026
Merged

Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
anamnavi:copy-item

Conversation

@anamnavi

@anamnavi Anam Navied (anamnavi) commented Sep 11, 2026

Copy link
Copy Markdown
Member

PR Summary

This pull request improves how Copy-Item -FromSession handles file, directory, and alternate stream names received from remote sessions. It adds validation to ensure remote-provided names are treated as simple item names to avoid unexpected destination paths during copy operations.

  • Added a new method in FileSystemProvider.cs to validate remote file, directory, and stream names before they are used to construct destination paths.

  • Added new error messages when an invalid remote name is detected.

  • Added comprehensive tests covering valid and invalid remote name scenarios to ensure consistent behavior across platforms.

  • Added test helpers in Copy-Item.Tests.ps1 to validate the new name-checking logic.

PR Context

PR Checklist

@anamnavi
Anam Navied (anamnavi) requested a review from a team as a code owner September 11, 2026 17:16
Copilot AI lite review requested due to automatic review settings September 11, 2026 17:16
@azure-pipelines

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

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

Critical path-traversal risk remains for Windows-normalized remote names; validation and tests must be updated.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Improves Copy-Item -FromSession validation against unsafe remote names.

Changes:

  • Adds validation for files, directories, and alternate streams.
  • Adds localized error messages.
  • Adds cross-platform validation tests.
File summaries
File Summary
test/powershell/Modules/Microsoft.PowerShell.Management/Copy-Item.Tests.ps1 Adds valid and invalid remote-name tests.
src/System.Management.Automation/resources/FileSystemProviderStrings.resx Adds path-traversal error messages.
src/System.Management.Automation/namespaces/FileSystemProvider.cs Adds remote-name validation; trailing dots or spaces can still enable traversal on Windows.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

Comment thread src/System.Management.Automation/namespaces/FileSystemProvider.cs
@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 11, 2026
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 85efec2 into PowerShell:master Sep 11, 2026
36 of 41 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.

3 participants