Improve validation for Copy-Item -FromSession - #28006
Merged
Merged
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
🟡 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.
Dongbo Wang (daxian-dbw)
approved these changes
Sep 11, 2026
Dongbo Wang (daxian-dbw)
merged commit Sep 11, 2026
85efec2
into
PowerShell:master
36 of 41 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header