Skip to content

fix(local): reject unsafe paths in installer state - #911

Open
rudycelekli wants to merge 1 commit into
Tencent:mainfrom
rudycelekli:fix/local-install-state-paths
Open

rudycelekli wants to merge 1 commit into
Tencent:mainfrom
rudycelekli:fix/local-install-state-paths

Conversation

@rudycelekli

Copy link
Copy Markdown

What changed

This ports the install-state path validation from @hobostay's #33 to the current local/ tree, following the maintainer's request for a rebased fix. Installer state now requires each recorded path to be relative and contained lexically under the project. The checks apply POSIX and Windows path rules so a state file moved between hosts gets the same validation.

Scope

  • Installer / CLI
  • Classic and Portable shared installer state

Compatibility

Valid existing install state needs no migration. Invalid paths cause a clear CLI error before managed files are processed.

Validation

  • cd local && PYTHONPATH=src python3.12 -m unittest discover -s tests -p test_installer.py -v passed 23 tests.
  • The new regression covers forced update, uninstall and status for POSIX and Windows parent traversal, absolute and drive-relative paths, Windows rooted paths, and paths naming the project root or an empty string. It also checks that the temporary sibling file is preserved.
  • npm and curl installation smoke tests and the observability tests passed.
  • The wheel smoke's unit checks passed. Its wheel bootstrap did not pass under the workstation's system pip 21.2.4.
  • validate.sh on this base stops on its existing ripgrep self-match, addressed independently in fix(local): avoid self-matches in public-content validation #909. Full E2E and Gitleaks were not run for this change.

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • Original contribution credited in the commit.

Port the state-path validation from Tencent#33 into local/.

Co-authored-by: Qiaochu Hu <110803307+hobostay@users.noreply.github.com>

@Yanami-2K Yanami-2K left a comment

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.

已核对 local/src/devflow_cli/core.py:load_state 现在会拒绝非 dict 的状态和缺少 files 列表的安装记录;is_safe_state_path 同时按 POSIX 和 Windows 规则拒绝带 anchor 的路径、..、空串、. 和 NUL。我逐一推演了 C:keep.txt、\keep.txt、. 等边界,都会被拦下。这是真实的安全问题:篡改过的安装状态可能让 update 或 uninstall 写入、删除项目外的文件。新测试对 8 种非法路径分别验证了 force update、uninstall 和 status 三个入口,并断言项目外的文件内容不变,断言充分。

提示:本 PR 与 #934 改的是同一文件中紧邻的 load_state 和 save_state,后合入的一方可能需要简单 rebase;两者功能互不重叠,都应保留。校验只做字面判断,不处理项目内指向外部的符号链接,这与 PR 描述一致。

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.

2 participants