Skip to content

fix: reject classification targets outside the archive root - #4

Merged
forgottenlab merged 1 commit into
mainfrom
fix/classify-target-containment
Nov 17, 2026
Merged

forgottenlab merged 1 commit into
mainfrom
fix/classify-target-containment

Conversation

@forgottenlab

Copy link
Copy Markdown
Owner

Summary / 概述

Fixes a file classification security issue that could allow configured targets to escape the managed archive root.

修复文件分类目标路径约束缺失的问题,防止分类规则将文件移动到受管归档目录之外。

Changes / 修改内容

English

  • Validate classification targets and fallback paths before moving files.
  • Reject parent-directory traversal, out-of-root absolute paths, and cross-drive targets.
  • Reject existing junctions or symbolic links that resolve outside the managed archive root.
  • Revalidate target directories in the watcher before and after directory creation.
  • Preserve valid classification behavior and add regression tests.
  • Record the fix in the Unreleased changelog.

简体中文

  • 在移动文件前验证分类规则及备用分类目标的路径。
  • 拒绝父目录穿越、归档目录外的绝对路径及跨盘符目标。
  • 拒绝解析后指向受管归档目录之外的 junction 或符号链接。
  • watcher 在创建目标目录前后重新执行路径校验。
  • 保持合法分类行为兼容,并新增回归测试。
  • 在 CHANGELOG 的 Unreleased 部分记录本次修复。

Verification / 验证结果

Windows 11 · Python 3.12.14

  • pytest: 94 passed, 1 skipped
  • Path traversal and junction regression tests passed.
  • Valid classification behavior remained functional.
  • Git whitespace checks passed.
  • No real Downloads, user configuration, or installer was modified.

简体中文

  • Windows 实机测试:94 项通过,1 项跳过。
  • 路径穿越和 junction 越界测试通过。
  • 合法文件分类行为保持正常。
  • Git 空白字符检查通过。
  • 未修改真实下载文件、用户配置或执行安装器。

The skipped test requires Windows symbolic-link privileges (WinError 1314). Equivalent junction-escape cases passed.

跳过的测试需要 Windows 符号链接创建权限(WinError 1314);相应 junction 越界场景已通过测试。

Remaining limitations / 剩余限制

A narrow time-of-check/time-of-use (TOCTOU) race may remain if a validated directory is replaced before file movement. This is outside the current fix scope and should be addressed separately.

如果其他进程在目录校验后、文件移动前替换目录,理论上仍可能存在竞态风险。本次不处理这一独立问题,后续单独跟踪。

Release scope / 发布范围

  • This PR targets the next unreleased version.
  • The published v0.2.2 tag and GitHub Release remain unchanged.
  • Installer-launch behavior and Environment Migration are outside this PR.

本 PR 面向后续未发布版本,不修改现有 v0.2.2 发布记录,也不涉及安装器启动逻辑或 Environment Migration 功能。

Changes:
- Validate rule and fallback classification targets as children of the managed archive root.
- Reject absolute paths, parent-directory traversal, other drive letters, and junctions or symbolic links that escape the archive tree before any file is moved.
- Add regression tests and record the security fix in the unreleased changelog.

修改内容:
- 将分类规则和 fallback 目标约束为受管归档根目录的子目录。
- 在移动文件前拒绝绝对路径、父目录穿越、其他盘符,以及指向归档树外的 junction 或符号链接。
- 新增回归测试,并在 Unreleased changelog 中记录该安全修复。

Verification:
- Windows host, repository venv Python 3.12.14: 94 passed, 1 skipped.
- The skipped test requires directory symlink privilege (WinError 1314); junction escape cases passed.

验证:
- 在 Windows 主机、仓库虚拟环境 Python 3.12.14 上运行完整测试集:94 passed,1 skipped。
- 跳过的用例需要创建目录符号链接的权限(WinError 1314);junction 逃逸用例已通过。
@forgottenlab
forgottenlab merged commit 48b09b3 into main Nov 17, 2026
8 checks passed
@forgottenlab
forgottenlab deleted the fix/classify-target-containment branch November 17, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant