Consolidate virtualenv cache validation and path security checks into a shared helper across scripts/lint.py and scripts/pre_commit_cache.py
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
Hướng nghiên cứu
Start by comparing _home_rejection and _read_pyvenv_cfg in scripts/lint.py and scripts/pre_commit_cache.py, and check scripts/git_base.py as the existing extraction pattern. Move the shared logic into a new scripts/venv_cache.py, then update both scripts to import it. Done means neither script defines those functions locally, scripts/test_venv_cache.py passes offline, and scripts/test_lint.py and scripts/test_pre_commit_cache.py still pass. The security-sensitive path checks make this a cautious change, so expect careful review.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happened
During PR #532 (resolving Issue #524), scripts/pre_commit_cache.py (running on the host runner to warm the cache) and scripts/lint.py (running inside the sandboxed agent environment to restore and normalize the cache) independently implemented and duplicated virtual environment metadata parsing (_read_pyvenv_cfg), path validation (_home_rejection), and platform interpreter validation (_python_env_rejection vs _verify_and_normalize_env).
Because these validation routines were duplicated rather than shared, security fixes required multiple coordinated edits across both files across four rounds of human review (e.g. adding traversal rejection and .resolve() in Round 2 [commit 16e8ebe], and reordering static checks ahead of version gates in Round 3 [commit 6ea7ec1]). Maintainer jerry-ng2 had to review and flag identical issues in both scripts/lint.py and scripts/pre_commit_cache.py independently. Furthermore, _home_rejection remains duplicated word-for-word in both scripts on main.
What could go better
Duplicating security-sensitive parsing and containment checks across runner and sandbox scripts creates maintenance divergence and review churn. In ProtoBot, Issue #541 successfully established the architecture pattern of extracting duplicated check logic (Git base resolution) from multiple scripts into a centralized, unit-tested module (scripts/git_base.py).
We have high confidence that extracting virtual environment metadata parsing and path containment checks into a shared scripts/venv_cache.py helper with its own comprehensive test suite (scripts/test_venv_cache.py) will prevent future drift, eliminate duplicate code, and ensure all cache creators and consumers enforce identical security invariants.
Proposed change
- Create a shared helper module
scripts/venv_cache.pycontaining:read_pyvenv_cfg(path: Path) -> dict[str, str]: Robust parsing ofpyvenv.cfgkey-value pairs.home_rejection(home: str) -> str | None: Canonical validation thathomeis absolute, rejects..path segments, and resolves to/usror a directory below/usr.contained_real_path_rejection(path: Path, root: Path) -> str | None: Verifies that a path is not a symlink and resolves strictly within the resolved root.platform_interpreter_rejection(path: Path, allowed_versions: set[str]) -> str | None: Verifies symlinks to platform interpreters.
- Refactor
scripts/lint.pyandscripts/pre_commit_cache.pyto import and consume these shared helpers instead of maintaining local duplicates. - Create unit test suite
scripts/test_venv_cache.pytesting path containment, traversal attempts (/usr/../tmp/evil), symlink escapes, and metadata edge cases. - Register
test_venv_cache.pyin.pre-commit-config.yamlunderrepo: local.
Validation criteria
scripts/lint.pyandscripts/pre_commit_cache.pycontain zero duplicate definitions of_home_rejectionor_read_pyvenv_cfg.python3 scripts/test_venv_cache.pyexecutes cleanly offline and passes 100% of unit tests covering traversal rejection, path resolution, and virtualenv metadata parsing.- Existing unit test suites
scripts/test_lint.pyandscripts/test_pre_commit_cache.pycontinue to pass without regression.
Related issues checked
Searched: consolidate virtualenv cache lint pre_commit_cache; duplicate helper scripts lint pre_commit_cache pyvenv
Considered: #541, #524, #432
#541 established the pattern for extracting duplicated check script logic into scripts/git_base.py but covers Git resolution, not virtualenv cache validation. #524 is the closed parent issue that implemented the cache bootstrap. #432 is the closed engine replacement issue that preceded #524.
Generated by retro agent from https://github.com/redhat-et/ProtoBot/pull/532
- Ngôn ngữ chính
- Go
- Star
- 7
- Fork
- 9
- Merge trung bình
- 22 giờ 37 phút
- Pull request đã merge (30 ngày)
- 118
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của redhat-et/ProtoBot
-
bug component:validator triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
redhat-et/ProtoBot#596 · 5 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation triaged
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
redhat-et/ProtoBot#589 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation risk/low triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
redhat-et/ProtoBot#588 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feature infra needs-human risk/low triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
redhat-et/ProtoBot#579 · 6 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
blocked documentation infra risk/low triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
redhat-et/ProtoBot#552 · 6 bình luận · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của redhat-et/ProtoBot
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
sresarehumantoo/cc-artex#456 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ollama/ollama#20021 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
factory:subtask
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
release
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
github/gh-aw-mcpg#17603 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
avr: SPI Mode2 runs as mode 1Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
tinygo-org/tinygo#6727 ·
Maintainer thường phản hồi trong vòng 1 ngày