Repository navigation
#628 [security][tools] Bash の閉じ込めの検査で、.. と ~ だけの語を確かめ、dd の of= を書き込み先として認識する - #642
Merged
Merged
Conversation
Issue #628 problem 1: a bare `..` or a `~`-prefixed `/`-less word, and the right-hand side of a non-assignment `NAME=value`, are now literal read candidates, so `ls ..`, `ls ~`, `make PREFIX=~`, `cat --file=..`, `tar -C ..` and `git -C ..` are refused. The `echo ~`/`echo ..` display forms and a leading assignment (`X=~ cargo test`) stay allowed, and a `/`-containing spelling keeps its existing handling. Issue #628 problem 2: `dd`'s non-empty `of=` arguments are write targets, so `dd if=in of=out` is a recognized mutation and loses `bash:verify` auto-approval; an outward `of=` is refused and a protected `of=` is detected. `of=/dev/null` stays allowed, like a redirection or `tee`. Update the #582 decision corpus (`allow-dd-nonpath` A 0->1, V 1->0, plus new rows) and add tests/issue628_bash_parent_home_dd.rs. 判断: the `..`/`~` right-hand side of a non-assignment `NAME=value` is a candidate only for a value word (not a leading assignment); the `echo` display exception is applied to the new parent/home candidates for both the bare word and the `=` right-hand side, matching the existing `echo $HOME` exception. Co-authored-by: CommandCodeBot <noreply@commandcode.ai>
…issue-628-security-tools-bash-dd-of-613
5 tasks
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 の閉じ込めの検査に、既存の見逃しが 2 種類ありました(#613 の着手前調査と merge 前レビューで発見)。
..と~だけの語:静的な path の判定が/を必須にしていたので、ls ..・ls ~・cat ~のような語は候補にならず、ワークスペースの親や home の一覧を読めました。make PREFIX=~・cat --file=..のような=の右側も同じです。ddのof=:dd of=…が書き込みと認識されず(A=0)、bash:verify の自動許可の対象にもなっていました(V=1)。外向き symlink を通して外に書けました。この PR は、Issue 本文の設計 1〜3 どおりに直します。
変更(4 ファイル、+351/−4)
src/tools/bash/read_guard.rs(+39/−2):先頭の代入より後の語が..ちょうど、または~で始まり/を含まないとき、字どおりの読み取りの候補にする(既存の字どおりのパスの検査が拒否する)。先頭の代入でないNAME=valueの右側も同じ。echoの区切り(echo ~・echo ..)と先頭の代入(X=~ cargo test)は、今どおり候補にしない。/を含む形は今の扱いのまま。src/tools/bash_write_guard.rs(+19/−1):ddのof=で始まり値が空でない引数を、操作名ddの書き込み先にする。書き込みの閉じ込め、作業ディレクトリの候補、保護 path の検出、自動許可の判定に、ほかの書き込み先と同じく渡る。of=/dev/nullは出力のリダイレクト・teeと同じく許可。tests/corpus/apps/issue582-bash-read-candidates/fixtures/decision-cases.jsonl(+27/−1):allow-dd-nonpathの行の期待を A=0・V=1 から A=1・V=0 に改めた(厳しくなる向き)。ほかの 102 行の期待は変えていない。親・home の語、=の右側、dd of=の外・/dev/null・保護 path、値が変わらない形の 26 行を足した。tests/issue628_bash_parent_home_dd.rs(新規、+266):本文の表の形、値が変わらない形、ddの書き込みと自動許可、拒否が shell の前で止まり canary が漏れないこと。fixture はCARGO_TARGET_TMPDIRの下の一時ディレクトリの中だけ。検証
commandmate verifyの 15 ゲート:develop66fbb07bを取り込んだ HEAD で 15/15 pass(d5da0b70、scope 4 本、違反 0)。TMPDIR=/tmp cargo test --test issue628_bash_parent_home_dd --test issue582_bash_read_candidates(CI と同じ条件を作るため):取り込んだ HEAD で exit 0、28 passed・0 failed、4 passed・0 failed(issue582・issue628 の順)。2a078debの src + この PR のテストと corpus の表):新しい形のテストだけが FAIL(ls ..が拒否されない、dd if=in.bin of=out.binの V が 1、表のallow-dd-nonpathの V の不一致、拒否されないまま shell でls ..が走る)。値が変わらないことを確かめる 1 本と、表の既存の行は develop でも pass。cargo mutants --jobs 1、--in-diff、--libと結合テスト 2 本):24 件で caught 22・missed 0・unviable 2。ddcb8022([security][tools] Bash の cd・pushd の行き先が 1 つに一致する glob だと作業ディレクトリが検査されず、外を読み書きできる(#613 のレビューで発見) #635・[test] runner cleanup の終了順序と孫プロセス消滅を直接確認する #630 を含む)→ develop+[security][tools] Bash の閉じ込めの検査が、.. と ~ だけの語を確かめず、dd の of= を書き込みとして認識しない(#613 の調査で発見) #628 の 2 組で比べ、R・A・W・P・S が 1→0 の行、V が 0→1 の行はどちらも 0 件。変わった 231 行はすべて厳しくなる向き。echoの例外は名前が字どおりechoのときだけで広すぎない(printf ~・/bin/echo ..・builtin echo ..は拒否)。of=/dev/null/../../etc/xやリダイレクトとの組み合わせも拒否される。新しく拒否される形
cd sub && ls ..(bash では中に留まるが、作業ディレクトリの候補に root も残るため)。root からlsで書けば通る。ls "~"(~という名前のファイル)。先頭に./を付ければ通る。make PREFIX=~のような home を値に渡す形(閉じ込めの外を指すので拒否のまま)。tar -C .. -cf - x・git -C .. status(..だけの語が候補になったため)。-Cの値を作業ディレクトリとして扱う修正そのものは [security][tools] Bash でオプションにより作業ディレクトリを変える形(tar -C・git -C など)と、- で始まる pushd の行き先が検査されない(#613・#635 のレビューで発見) #637。dd … of=…は、中に書く形も自動許可から外れる(書き込みのコマンドなので)。..・~だけの語、dd、-Cを含むものは 0 件。この PR では直していない既存の穴(どれも #628 の前からあり、この PR で緩んではいない)
-Cで作業ディレクトリを変える形(tar -C sub -cf - lf2、git -C sub …):[security][tools] Bash でオプションにより作業ディレクトリを変える形(tar -C・git -C など)と、- で始まる pushd の行き先が検査されない(#613・#635 のレビューで発見) #637 で扱う。~(ls {~,x}、cat {~,~}):H-13 で見つけた base からの穴。展開の結果が~で始まる場合だけ漏れている。別の Issue で扱う。Refs #628
🤖 Generated with Claude Code