Skip to content

#641 [security][tools] Bash の閉じ込めの検査で、brace の展開から出てくる ~ を拒否する - #644

Merged
Kewton merged 1 commit into
developfrom
feature/issue-641-security-tools-bash-brace-home-628
Oct 9, 2026
Merged

Kewton merged 1 commit into
developfrom
feature/issue-641-security-tools-bash-brace-home-628

Conversation

@Kewton

@Kewton Kewton commented Oct 9, 2026

Copy link
Copy Markdown
Owner

概要

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)

検証

  • commandmate verify の 15 ゲート:develop b506fbdf を含む 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 の順)。
  • 二点測定(develop b506fbdf の src に、この PR のテストを足した):
    • 新しい形のテスト 2 本だけが FAIL(ls {~,x}、tee {~/f,y} が拒否されない)。
    • 許可のままの形と拒否のままの形を確かめる 2 本は、develop でも pass。
  • 変異テスト(cargo mutants --jobs 1、--in-diff、--lib と結合テスト 3 本):1 件で caught 1・missed 0。
    • 足した条件そのものには、cargo-mutants は変異を作らない。この 1 か所が無いと FAIL することは、二点測定で示した。
  • merge 前レビュー(H-15):merge 可、blocker 0。
    • 判定の関数を fixture で呼んだ probe 2,077 行(記録 436 行を含む)を、base b506fbdf → HEAD で比べた。
    • R・A・W・P・S が 1→0 の行と、V が 0→1 の行は 0 件。
    • 変わった 113 行は、すべて brace から ~ が出る形が R(書き込みなら R・W)0→1 になったもの。記録の 436 行は 1 行も変わらない。
    • 本文の表に近い 141 形(入れ子、glob との組み合わせ、引用、前置き、リダイレクト、上限の近く)で、shell で home になる形はすべて拒否された。

新しく拒否される形

  • echo {~,x}(表示だけの echo)。echo {..,x} が今も拒否されるのと同じ扱い。
  • ls {"~",x}・ls {'~',x}・ls {\~,x}:shell では home にならないが、字句の読み方が引用を区別しないため拒否される(厳しい向き)。
  • 記録の 436 件と、参考の約 5.9 万件に、該当する形は 0 件。

この PR では直していない点(どれも blocker ではない。H-15 の後続の候補)

  • 読み取りの形の拒否でも、理由の文が「home-relative Bash write target …」になる。読み取りの glob・brace は前から書き込みの証明の関数を通っており、上限を超えたときの文も同じ形。event の名前と schema は変わらない。
  • = の右側の brace(cat --file={~,x})は R=0 のまま。手元の shell では home にならないので、漏れではない。

Refs #641

🤖 Generated with Claude Code

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>
@Kewton
Kewton merged commit 88d5a0d into develop Oct 9, 2026
5 checks passed
@Kewton
Kewton deleted the feature/issue-641-security-tools-bash-brace-home-628 branch October 9, 2026 14:17
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