Create parent directories only after the containment check in InstallHelper.TryExtractToDirectory

未关闭 适合新手
#2,056 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp
领域
security

调研方向

从 src/code/InstallHelper.cs 中的 InstallHelper.TryExtractToDirectory 开始,检查目录创建和包含关系检查逻辑附近的代码。跟踪 entry.FullName 如何变成 destinationPath,并验证是否在任何目录或文件副作用发生之前完成包含关系检查。完成标准是:被包含关系检查拒绝的条目不会留下任何目录,而有效条目仍能正常提取。

由索引模型根据 Issue 内容生成。

描述

Summary of the new feature / enhancement

During package extraction, entry-derived parent directories are created before the path-containment decision runs. An entry whose file write the containment check would reject can still leave empty directories outside the extraction root (directory-only effect — no file content is written outside). As a user, I want each entry's extraction side effects to be all-or-nothing, so a malformed package cannot leave stray directories anywhere on disk.

Proposed technical implementation details

In src/code/InstallHelper.cs, TryExtractToDirectory (~L1299 on current main):

  • For entries containing a path separator, Directory.CreateDirectory(Path.Combine(extractPath, parentDirs)) runs first (~L1372-1377), using the raw entry prefix.
  • Only afterwards is destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName)) computed and the StartsWith(extractPath) containment verified (~L1381-1386) — and that check gates only the ExtractToFile call (~L1388).

So a package containing an entry such as ../../../../empty/dir/x (this loop is reached on installs from HTTP repositories, which do not go through a BCL extraction up front) creates empty/dir relative to the extraction temp directory as empty directories, and then the file write is skipped by the containment check.

Suggested reordering, so containment gates every side effect:

  1. Compute destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName)) first.
  2. Verify containment of destinationPath under extractPath.
  3. Only then create Path.GetDirectoryName(destinationPath) and call ExtractToFile.
  4. Skip entries that fail containment entirely — no partial side effects.

This also makes directory creation consistent with the resolved path rather than the raw entry string.

主要语言
C#
星标
576
派生
114
平均合并
1 天 2 小时
30 天内合并 PR
7

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PowerShell/PSResourceGet 的其他 Issue

查看 PowerShell/PSResourceGet 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。