Skip to content

Improve CAB extraction path handling - #28009

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

Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
anamnavi:cab-validation

Conversation

@anamnavi

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

Copy link
Copy Markdown
Member

PR Summary

This pull request improves path handling during CAB file extraction in CabinetNativeApi and enhances error handling around extraction operations. It ensures extracted files are resolved relative to the intended help directory before files or directories are created. The change also includes a test update to improve reliability in Debug-Runspace tests.

PR Context

PR Checklist

Copilot AI lite review requested due to automatic review settings September 11, 2026 17:46
@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 CAB extraction safety issues remain unresolved.

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

Pull request overview

Improves CAB extraction path safety and makes a Debug-Runspace test less timing-sensitive.

Changes:

  • Adds CAB path validation and extraction error handling.
  • Increases the Debug-Runspace event wait timeout.
File summaries
File Review summary
test/powershell/Modules/Microsoft.PowerShell.Utility/Debug-Runspace.Tests.ps1 Extends the asynchronous wait timeout.
src/System.Management.Automation/help/CabinetNativeApi.cs Critical issues: FdiOpen exceptions can escape the callback (3 votes), and reparse points can bypass path containment (2 votes). Nit: add regression coverage for malicious and valid CAB paths (1 vote).
Review details

Suppressed comments (1)

src/System.Management.Automation/help/CabinetNativeApi.cs:398

  • These new security checks are not covered by a regression test. The existing Update-Help tests exercise trusted CABs but do not cover rooted paths, .. traversal, colon/ADS names, or directory-prefix collisions, so a future change could reintroduce extraction outside the destination without failing CI. Add a Windows CAB fixture/test that asserts malicious entries are rejected while valid nested paths still extract.
            // Ensure resolved path starts with the canonical help directory.
            // OrdinalIgnoreCase is intentional: NTFS on Windows is case-insensitive, so two paths that
            // differ only in case refer to the same file and must be treated as equivalent here.
            if (!resolvedPath.StartsWith(canonicalHelpDir, StringComparison.OrdinalIgnoreCase))
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • 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/help/CabinetNativeApi.cs
Comment thread src/System.Management.Automation/help/CabinetNativeApi.cs
@anamnavi Anam Navied (anamnavi) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Sep 11, 2026
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 9f7b306 into PowerShell:master Sep 11, 2026
36 of 41 checks passed
// The trailing separator is needed to prevent false positive matches where a directory
// name is a prefix of another (e.g., "/path/help" matching "/path/help-backup/file.txt")
string canonicalHelpDir = Path.GetFullPath(helpDirectory);
if (!canonicalHelpDir.EndsWith(Path.DirectorySeparatorChar.ToString()))

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.

We have no need to use ToString().
Also now there is Path.EndsInDirectorySeparator() method.

Suggested change
if (!canonicalHelpDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
if (!Path.EndsInDirectorySeparator(canonicalHelpDir))

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

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants