Repository navigation
#641 [security][tools] Bash の閉じ込めの検査で、brace の展開から出てくる ~ を拒否する - #644
Merged
Kewton merged 1 commit intoOct 9, 2026
Merged
Conversation
Issue #641: the expansion proof re-checked each brace result only as a workspace-relative spelling, so `{~,x}` was proven as `~`/`x` and could read or write the home directory. The shell tilde-expands after brace expansion, so refuse a brace result that starts with `~` before the glob search; a name found by a glob (`*` matching `~x`) is still judged by its literal spelling. Adds tests/issue641_bash_brace_home.rs (R=1 reads, W=1 writes, and the unchanged workspace/glob forms). 判断: the refusal reason reuses the existing "home-relative" message from ensure_bash_write_target; a write-shaped command is still refused by the write guard first, so the integration test distinguishes W by the non-"path reference" operation. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
5 tasks
Kewton
deleted the
feature/issue-641-security-tools-bash-brace-home-628
branch
October 9, 2026 14:17
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.
概要
Bash の閉じ込めの検査に、既存の見逃しがありました(#628 の merge 前レビュー H-13 で発見)。brace の展開から
~で始まる語が出てくると、その語は home として確かめられていませんでした。shell は brace を展開した後に~を展開するので、次のことができました。ls {~,x}、cat {~/.bashrc,x}で、home の一覧や中身を読む。rm {~/f,x}、echo x > {~/f,y}で、home に書く。~で始まる語の拒否は、brace を展開する前の語({~,x})にしか当たっていませんでした。展開した後の各語は、ワークスペースからの相対パスとして確かめるだけでした。この PR は、Issue 本文の設計どおりに直します。
変更(2 ファイル、+187/−0)
src/tools/path_guard/bash_pattern.rs(+8/−0)ensure_expanded_write_target)で、brace を展開した直後、glob の一致を探す前に、展開の結果が~で始まれば拒否する。拒否の理由は、既存の home-relative の文。*に一致する~xという名前のファイル)には当てない。shell は glob の結果の~を展開しないため。tests/issue641_bash_brace_home.rs(新規、+179)ls {src,tests}、cat {a,b}.txt、touch {a,b}.txt、cp a.txt{,.bak})、ls x{~,y}・ls {x~,y}、glob の一致の~で始まる名前が許可のままなこと。CARGO_TARGET_TMPDIRの下の一時ディレクトリの中だけ。shell は起動しない。read_guard.rs、[security][tools] Bash の閉じ込めの検査が、.. と ~ だけの語を確かめず、dd の of= を書き込みとして認識しない(#613 の調査で発見) #628 の試験、[security][tools] Bash の 2 段目の path 検査が、$・glob・動的な値で静的な相対パスや展開先を確かめず、ワークスペース外を読める(#571 を統合) #582 の corpus の表。検証
commandmate verifyの 15 ゲート:developb506fbdfを含む HEAD で 15/15 pass(8fa2e470、scope 2 本、違反 0)。TMPDIR=/tmp cargo test --test issue641_bash_brace_home --test issue628_bash_parent_home_dd --test issue582_bash_read_candidates(CI と同じ条件を作るため):exit 0、28 passed・0 failed、4 passed・0 failed、4 passed・0 failed(issue582・issue628・issue641 の順)。b506fbdfの src に、この PR のテストを足した):ls {~,x}、tee {~/f,y}が拒否されない)。cargo mutants --jobs 1、--in-diff、--libと結合テスト 3 本):1 件で caught 1・missed 0。b506fbdf→ HEAD で比べた。~が出る形が R(書き込みなら R・W)0→1 になったもの。記録の 436 行は 1 行も変わらない。新しく拒否される形
echo {~,x}(表示だけのecho)。echo {..,x}が今も拒否されるのと同じ扱い。ls {"~",x}・ls {'~',x}・ls {\~,x}:shell では home にならないが、字句の読み方が引用を区別しないため拒否される(厳しい向き)。この PR では直していない点(どれも blocker ではない。H-15 の後続の候補)
=の右側の brace(cat --file={~,x})は R=0 のまま。手元の shell では home にならないので、漏れではない。Refs #641
🤖 Generated with Claude Code