Skip to content

#628 [security][tools] Bash の閉じ込めの検査で、.. と ~ だけの語を確かめ、dd の of= を書き込み先として認識する - #642

Merged
Kewton merged 2 commits into
developfrom
feature/issue-628-security-tools-bash-dd-of-613
Oct 9, 2026
Merged

Kewton merged 2 commits into
developfrom
feature/issue-628-security-tools-bash-dd-of-613

Conversation

@Kewton

@Kewton Kewton commented Oct 9, 2026

Copy link
Copy Markdown
Owner

概要

Bash の閉じ込めの検査に、既存の見逃しが 2 種類ありました(#613 の着手前調査と merge 前レビューで発見)。

  1. .. と ~ だけの語:静的な path の判定が / を必須にしていたので、ls ..・ls ~・cat ~ のような語は候補にならず、ワークスペースの親や home の一覧を読めました。make PREFIX=~・cat --file=.. のような = の右側も同じです。
  2. 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 の下の一時ディレクトリの中だけ。
  • event の名前と schema は変えていない。拒否は既存の理由の文を使う。

検証

新しく拒否される形

この PR では直していない既存の穴(どれも #628 の前からあり、この PR で緩んではいない)

Refs #628

🤖 Generated with Claude Code

Kewton and others added 2 commits October 9, 2026 18:04
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>
@Kewton
Kewton merged commit b506fbd into develop Oct 9, 2026
5 checks passed
@Kewton
Kewton deleted the feature/issue-628-security-tools-bash-dd-of-613 branch October 9, 2026 11:01
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