fix(hooks): harden env escaping and privacy symlink resolution#65
Open
hapo-nghialuu wants to merge 1 commit into
Open
fix(hooks): harden env escaping and privacy symlink resolution#65hapo-nghialuu wants to merge 1 commit into
hapo-nghialuu wants to merge 1 commit into
Conversation
- session.cjs writeEnv: escape \ $ ` " (was " only) to stop shell injection when CLAUDE_ENV_FILE is sourced - privacy-block.cjs: resolve symlink targets before the sensitive-file check so a benign-named symlink to .env cannot bypass the gate - add first hook behavioral test harness (node --test subprocess), wired into the self-test suite; regression tests proven red on unpatched code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mục đích
Hai lỗi hook đã kiểm chứng còn tồn tại trên
dev/0.13.3, mỗi lỗi kèm test hồi quy. Đây là gói fix độc lập, tách khỏi PR CI (#64).Thay đổi
1.
session.cjs— shell injection quaCLAUDE_ENV_FILE(HIGH)writeEnvtrước chỉ escape". Một giá trị chịu ảnh hưởng từ bên ngoài chảy vào env file — ví dụ tên git branchevil$HOME-x`pwd`— sẽ expand$HOMEvà thực thipwdkhi env file đượcsource. Sửa: escape\ $ \"trong một pass, output **giống hệt**escapeShellValuechuẩn ởlib/config.cjs` (đã verify equivalence trên 8 ca gồm chuỗi lồng nhau).2.
privacy-block.cjs— symlink bypass (MEDIUM)Gate chặn file nhạy cảm chỉ kiểm
path.basename. Một symlink tên vô hại (notes.txt→.env) lọt qua vì basename không khớp pattern. Sửa:fs.realpathSyncgiải symlink, kiểm cả tên yêu cầu lẫn tên đích thật. Exemption (.env.example) vẫn thắng trên một trong hai tên; fail-open khi không resolve được.3. Khung test hook đầu tiên (
src/claude/hooks/__tests__/)Chạy hook như subprocess thật (pipe payload vào stdin → assert exit code/output) qua
node --test, nối vàorun-skill-self-tests.mjs. 5 test:.envtrực tiếp / chặn symlink→.env(hồi quy) / cho file thường / cho symlink→.env.example$HOME+backtick, source env file, assertGIT_BRANCHđọc lại đúng literal (không expand/execute)Bằng chứng
escapeShellValuechuẩn: khớp trên mọi ca thửLưu ý CI
Branch nhánh từ
dev(chưa cótest.yml— đang ở PR #64). CI sẽ tự chạy cho PR này sau khi #64 merge vàodev. Trước đó dựa trên bằng chứng local 142-pass ở trên.🤖 Generated with Claude Code