Repository navigation
fix(hooks): judge gh beside commands that write nothing as gh alone - #256
Conversation
A line joining gh with commands that only read and print, such as jq, grep, head, awk, sort, sed -n, git reads, or a literal cd, can no longer plant a stand-in on PATH, so it no longer asks for that reason. The working repository is checked in every directory the call may run in. Lines that may write a program, change PATH, or build text with a heredoc or a substitution still ask. Closes #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Review summaryI read the new P1: a same-line redirect can plant what a later
Checked and found fine
No other findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 82a20876a2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A file written beside gh may be configuration a later git read runs, such as .git/config naming a diff program, which could then place a stand-in gh on PATH. Only gh's own output may go to a file off PATH; every other command may write only to /dev/null. Refs #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Review summaryI reviewed the diff read-only. I did not run the test suite. I found one blocking issue. P1 — gh's own redirect can plant git configuration that a later git read runs (inline comment on What I checked and found fine:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30052ef47a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
… git read gh's own output may land in .git/config or another file a later git read on the line consumes, and GIT_EXTERNAL_DIFF makes git diff run a program. A line with a git read now allows gh's output only to /dev/null, and an inherited GIT_EXTERNAL_DIFF keeps the git read untrusted. Refs #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Review summaryI read the whole diff. I couldn't run anything, so the findings below come from reading the code. The core design holds up:
Findings:
No P0 or P1 findings. 🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 02f1ba91cd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…a git read A git read that refreshes the index runs the repository's post-index-change hook, which the agent can write, and settings injected through GIT_CONFIG_* may name a program. Either keeps a git read beside gh untrusted; injected settings that run nothing, such as the sandbox's core.fsmonitor=false, still pass. Unit tests pin the option checks of read_only_commands. Refs #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Review summaryI found no P0 or P1 problems, and no correctness or security bugs in the changed behaviour. I read the diff and the surrounding code ( What I checked
Finding
Residual risks the PR already notes
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e7e0db9c9e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
git names the post-index-change hook's path itself, following core.hooksPath and worktrees. A repository with submodules, whose configuration and hooks a read also enters, and a hook defined in repository configuration keep a git read beside gh untrusted. Refs #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
|
Review summary: one P2 finding, no blockers found.
I also checked the word-level read-only checks in 🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de1b3bd9d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
git reads may run programs that repository configuration, hooks, submodules, the environment, or a lazy fetch name, and each fix uncovered another, so a line holding git keeps asking as before and the git configuration checks that served only these reads are gone. A cd is now followed by both the logical path bash keeps after a symlink and the physical one, and any option or `--` before its operand is not followed. Refs #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Review summaryI read the diff and the surrounding parser code. The sandbox blocked every attempt to run Python or the tests, so the points below come from reading the code, not from running it. P2 (inline): P3: PR description vs diff. The description says I checked the |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff71434a1f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A word known only at run time may turn printf into `printf -v PATH`, so echo and printf with one no longer count as read-only. A redirection on a group, subshell, branch, or loop belongs to no call inside it, so a line holding one keeps asking. Refs #255 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
Review summaryI read the new Nothing blocks the merge (no P0 or P1). The word-level checks for awk, sed, sort, uniq and base64 are strict allowlists. Anything unrecognised falls back to asking, and I found no bypass in them. Two P2 findings, both in
Neither case has a test yet. The replay data covers real traffic, not these inputs. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 084e32322e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…thing (#262) ## 概要 `printf x%n PATH` は PATH に `1` を代入するのに,#256 の「何も書かないコマンド」判定では読み取りに数えられ,`printf x%n PATH; gh pr list -R furedea/agent-config` が allow になっていた.書式に `%n` 変換を持つ `printf` を読み取りに数えず,こうした行は確認にする.これで #256 の「記録」に残した P1(`%n`)の限界を閉じる. Refs #255 ## 変更前後 | 行 | 変更前 | 変更後 | | --- | --- | --- | | `printf x%n PATH; gh pr list -R furedea/agent-config` | allow | **ask** | | `printf '%s\n' x; gh pr list -R furedea/agent-config` | allow | allow | | `printf $OPT PATH /tmp; gh …`(run time の書式) | ask | ask(#256 のまま) | | `printf x{%,}n PATH; gh …`,`sort {-o,later/gh} x; gh …`(ブレース展開) | allow | **ask** | | `printf x%n GH_HOST; gh issue comment 1 -R furedea/agent-config -b ok` | allow | **ask** | ## 変更 - `agents/hooks/lib/read_only_commands.py`:`writes_nothing` で,`printf` の書式オペランド(先頭の `--` は飛ばす)に `%n` 変換があれば読み取りに数えない. - `%n` の形:`%` のあとにフラグ・幅・精度(`-+ #0'*.` と数字),位置指定(`$`),長さ修飾子(`hlLqjzt`)を挟んだ `n`.`%%` は文字の `%` として飛ばす. - zsh は書式のエスケープを変換の解釈より先に文字にする.`\u`/`\U` で作った `%` は変換になり,`\x`/8 進で作った `%` は文字のまま,`n` はどのエスケープから作っても変換になる.この挙動どおりに展開した書式でも判定する(bash はエスケープから変換を作らないので,bash にとっては確認が増えるだけ). - `agents/hooks/lib/gh_command_line.py`: - `_writes_nothing`:ブレース展開などで別の語になりうる語(`Command.spreading`)を run time の語と同じに扱う.`printf x{%,}n` や `sort {-o,later/gh}` は展開後に `%n`/`-o` になる(ローカルの自動セキュリティレビューの指摘). - `_changes_environment`:`printf` の `%n`,zsh の `print -f`(`print -f x%n V` も代入する),print/printf の run time に決まる語や広がりうる語(`printf "$F" GH_HOST`,`printf {-v,GH_REPO} x` は `-v` になる)を変数の代入とみなす(自動セキュリティレビューの指摘).`%n` で GH_HOST を変えると `-R OWNER/REPO` の host が変わるため. ## 実際の挙動の確認(bash 5.3.9,macOS の bash 3.2.57,zsh 5.9.1) `V=old; printf "<書式>" V` の後の `V`: | 書式 | bash 5.3 / 3.2 | zsh | | --- | --- | --- | | `x%n` `x%5n` `x%-n` `x%.3n` `x%#n` `x%0n` `x% n` `x%+n` `x%'n` `x%ln` `x%Ln` | 1 | 1 | | `x%hhn` `x%zn` `x%jn` `x%tn` `x%lln` | 1 | `%hhn` 以外は代入しない | | `x%*n`,`x%.*n`(`*` が引数を 1 つ取る) | 1 | 1 | | `x%1$n`,`x%2$n` | 代入しない | 1 | | `x%%%n` | 2 | 2 | | `x%%n`,`x%qn`,`x%bn` | 代入しない | 代入しない | | `x%n`,`x\U00000025n`,`x%\x6e`,`x%\156`,`x%l\x6e` | 代入しない | 1 | | `x\045n`,`x\x25n`,`x\x25\x6e` | 代入しない | 代入しない | ## テスト - [x] Red:追加した `printf x%n PATH; gh pr list -R furedea/agent-config` が修正前は `allow` で失敗(`test_a_line_that_may_plant_a_program_or_change_path_still_asks[printf assigning PATH with %n]`),`writes_nothing` の単体テスト 17 件も失敗. - [x] Green:同じテストが修正後に通過. - [x] `tests/hooks/test_gh_joined_read_only_lines.py`:`%n` の行は確認,普通の `printf '%s\n' x` の行は allow. - [x] `tests/hooks/test_read_only_commands.py`:上表で代入した書式(`--` 付きも)は読み取りでない,`%s\n`・`x%%n`・`100%%`・`%d items`・`x\045n`・`%s`・`-n` は読み取り,`\UFFFFFFFF` のような Unicode 範囲外のエスケープでも落ちない. - [x] `test_gh_joined_read_only_lines.py`:`printf x{%,}n PATH`,`sort {-o,later/gh} x` の行は確認(修正前は allow で失敗). - [x] `test_gh_environment.py`:`printf x%n GH_HOST`(修正前は allow で失敗),`print -f x%n GH_HOST`,`printf {-v,GH_REPO} other/r`,`printf "$F" GH_HOST`(修正前は allow で失敗)の行は確認. - [x] 手動の mutation(8 個:判定の削除,フラグ・長さ修飾子の文字クラスの縮小,`%%` 判定,zsh 展開の削除,`\x`/8 進の `%` の扱い,`--` の扱い,8 進の桁数)はすべて検出. - [x] `uv run pytest -n auto tests`(6253 passed,2 skipped),`ruff check`,`ruff format --check`,`ty check`,`deptry`,`vulture`. <details> <summary>範囲・前提・限界</summary> - 範囲は #256 の限界のうち `%n` だけ.zsh の `cd OLD NEW`,リダイレクト先のブレース展開・`~+`/`~-`,コマンドの無い文の `> f`,git 読み取り(#181)は範囲外. - 脅威モデルは #256 と同じ(エージェントは引数・環境変数・PATH を作れる.hook,Nix store,GitHub 設定は信頼する). - 判定は書式オペランドだけを見る.書式の後のオペランドは変数名として使われるだけで変換にはならない. - 誤検知として残るもの(確認が増えるだけ):`\\156` のようにエスケープされたバックスラッシュの後の数字も zsh のエスケープとして展開するので,`%\\156` は確認になる.bash で `%n` などを使う書式も確認になる. - `%n` による gh の読む変数の代入(`changes_environment`)とブレース展開は,同じ `%n` の取りこぼしとして本 PR で扱った. - 誤検知として増えるもの:`print -f` はどの書式でも確認になる.`printf '%s\n' "$X"` のように run time の語を持つ print/printf と gh を並べた行は確認になる.ブレースなどで広がる語を持つ `printf`/`echo`/`sort`/`sed`/`awk`/`uniq`/`base64` は確認になる. - レビュー対応(1 回分): - Codex P1「zsh の printf は `\0NNN`(4 桁)を読む」:zsh 5.9.1 で `printf 'a\0156b'` は `a \r 6 b`,`printf 'a\0045b'` は `a \004 5 b`,`V=old; printf 'x\0045n' V` で V は変わらず,`\0` を含めて 3 桁までと確認したため変更しない(スレッドに証拠を返信して解決).8 進で作った `%` は zsh でも文字のままなので,`\0045` が `%` になっても `%n` 変換にはならない.claude-review の同じ P3 の疑問も同じ理由で変更しない. - claude-review P3「`printf -v VAR fmt` では `assigns_a_count` が `-v` を書式と読む」:`-v` は `_changes_environment` が変数の代入として捕らえるので,`printf -v PATH x; gh pr list -R …`,`printf -v X x%n PATH; gh …` はどちらも確認になることを確かめた.誤った allow にならないため変更しない. - ローカルの自動セキュリティレビュー(ブレース展開,run time の書式)は修正した(上の「変更」). </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: furedea <132188853+furedea@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
🤖 I have created a release *beep* *boop* --- ## [0.3.1](v0.3.0...v0.3.1) (2026-11-20) ### Bug Fixes * **hooks:** do not count a printf whose format holds %n as writing nothing ([#262](#262)) ([f3a4543](f3a4543)) * **hooks:** judge gh beside commands that write nothing as gh alone ([#256](#256)) ([540bbad](540bbad)) * **hooks:** stop asking for gh calls whose target and arguments are known at hook time ([#254](#254)) ([f4aa355](f4aa355)) * **lint:** close the Rust and TypeScript items of [#196](#196) ([#259](#259)) ([1d2a81e](1d2a81e)) * **lint:** select the Go model-rule forms deferred in [#196](#196) ([#257](#257)) ([8c347fe](8c347fe)) * **lint:** widen three Python model-rule selectors deferred in [#196](#196) ([#258](#258)) ([b3fc801](b3fc801)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
概要
ghを読み取り専用のコマンドやcdとつないだ行は,「同じ行の別のコマンドが PATH の前の方に別の gh を置けるかもしれない」として確認になっていた.hook の時点で分かる事実(各コマンドが何も書かず別のプログラムも走らせない,リダイレクト先が PATH の要素でない,PATH に相対パスが無い)で判定し,この理由の確認をなくす.gh 自体の判定は #201 の policy table のまま.Closes #255
Refs #197, #253, #181
変更
read_only_commands.py(新規):語だけで「ファイルを書かず,別のプログラムも走らせない」と言えるコマンドの判定.cat column cut echo false grep head jq ls nl printf pwd sleep tail tr true wcawk(-F/-vだけ,プログラムに> | @ system getlineが無い),sed(-n -E -r -eだけ,スクリプトは行番号・パターンのpかw/eフラグの無いs///),sort(-o・--compress-programなどを除く),uniq(オペランド 1 つまで),base64(-dだけ)echo/printf(printf -v PATHになりうる)では確認.gh_command_line.command_line:plants_nothing:gh 以外がすべて上の読み取り(またはリテラルのcd)で,gh 呼び出しが 1 つ,gh 以外のリダイレクト先は/dev/nullだけ,gh 自身の出力先は/dev/nullか PATH の要素でないディレクトリ(run time に決まる先・PATH に相対要素があるときは不可).このときgh_environment._stand_in_problemは PATH を理由に確認しない.directories:hook の cwd と,リテラルのcdが入りうる各ディレクトリ(それまでの各ディレクトリから,bash が保つ論理パスと物理パスの両方).cdが失敗しても,サブシェル・パイプ内でも gh はこのどこかで動く.存在しない先,-で始まる語(cd -,-P,--など),pushd/popd,run time の先,PATH に相対・空の要素がある,CDPATH下の相対のcd,環境のcd関数は従来どおり確認.{ },( ),if,ループなど CallExpr 以外の文にリダイレクトがある行は,中のコマンドに書き込みとして記録されないので確認.changes_environmentで確認.command_objections.gh_objection:gh 呼び出しをdirectoriesの各ディレクトリで判定し,全部で allow のときだけ allow(作業リポジトリの remote,設定,プログラムの所在をそれぞれのディレクトリで見る).hook_input.working_directoryを切り出した.gh_environment:_stand_in_problemの条件にplants_nothingを足しただけ(main との差は 1 行).再生(2026-11-18 14:24〜11-19 15:13 JST の確認 390 件)
issue255_replay.pyを本ブランチの hook とorigin/mainの hook に向けて実行した(XDG_STATE_HOMEを scratch に向け,実際の audit log には書かない).390 件のうち command が無い 2 件を除く 388 件,guard_command 以外の hook による 16 件は対象外.再生環境の PATH には書き込める要素が gh より前に無かったため,実際の hook 環境(PATH 理由 74 件)を近似する「書き込める要素を先頭に足した PATH」でも測った.cdを既存チェックアウトに置き換えると追加で allowgit 読み取りを入れていた段階(43 件 / 25 件)から 7 件 / 6 件減った.
確認のまま残る内訳(通常の PATH,388 件中 allow 49 件・他 hook 16 件を除く 323 件):
python3,jev-lint,mkdir,消えた worktree へのcd20 件など)$'...'など)書き込める PATH の場合は,確認のまま 260 件が PATH 理由で出る.その内訳(通常の PATH での理由)は,代入・ループ 129,別コマンド 64,gh 呼び出しが複数(通常の PATH なら allow)30,分類不可 24,class C/D 7,送るファイル 6.
新たに allow になった 36 件はすべて目視で確認した:gh 以外は
grep/head/tail/jq/awk '{print ...}'/sed -n/sort/uniq/ls/cat/sleep/echo/wc/base64 -d,リテラルのcd(/tmp,相対のtests/hooks→../..),2>/dev/nullと2>&1だけ.gh はすべて読み取り(pr view/list/checks/diff,run view/list/watch,issue view,GET のgh api/api graphqlquery)で,#201 の policy table で許可される操作.テスト
tests/hooks/test_gh_joined_read_only_lines.py(新規,書き込める PATH 要素を gh より前に置いた状態で):gh pr checks 240 -R … 2>&1 | grep -c pass,/dev/nullへの出力,awk | sort | uniq -c,sleep/echo,ls/wc,sed -nの行番号・パターン,base64 -d,PATH 外への gh の出力.cp x later/gh,cp x later/git(Issue の例),mv,ln,install,chmod,export PATH=,PATH の要素へのリダイレクト(gh 自身の出力も),run time のリダイレクト先,ほかのコマンドのecho x > notes.txt・>> .git/config,sort -o/-uo/--compress-program,uniqの出力ファイル,awkの書き込み・system・-f,sed w/-i,base64 -o,printf $OPT PATH /tmp,echo $WORDS,{ echo x; } > later/gh,(echo x) > later/gh,if …; fi > later/gh,{ echo x; } >> .git/config,git status,git log,git commit,python3.cd:github.com のチェックアウトへのcdは allow,github.com 外へは確認(-R付きなら allow),cwd 側が github.com 外なら確認,存在しない先・$DIR・cd -・cd -P・pushd・cd -- -foreign・symlink 越しのcd ..・CDPATH下の相対・環境のcd関数・PATH の相対要素(.,空)は確認.$(...),<(...),ループ,関数,代入の行は確認.cd --,symlink,-P,run time のprintf/echo,まとまりへのリダイレクト).tests/hooks/test_read_only_commands.py(新規):writes_nothingの単体テスト(sort -t -o,sed -e p -e 'w out',awk -v x=1 -F: …,git log/git statusは読み取りに入らない,など).test_gh_targets.py(gh … && gh …は確認,printf x > .git/config; gh pr listは確認など)は変更なしで通過.uv run pytest tests(6220 passed,2 skipped),ruff check,ruff format --check,ty check,deptry,vultureを通過.記録(範囲外・前提・限界)
diff.external,filter,fsmonitor,gpg.program,hook.*,core.alternateRefsCommand),post-index-changeフック,submodule(gitlink),環境(GIT_PAGER,GIT_EXTERNAL_DIFF,GIT_CONFIG_*),promisor remote の遅延 fetch などからプログラムを走らせうる指摘が直すたびに続き,feat(hooks): judge shell function bodies instead of asking for every function #200 と同じく収束しなかった.ユーザー判断(どちらでも可)を受けて親セッションが「外す」を選んだ.git を含む行は従来どおり確認になり,そのための設定検査も削除した.減る件数は通常の PATH で 7 件,書き込める PATH で 6 件./dev/nullと PATH 外を許す)より厳しくした:PATH 外を許すのは gh 自身の出力だけで,gh 以外のコマンドは/dev/nullだけ.書いたファイルが同じ行の後のプログラムの設定になりうるため(自動セキュリティレビューの指摘).cd先・設定が実行時に変わりうる(同じ行のコマンドは書かないが,並行する別プロセスは書ける).feat(agent-runtime): build persistent, isolated, provider-neutral agent infrastructure #181 で扱う.cdは「gh が cwd と各cd先のどれで動いても allow」とした.cd 先だけで判定する Issue の文言より厳しく,cwd の remote が github.com 外の場合はcdしても確認になる(構文からcdの成否・サブシェルを読まずに済ませるため).gh repo clone/run downloadが後の gh の前に置きうるため).書き込める PATH の再生で 30 件がこれで残る.printfの%nは引数名に文字数を代入する(printf x%n PATHで PATH が1になる).書き込める PATH 要素がある環境では誤った allow になりうるので,最初に直す項目(対処案:%nを含むprintfを読み取りに数えない).cd OLD NEWを追跡していない(対処案:オペランドが 2 つ以上なら追わない).~+/~-を run time の先として扱っていない(対処案:literal_words.EXPANDING_TEXTを再利用する).> f単独)を,まとまりへのリダイレクトと同じく扱っていない(対処案:Cmdが引数のある CallExpr でない文のRedirsをすべて書き込みとみなす).awkの比較>,値を取るuniq -f N,一覧に無いsortの option,base64のファイル入力,cd -P.🤖 Generated with Claude Code