Repository navigation
fix(security): ask for every script a non-bash shell receives - #99
Conversation
A shell whose syntax is not bash's (pwsh, powershell, nu, fish, ...) could receive a script through -Command in any letter case, an encoded command, a pipe, a heredoc, or a here-string, and the guard allowed it. Mark such a call as unreviewed: its visible script text is read as bash so a deny rule still wins, and otherwise the call asks. Also deny abbreviated git commit --no-verify (--no-v...) and python -m pip or ensurepip behind the valued -W, -X, and --check-hash-based-pycs options. Refs #87 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
| unreviewed = any(takes_foreign_option(layer) for layer in layers) | ||
| if not scripts and name in SHELLS: | ||
| scripts = [(script, innermost.wrapper_depth + 1) for script in sources.scripts(owner, directories)] | ||
| elif not unreviewed and name in FOREIGN_SHELLS: |
There was a problem hiding this comment.
P2 — The stdin/heredoc branch checks name in FOREIGN_SHELLS, but the -c path uses is_foreign_shell(), which also covers names that look like shells (SHELL_LOOKALIKE). So a shell that matches only by its name, such as ysh or lolsh, still gets no review when its script comes through a pipe, heredoc or <<<. For example, echo 'gh pr merge 76 --merge' | ysh and ysh <<EOF … EOF stay allow. The parser never reads the script and unreviewed is never set. Meanwhile ysh -c '…' now asks. That goes against the PR's goal of asking for "every script a non-bash shell receives". Consider using is_foreign_shell(Path(innermost.arguments[0]).name) here, and add a pipe/heredoc case for a lookalike to test_non_bash_shell_input.py. This is static analysis; I couldn't run the tests in this environment.
There was a problem hiding this comment.
指摘のとおりです.stdin 経路も is_foreign_shell() にそろえ(a032ada),ysh / lolsh のパイプ,ヒアドキュメント,here-string の回帰テストを追加しました.
Review summaryI reviewed this read-only and couldn't run the tests here (running commands needs approval), so the findings come from reading the code. Blocking (P0/P1): none. P2 (1):
Checked and fine:
🤖 Generated with Claude Code |
A shell known only by a name ending in sh (ysh, lolsh) was reviewed for -c scripts but not for a script on a pipe, heredoc, or here-string. Use the same foreign-shell test for both paths. Refs #87 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@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. |
| FOREIGN_COMMAND_OPTION = re.compile(r"-(-command|[A-Za-z]*c[A-Za-z]*)(=.*)?") | ||
| # Options that hand a script over, in any letter case and abbreviation PowerShell accepts: -c, -Command, | ||
| # --commands, --execute, or a short bundle holding c such as tcsh's -fc. | ||
| FOREIGN_COMMAND_OPTION = re.compile(r"-(-commands?|-execute|[a-z]*c[a-z]*)(=.*)?", re.IGNORECASE) |
There was a problem hiding this comment.
P2: fish's long option --init-command is not matched here. The short form -C does match, because of the [a-z]*c[a-z]* branch with IGNORECASE. The long form doesn't: --init-command starts with a second - followed by init, so neither the -commands? branch nor the letters-only branch can match it.
Result: fish --init-command='gh repo delete x --yes', or the same thing without =, gets no script option. Nothing is piped in or redirected, so unreviewed stays false and the inner text is never read as bash. The command is allowed, not denied or asked. fish runs the init command before it reads standard input, so the script does execute. That conflicts with the PR's stated goal that every script a non-bash shell receives is asked for at minimum.
Suggested fix: add -init-command to the alternation, or treat any --*command* long option as a script option. Then add fish --init-command=... and fish --init-command ... to test_a_visible_script_that_matches_a_deny_rule_is_denied.
There was a problem hiding this comment.
指摘のとおりです.--init-command をスクリプトオプションに追加しました(0813ddd).attached と separate の回帰テストを追加し,修正前に allow のまま通ることを確認しています.
Review summaryBlocking findings (P0/P1): 0
Everything else checks out:
Note: this review was done by reading the code only. I couldn't run the test suite in this environment. 🤖 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: a032adac92
ℹ️ 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".
| if FOREIGN_ENCODED_OPTION.fullmatch(argument): | ||
| continue |
There was a problem hiding this comment.
Nushell の CLI リファレンスでは -e は --execute の短縮形ですが,ここでは全外来シェルの -e を PowerShell のエンコード済み入力として扱い,後続の本文を解析せず捨てています.そのため nu -e 'gh repo delete x --yes' は,等価な長形式なら deny になるのに ask までしか到達せず,可視の deny 対象をハード拒否する方針を回避できます.エンコード済みオプションの判定を PowerShell に限定するか,Nu の -e を通常のコマンドオプションとして抽出してください.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
指摘のとおりです.エンコード済みオプションの判定を pwsh / powershell に限定し,nu の -e は --execute として本文を解析するようにしました(0813ddd).nu -e の回帰テストを追加し,修正前に allow のまま通ることを確認しています.
| "(^|[[:space:]])python[0-9.]*([[:space:]]+-[A-Za-z]+)*[[:space:]]+-[A-Za-z]*m[[:space:]]*(pip|ensurepip)([[:space:]]|$)" | ||
| "^git[[:space:]]+commit([[:space:]].*)?[[:space:]]+(--no-v[a-z]*|-[aeiopqsvz]*n[^[:space:]]*)([[:space:]]|$)", | ||
| "(^|[[:space:]])git[[:space:]]+commit([[:space:]].*)?[[:space:]]+(--no-v[a-z]*|-[aeiopqsvz]*n[^[:space:]]*)([[:space:]]|$)", | ||
| "(^|[[:space:]])python[0-9.]*([[:space:]]+(-[A-Za-z]*[WX][[:space:]]+[^[:space:]]+|--check-hash-based-pycs[[:space:]]+[^[:space:]]+|-[A-Za-z]+))*[[:space:]]+-[A-Za-z]*m[[:space:]]*(pip|ensurepip)([[:space:]]|$)" |
There was a problem hiding this comment.
python3 --help が示す -W arg の値は action:message:category:module:lineno 形式で,-X opt にも = を含む値があり,どちらもオプションへ連結できます.しかし末尾の -[A-Za-z]+ は英字だけを許すため,実際にモジュール実行まで到達する python3 -Wignore::DeprecationWarning -m pip install x や python3 -Xutf8=0 -m pip install x がこの deny パターンに一致せず,今回閉じようとしている pip 実行の迂回が残ります.連結された -W/-X の非空白値も明示的に消費してください.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
指摘のとおりです.-W / -X の値が英字以外(コロン,イコール)を含んで連結される形も deny パターンに加えました(0813ddd).-Wignore::DeprecationWarning,-Xutf8=0,-IXutf8=0 の回帰テストを追加し,修正前に allow のまま通ることを確認しています.
…n -W/-X values Treat the encoded-script options as PowerShell's only, so nu -e is read as the script it is. Add fish's --init-command to the script options. Let a python -W or -X value attach to its option with any characters, as in -Wignore::DeprecationWarning and -Xutf8=0. Refs #87 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
| FOREIGN_COMMAND_OPTION = re.compile(r"-(-command|[A-Za-z]*c[A-Za-z]*)(=.*)?") | ||
| # Options that hand a script over, in any letter case and abbreviation PowerShell accepts: -c, -Command, | ||
| # --commands, nu's -e and --execute, fish's --init-command, or a short bundle holding c such as tcsh's -fc. | ||
| FOREIGN_COMMAND_OPTION = re.compile(r"-(-commands?|-execute|-init-command|e|[a-z]*c[a-z]*)(=.*)?", re.IGNORECASE) |
There was a problem hiding this comment.
P1: PowerShell options with a -- prefix get past this check.
pwsh's CommandLineParameterParser removes a second leading dash ("agnostic wrt specifying - or --"), so pwsh --c '…', pwsh --co '…', pwsh --ec <b64> and pwsh --encodedcommand <b64> behave the same as their single-dash forms. Neither regex matches them:
FOREIGN_COMMAND_OPTIONonly allows--before the literal wordscommand(s),executeandinit-command. Its[a-z]*c[a-z]*branch can't start with a dash.POWERSHELL_ENCODED_OPTIONonly matches one dash.
With no option found and no stdin, parse falls through to sources.scripts(...), which returns []. So unreviewed stays False and the hook returns allow:
pwsh --c 'gh repo delete x --yes'→ allow (should be deny)pwsh --encodedcommand SQBHAGUA...→ allow (should be ask)
This bypasses the guarantee this PR adds ("every script a non-bash shell receives asks"). A fix: for POWERSHELLS, strip one extra leading - (and possibly a leading /, which the same parser also accepts) before matching. Then add --c, --ec and --encodedcommand cases to test_non_bash_shell_input.py.
There was a problem hiding this comment.
指摘のとおりです.PowerShell のオプションだけ,先頭の -- と / を - にそろえてから判定するようにしました(ed615b6).--c,--encodedcommand,--ec,/c,/e,/Command の回帰テストを追加し,修正前に allow のまま通ることを確認しています.
Review summary1 blocking finding (P1)
Everything else looks sound:
How this was checked: by reading the code only. I couldn't run the guard in this environment, so the bypass verdicts come from tracing the code by hand. 🤖 Generated with Claude Code |
PowerShell accepts --name and /name as -name, so pwsh --c, --encodedcommand and /c handed a script over unseen. Read those spellings as the one-dash option before matching. Refs #87 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0813ddd2ff
ℹ️ 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".
| while operands and arguments[operands[0]].startswith("-"): | ||
| operands.pop(0) |
There was a problem hiding this comment.
PowerShell の
-Command 後の先頭オペランドを捨てない
pwsh -Command '-not $false; gh repo delete x --yes' のように PowerShell コードが - で始まる場合,このループがコマンド文字列全体をオプションとして削除するため,内側の gh repo delete が解析されず deny ではなく ask になります.PowerShell では -Command が最後のホストパラメーターであり,その後の引数はすべて実行するコマンドの一部です(Microsoft の CLI リファレンス).ホストオプションとして読み飛ばせるのは -Command より前だけなので,後続の - 始まりのコードもスクリプトとして保持してください.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
方針を変えました(47eebb4).既知の非 bash シェルは,呼び出し方によらずシェル名だけで最低 ask にします.本文の bash 解析は deny へ上げる補助で,ここは best-effort です.-Command 直後が - で始まるコードは,ask の下限は保たれたまま deny に届かない場合があり,この PR では対象外とします.
| elif not unreviewed and is_foreign_shell(name): | ||
| scripts = [(script, innermost.wrapper_depth + 1) for script in sources.scripts(owner, directories)] | ||
| unreviewed = bool(scripts) |
There was a problem hiding this comment.
pwsh -Command - の標準入力も deny 検査する
echo 'gh repo delete x --yes' | pwsh -Command - では -Command により unreviewed が先に真になるため,この分岐が sources.scripts(...) を呼ばず,パイプ内の可視スクリプトが解析されないまま ask になります.PowerShell の公式仕様では -Command - は標準入力からコマンドを読みます(Microsoft の CLI リファレンス).この形式でも入力ソースを抽出しないと,今回維持するはずの hard deny を回避できます.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
指摘のとおり,標準入力を読まない経路でした.47eebb4 で,名前で ask にする方針に変え,標準入力・ヒアドキュメント・here-string の本文は常に読むようにしました.echo ... | pwsh -Command - が deny になる回帰テストを追加し,通ることを確認しています.
| if unreviewed: | ||
| layers[-1] = replace(innermost, unreviewed=True) | ||
| commands += layers | ||
| commands += [nested for script, nested_depth in scripts for nested in parse(script, nested_depth, directories)] |
There was a problem hiding this comment.
Bash で解析不能な外来構文でも deny 対象を検出する
fish -c 'if true; gh repo delete x --yes; end' のような入力では,これは公式に記載された有効な fish の if … end 構文ですが(fish の if リファレンス),この行で本文全体を Bash として再帰解析すると構文エラーになり,外側の処理が ask を返して可視の gh repo delete を deny できません.外来シェル固有の制御構文を加えるだけで hard deny を迂回できるため,Bash の構文解析が失敗した場合にも可視テキスト中の禁止対象を保守的に検出する必要があります.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
方針を変えました(47eebb4).既知の非 bash シェルは,シェル名だけで最低 ask にします.deny は,本文が bash として読めるときの best-effort です.fish の if ... end のように bash で読めない本文は ask のままで,deny には届きません.ask の下限が保たれることを回帰テスト(fish の呼び出しがすべて ask)で確認しています.これは意図した仕様として PR 本文に明記しました.
|
@codex review |
| return shell in FOREIGN_SHELLS or (shell not in SHELLS and SHELL_LOOKALIKE.fullmatch(shell) is not None) | ||
|
|
||
|
|
||
| def option_form(arguments: tuple[str, ...], argument: str) -> str: |
There was a problem hiding this comment.
P2 — PowerShell's command-line parser also accepts Unicode dashes (en dash –, em dash —, horizontal bar) as the option prefix, the same way it accepts / and --. option_form only rewrites / and --, and FOREIGN_COMMAND_OPTION / POWERSHELL_ENCODED_OPTION both need an ASCII -. So pwsh –Command 'gh pr merge 76 --merge' or pwsh —e <base64> never gets marked unreviewed. With no stdin feed it falls through to allow, which skips the ask floor this PR is meant to guarantee. Suggest also converting a leading –—― to - for POWERSHELLS (or asking on any PowerShell argument that starts with one), and adding a regression case.
Caveat: I couldn't run the guard in this environment, so this comes from reading the code plus PowerShell's documented parsing (CharExtensions.IsDash), not from an executed test.
There was a problem hiding this comment.
指摘のとおりです.47eebb4 で,PowerShell は呼び出し方(Unicode のダッシュを含む)によらず,シェル名だけで最低 ask にしました.–Command と —e の回帰テストを追加し,通ることを確認しています.
|
Review summary (read-only) Blocking (P0/P1): 0
Other things I checked that look fine:
Minor and not filed: Tests: the new behaviour is well covered by |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed615b6d7c
ℹ️ 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".
| FOREIGN_SHELLS = frozenset( | ||
| {"csh", "elvish", "es", "fish", "nu", "nushell", "powershell", "pwsh", "rc", "tcsh", "xonsh"} | ||
| ) |
There was a problem hiding this comment.
PowerShell Preview を使用する環境では,公式の起動コマンドは pwsh-preview ですが,Microsoft のインストール手順にもこの名前が明記されています.この集合は pwsh しか含まず,pwsh-preview は sh で終わる lookalike にも該当しないため,pwsh-preview -Command 'gh repo delete x --yes' の引用された本文は再帰解析も unreviewed 設定もされず,hard deny が allow まで迂回されます.Preview の実行名も同じ PowerShell として正規化してください.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
指摘のとおりです.pwsh-preview を非 bash シェルの名前に加えました(47eebb4).あわせて ysh も加え,名前だけで最低 ask にしています.pwsh-preview の回帰テストを追加し,通ることを確認しています.
Chasing each way a script can reach a non-bash shell left a new bypass with every review: option spellings, Unicode dashes, executable names. Ask for any invocation of a listed shell (fish, nu, pwsh, ysh, ...) by its name alone. Its visible script text is still read as bash, only to raise the verdict to deny when a deny rule matches. This deliberately turns allows such as fish --version into asks. Names that merely end in sh keep asking only when handed a script. Refs #87 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 47eebb4328
ℹ️ 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".
| # Options that hand a script over, in any letter case and abbreviation PowerShell accepts: -c, -Command, | ||
| # --commands, nu's -e and --execute, fish's --init-command, or a short bundle holding c such as tcsh's -fc. | ||
| FOREIGN_COMMAND_OPTION = re.compile(r"-(-commands?|-execute|-init-command|e|[a-z]*c[a-z]*)(=.*)?", re.IGNORECASE) | ||
| POWERSHELLS = frozenset({"powershell", "pwsh"}) |
There was a problem hiding this comment.
pwsh-preview を PowerShell のオプション規則に含める
pwsh-preview /Command 'gh repo delete x --yes' のようにスラッシュ形式を使う場合,pwsh-preview は FOREIGN_SHELLS には追加された一方でこの集合に含まれないため,option_form() が /Command を正規化せず,本文を抽出できません.その結果,tests/hooks/test_non_bash_shell_input.py:43 で通常の PowerShell に保証している deny ではなく外側の ask で止まり,禁止コマンドを承認可能にしてしまいます.以前の pwsh-preview 指摘への修正後も残る新しい根拠は,この PowerShell 専用集合から Preview 名だけが欠けており,同じく pwsh-preview7 でも foreign_option_indexes() が空になる点です.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
指摘のとおりです.pwsh-preview を PowerShell のオプション規則の集合にも加えました(85d4fed).バージョン付きの名前(pwsh-preview7)は,既存のバージョン接尾辞の除去で同じ集合に当たります.pwsh-preview /Command と pwsh-preview7 --c の回帰テストを追加し,修正前に ask で止まり deny に届かないことを確認しています.
pwsh-preview was listed as a non-bash shell but not as a PowerShell, so its /Command and --c spellings were not read as script options and its visible script could not escalate to deny. Refs #87 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
| return [arguments[script]] | ||
|
|
||
|
|
||
| def is_foreign_shell(executable: str) -> bool: |
There was a problem hiding this comment.
P2 The name-based ask floor is case-sensitive, but the default macOS filesystem (APFS) is not. FOREIGN_SHELLS membership and SHELL_LOOKALIKE ([a-z0-9_-]*sh, no IGNORECASE) only match lower-case names, and shell_name doesn't normalise case.
On macOS, which this repo targets via flake.nix/darwin, PWSH -Command '…' or Fish -c '…' resolves to the real shell through PATH lookup. The guard doesn't recognise either as a foreign shell, so unreviewed stays False and the call is allowed. That breaks the PR's stated guarantee that these shells ask however they're invoked. Known shells such as BASH -c already have the same issue, so this isn't new to the PR. Still, this PR's whole point is a name-only floor that can't be bypassed.
Suggested fix: compare shell_name(executable).lower() (or casefold) in is_foreign_shell and at line 214. Add a test row such as PWSH -c 'ls' → ask.
There was a problem hiding this comment.
指摘のとおりです.shell_name で大文字小文字をそろえました(57b10ab).PWSH,Fish,NU,FISH -c,BASH -c の回帰テストを追加し,修正前に allow のまま通る,または deny に届かないことを確認しています.BASH -c の穴も同時に塞がります.
| "(^|[[:space:]])git[[:space:]]+commit([[:space:]].*)?[[:space:]]+(--no-verify|-[aeiopqsvz]*n[^[:space:]]*)([[:space:]]|$)", | ||
| "(^|[[:space:]])python[0-9.]*([[:space:]]+-[A-Za-z]+)*[[:space:]]+-[A-Za-z]*m[[:space:]]*(pip|ensurepip)([[:space:]]|$)" | ||
| "^git[[:space:]]+commit([[:space:]].*)?[[:space:]]+(--no-v[a-z]*|-[aeiopqsvz]*n[^[:space:]]*)([[:space:]]|$)", | ||
| "(^|[[:space:]])git[[:space:]]+commit([[:space:]].*)?[[:space:]]+(--no-v[a-z]*|-[aeiopqsvz]*n[^[:space:]]*)([[:space:]]|$)", |
There was a problem hiding this comment.
P3 --no-v[a-z]* also matches git commit --no-verbose, a valid and harmless option (the negation of -v/--verbose), so that command is now denied. Git treats the short prefixes --no-v and --no-ver as ambiguous between verify and verbose, so only --no-veri… can actually reach --no-verify.
Narrowing the pattern to --no-veri[a-z]* (or explicitly excluding --no-verbose) would keep the bypass blocked without the false positive. It's worth adding git commit --no-verbose -m x to test_the_wider_option_patterns_keep_ordinary_forms_allowed.
There was a problem hiding this comment.
指摘のとおりです.パターンを --no-veri[a-z]* に狭めました(57b10ab).git は --no-v と --no-ver を verify と verbose のどちらにも取れるとして拒否するため,実行できません.git commit --no-verbose -m x が allow になる回帰テストを追加し,修正前に deny になることを確認しています.
Review summaryI found no blocking issues (no P0 or P1). The design is sound. A foreign shell always gets an Findings (posted inline):
I reviewed the code by reading it only; I couldn't run the probes in this environment. 🤖 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: 85d4fed3bd
ℹ️ 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".
| if not scripts and (name in SHELLS or is_foreign_shell(name)): | ||
| scripts = [(script, innermost.wrapper_depth + 1) for script in sources.scripts(owner, directories)] |
There was a problem hiding this comment.
fish -C 'echo init' script.fish のように初期化コマンドと本体スクリプトを併用すると,-C から scripts が生成済みなのでこの条件が偽になり,sources.scripts(...) が本体ファイルを読みません.fish の公式 CLI リファレンスも,-C は本体より先に実行されるものであり,初期化後にファイルを実行する例を示しています(fish invocation documentation).したがって script.fish 内の gh repo delete x --yes などは再帰解析されず,hard deny が承認可能な ask に弱まるため,オプション由来のスクリプトがあっても併存する入力元を検査してください.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
標準入力側は指摘のとおりなので,オプションのスクリプトと併せて標準入力・ヒアドキュメントの本文も読むように直しました(57b10ab).echo ... | fish -C に対する deny の回帰テストを追加し,修正前に ask で止まることを確認しています.一方,fish script.fish のようにスクリプトファイルを引数で渡す形は,この PR の対象外です(PR 本文に記載).ファイルの内容は読まず,ask の下限は保たれるため,deny に届かないだけです.
| if any(command.dynamic[position] for position in operands): | ||
| raise UnsupportedSyntax(f"{arguments[0]} running a computed script requires explicit review", "wrapper") | ||
| if operands: | ||
| scripts.append(" ".join(arguments[position] for position in operands)) |
There was a problem hiding this comment.
fish -c 'printf "%s\n" $argv;' 'gh repo delete x --yes' では,fish が実行する本文は第1オペランドだけで,後続値は $argv ですが,ここでは全オペランドを連結するため,検査側では gh repo delete が別コマンドとして現れて誤って hard deny されます.この引数規則は fish の公式 CLI リファレンスにも明記されています(fish invocation documentation).全語を結合する PowerShell の規則を他の外来シェルへ共用せず,fish ではコマンド直後の1語だけを本文として抽出してください.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
指摘のとおりです.全語の連結は PowerShell だけにして,ほかのシェルは直後の 1 語だけを本文にしました(57b10ab).fish -c の後続引数($argv)を本文として読まない回帰テストを追加し,修正前に deny になることを確認しています.
…ipt reading - Fold the case of a program name before judging it, since PATH lookup on a case-insensitive filesystem runs PWSH as pwsh (this also covers BASH). - Read a foreign shell's input beside its option script (fish -C with a script on the pipe); an unreadable input keeps the call at ask. - Read only PowerShell's words after -Command as one script; other shells take the first word, the rest being positional arguments. - Narrow --no-v to --no-veri: git rejects --no-v and --no-ver as ambiguous, and --no-verbose is a harmless option. Refs #87 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
|
@codex review |
|
Review summary (read-only) I found no P0–P3 issues worth blocking or flagging. What I checked:
Note (outside this PR's scope): case folding applies only to shell names. Wrapper names ( I could not execute tests in this environment, so this review is from a static reading of the code. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57b10ab969
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57b10ab969
ℹ️ 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".
| scripts = [(script, layer.wrapper_depth + 1) for layer in layers for script in shell_scripts(layer)] | ||
| if not scripts and shell_name(Path(innermost.arguments[0]).name) in SHELLS: | ||
| scripts = [(script, innermost.wrapper_depth + 1) for script in sources.scripts(owner, directories)] | ||
| unreviewed = name in FOREIGN_SHELLS or any(takes_foreign_option(layer) for layer in layers) |
There was a problem hiding this comment.
ラッパー名もシェル名と同様に case-fold してください
大文字小文字を区別しない macOS ボリュームでは NOHUP fish -c 'gh repo delete x --yes' や ENV A=1 PWSH -Command ... も実際のラッパーと外来シェルを起動しますが,wrapped_index() は agents/hooks/lib/shell_wrappers.py:87-89 でラッパー名を完全一致させるため展開されません.その結果,ここでは innermost が NOHUP のままで unreviewed が立たず,引用された deny 対象も解析されないため,今回保証するはずの最低 ask を allow まで迂回できます.
Useful? React with 👍 / 👎.
| index | ||
| for index, argument in enumerate(arguments[1:], 1) | ||
| if FOREIGN_COMMAND_OPTION.fullmatch(option_form(arguments, argument)) or is_encoded_option(arguments, argument) |
There was a problem hiding this comment.
fish の位置引数を再度オプションとして走査しないでください
fish -c 'printf "%s\n" $argv' --command 'gh repo delete x --yes' では --command 以降も単なる $argv ですが,この全引数走査はそれを第2のスクリプトオプションとして拾い,後続文字列を実行本文として解析して誤って hard deny します.fish の公式 CLI リファレンスでも -c COMMAND 後の追加値は位置引数として $argv に渡すと定義されています.以前の位置引数指摘への修正後も,オプション形の位置引数だけは再解釈されるという新しい根拠が残っています.
Useful? React with 👍 / 👎.
🤖 I have created a release *beep* *boop* --- ## 0.1.0 (2026-11-10) ### Features * add devin provider to hooks.json with hook adapter (furedea/dotfiles[#136](#136)) ([5bc5550](5bc5550)) * add git-commit-split skill ([35f4e16](35f4e16)) * add Hermes Agent and pi hook providers (furedea/dotfiles[#138](#138)) ([ed3a774](ed3a774)) * add lock-settings, report-doc-conflict, and report-hook-block skills ([35b8585](35b8585)) * **agents:** add Rust style skill ([a82df41](a82df41)) * **agents:** allow cd, sed, awk, xargs, cp, and mv under the sandbox (furedea/dotfiles[#165](#165)) ([5783f87](5783f87)) * **agents:** bootstrap the harness on servers without Nix ([80a0f9b](80a0f9b)) * **agents:** chain git add, status, commit, and push outside the sandbox (furedea/dotfiles[#169](#169)) ([dd5a05c](dd5a05c)) * **agents:** Codex implements, Claude reviews, and lanes clean up opened workspaces (furedea/dotfiles[#266](#266)) ([c9a3fd9](c9a3fd9)) * **agents:** generate hook settings from nix ([b20d592](b20d592)) * **agents:** hand approved lanes to Herdr task worktree sessions (furedea/dotfiles[#184](#184)) ([58a591f](58a591f)) * **agents:** own personal agent source (furedea/dotfiles[#52](#52)) ([51060b1](51060b1)) * **agents:** permit commands by reversibility (furedea/dotfiles[#124](#124)) ([bb96256](bb96256)) * **agents:** run agent git inside the sandbox with unsigned commits (furedea/dotfiles[#172](#172)) ([1492f3e](1492f3e)) * **agents:** start Herdr Claude lanes on Sonnet at medium effort (furedea/dotfiles[#257](#257)) ([3caf8d5](3caf8d5)) * **agents:** write PR bodies inline and close lanes' parent workspaces (furedea/dotfiles[#211](#211)) ([8c6df4e](8c6df4e)) * **claude:** close the sandbox escape and reach the Nix daemon inside (furedea/dotfiles[#191](#191)) ([b61f2ac](b61f2ac)) * **claude:** let Go CLIs verify TLS inside the sandbox (furedea/dotfiles[#167](#167)) ([282b3d2](282b3d2)) * **claude:** let sandboxed commands listen on local ports (furedea/dotfiles[#206](#206)) ([36c09d2](36c09d2)) * **claude:** run the Codex plugin companion outside the sandbox (furedea/dotfiles[#232](#232)) ([0255159](0255159)) * **codex:** let Codex write, test, and deliver inside the sandbox (furedea/dotfiles[#200](#200)) ([33a0a82](33a0a82)) * compose Herdr and Moshi agent hooks (furedea/dotfiles[#33](#33)) ([4951ee8](4951ee8)) * **dsh:** add the dsh hook adapter ([#101](#101)) ([db86f57](db86f57)) * **git-commit-split:** accept mode from slash-command argument ([10c3ef7](10c3ef7)) * **git-commit-split:** modularize commit splitting workflow with branch ([bab6f19](bab6f19)) * **github:** add repository creation script ([1a7910b](1a7910b)) * **hermes:** use Apple Mail for mail access (furedea/dotfiles[#69](#69)) ([94268fa](94268fa)) * **hooks:** add related test selection rules ([2aca101](2aca101)) * **hooks:** add shared audit and command guard hooks ([6ab33b5](6ab33b5)) * **hooks:** allow read-only local curl diagnostics and log syntax ask kinds (furedea/dotfiles[#287](#287)) ([83cd643](83cd643)) * **hooks:** ask before an agent adds a lint suppression (furedea/dotfiles[#214](#214)) ([b767665](b767665)) * **hooks:** ask only for effects that escape the sandbox (furedea/dotfiles[#163](#163)) ([21409a5](21409a5)) * **hooks:** block destructive non-push git operations ([cc02cb4](cc02cb4)) * **hooks:** escalate unrecognized command forms to a prompt (furedea/dotfiles[#159](#159)) ([e30de17](e30de17)) * **hooks:** fast-forward main after cleaning up merged lanes (furedea/dotfiles[#210](#210)) ([f8a60af](f8a60af)) * **hooks:** honor project allow rules only from trusted owners ([#33](#33)) ([305d391](305d391)) * **hooks:** improve lint-format feedback across providers ([8a512f6](8a512f6)) * **hooks:** judge heredocs, substitutions, loops, and redirections structurally (furedea/dotfiles[#175](#175)) ([9276283](9276283)) * **hooks:** let sessions lock flake inputs and close their own lanes (furedea/dotfiles[#208](#208)) ([f109b49](f109b49)) * **hooks:** let the parent run cleanup_worktrees.py after merge (furedea/dotfiles[#300](#300)) ([fc44c74](fc44c74)) * **hooks:** remove merged task worktrees and branches at session start (furedea/dotfiles[#185](#185)) ([2701e0b](2701e0b)) * **hooks:** replay recent commands through the hooks (furedea/dotfiles[#199](#199)) ([2ed4984](2ed4984)) * **hooks:** report ast-grep rule findings after an edit ([#119](#119)) ([ff91d8c](ff91d8c)) * **hooks:** review only commands that reach past the sandbox (furedea/dotfiles[#178](#178)) ([40c97da](40c97da)) * **hooks:** run zizmor offline after workflow edits (furedea/dotfiles[#295](#295)) ([79b66a6](79b66a6)) * **hooks:** scan with the shared ast-grep rules shipped beside the hooks ([#121](#121)) ([35a9270](35a9270)) * **hooks:** support Go projects in formatting, verification, and permissions ([#57](#57)) ([5506f3c](5506f3c)) * **hooks:** verification selection, unified patch input, formatter/linter ordering (furedea/dotfiles[#144](#144)) ([99a825b](99a825b)) * **lint:** add the first ten ast-grep rules and drop the prose they replace ([#117](#117)) ([c235eb5](c235eb5)) * **nix:** expose the plain agents path as passthru.tree of agent-source ([#94](#94)) ([63632e4](63632e4)) * **security:** add a program_path option that pins a rule's program to one absolute path ([#61](#61)) ([d629ca9](d629ca9)) * **security:** allow agent-browser and agent-desktop except named risky forms ([#63](#63)) ([8dc8da5](8dc8da5)) * **security:** allow cargo caches, crates.io, and OSV in the sandbox ([#60](#60)) ([2f29423](2f29423)) * **security:** allow Go caches and module hosts in the sandbox ([#58](#58)) ([4b3a35c](4b3a35c)) * **security:** ask for every docker form the allowlist does not list ([#54](#54)) ([764374f](764374f)) * **security:** deny the 1Password CLI and keep the Codex login in the keyring ([#52](#52)) ([0580825](0580825)) * **skill-auditor:** support Codex audit workflow ([0d88c3f](0d88c3f)) * **skills:** add measurement-evidence and change-type evidence to tsdd ([#70](#70)) ([85714b5](85714b5)) * **skills:** clarify names and add Herdr delegation (furedea/dotfiles[#127](#127)) ([e6576ba](e6576ba)) * **skill:** skill-auditor by nyosegawa/skills/skill-auditor ([f191132](f191132)) * **skills:** render provider-specific SKILL.md frontmatter ([44325e5](44325e5)) * **statusline:** render the status on one line (furedea/dotfiles[#110](#110)) ([03ad85e](03ad85e)) * update bash-style skill instructions ([9ab1d65](9ab1d65)) * update github-ci-init skill templates ([d238f51](d238f51)) * verify agent changes through native hooks (furedea/dotfiles[#106](#106)) ([923b0ae](923b0ae)) ### Bug Fixes * **agents:** accept generated command permissions (furedea/dotfiles[#66](#66)) ([0af9650](0af9650)) * **agents:** allow gh api reads that pass --allow-escape-sequences (furedea/dotfiles[#265](#265)) ([e732939](e732939)) * **agents:** apply harness review findings (furedea/dotfiles[#149](#149)) ([c8a51d7](c8a51d7)) * **agents:** cap Codex session-end timeout ([2f29a7e](2f29a7e)) * **agents:** deny codex-companion calls the sandbox exclusion cannot match (furedea/dotfiles[#269](#269)) ([25518ab](25518ab)) * **agents:** harden hooks and separate workflow responsibilities (furedea/dotfiles[#128](#128)) ([7e508c4](7e508c4)) * **agents:** let pnpm fetch from the npm registry inside the sandbox (furedea/dotfiles[#222](#222)) ([ac114e8](ac114e8)) * **agents:** let the forbidden rule admit Sonnet lane arguments (furedea/dotfiles[#259](#259)) ([f1b29a9](f1b29a9)) * **agents:** make the bootstrap hint work for POSIX login shells ([c2667fa](c2667fa)) * **agents:** stop asking for commands the hooks can prove safe (furedea/dotfiles[#242](#242)) ([a93d241](a93d241)) * **agents:** wait for hook state locks instead of failing with EAGAIN (furedea/dotfiles[#285](#285)) ([673c108](673c108)) * allow secret scanner hook files ([bca4207](bca4207)) * **bootstrap:** give Codex the agent GitHub token settings and run the bootstrap in CI ([#21](#21)) ([25de080](25de080)) * **bootstrap:** keep Neovim's fallback nvim.log out of the working directory ([#43](#43)) ([3c9fc5c](3c9fc5c)) * **bootstrap:** make the server bootstrap behave like the Nix hosts ([#15](#15)) ([4554dec](4554dec)) * **bootstrap:** print actionable profile and legacy-file messages only when needed ([#49](#49)) ([1918254](1918254)) * **bootstrap:** target the login profile bash actually reads ([#50](#50)) ([0dae5bf](0dae5bf)) * **bootstrap:** verify downloaded tools against pinned checksums ([#111](#111)) ([1744df3](1744df3)) * **ci:** install the locked agent-harness instead of reading it from the flake ([bc2395b](bc2395b)) * **ci:** provide the shell format config and locked JavaScript tools ([dd59634](dd59634)) * **claude:** trust only the CA store bundled with Claude Code (furedea/dotfiles[#284](#284)) ([34be271](34be271)) * **codex:** fall back to auth.json when no keyring is available ([#62](#62)) ([79b6ceb](79b6ceb)) * correct agent tooling and Hister activation (furedea/dotfiles[#85](#85)) ([4bab065](4bab065)) * honor pytest testpaths and bootstrap bats on servers (furedea/dotfiles[#116](#116)) ([b17b59e](b17b59e)) * **hooks:** allow double quoted commit messages ([fc4afd4](fc4afd4)) * **hooks:** bound curl -o, -d and -H in the localhost rule (furedea/dotfiles[#291](#291)) ([7c9db8a](7c9db8a)) * **hooks:** close shell-syntax bypasses of the guard hooks ([#11](#11)) ([c6aacdf](c6aacdf)) * **hooks:** close the guard contract gaps from [#11](#11) review ([#31](#31)) ([db318db](db318db)) * **hooks:** deny codex-companion calls whose text holds a dollar sign or backtick (furedea/dotfiles[#290](#290)) ([f37c317](f37c317)) * **hooks:** find GNU grep on PATH instead of the first grep (furedea/dotfiles[#193](#193)) ([99ba317](99ba317)) * **hooks:** format without dotfiles-installed dprint and prettier configs ([#16](#16)) ([db21f55](db21f55)) * **hooks:** ignore git-ignored sources when judging a project removed ([#22](#22)) ([97c6b93](97c6b93)) * **hooks:** ignore prose arguments when matching forbidden patterns (furedea/dotfiles[#189](#189)) ([d2049d6](d2049d6)) * **hooks:** judge each command as one line with any grep (furedea/dotfiles[#196](#196)) ([202f937](202f937)) * **hooks:** keep merged worktrees holding non-regenerable ignored files ([#29](#29)) ([ac03cfa](ac03cfa)) * **hooks:** keep the first grep when no GNU grep is on PATH (furedea/dotfiles[#195](#195)) ([a0e6a2f](a0e6a2f)) * **hooks:** keep the verification snapshot from locking out symlinked or large worktrees ([#66](#66)) ([7d13f0e](7d13f0e)) * **hooks:** let cleanup_worktrees remove Claude Code session files ([#36](#36)) ([0a910bc](0a910bc)) * **hooks:** let cleanup_worktrees tests choose the untrusted locations (furedea/dotfiles[#306](#306)) ([e82980e](e82980e)) * **hooks:** let GitHub API reads take an unquoted jq filter (furedea/dotfiles[#198](#198)) ([5b6210a](5b6210a)) * **hooks:** make stop verification reliable (furedea/dotfiles[#81](#81)) ([04a33dd](04a33dd)) * **hooks:** preserve verification evidence (furedea/dotfiles[#87](#87)) ([4b5b9c2](4b5b9c2)) * **hooks:** redirect sandbox-failing Git forms and drop covered prompts (furedea/dotfiles[#180](#180)) ([34e39a7](34e39a7)) * **hooks:** resolve Rust integration test targets inside tests subdirectories (furedea/dotfiles[#304](#304)) ([2ccf547](2ccf547)) * **hooks:** respect project formatters and bound diagnostics (furedea/dotfiles[#131](#131)) ([30e83cf](30e83cf)) * **hooks:** scope generic secret regex to quoted values ([fc09292](fc09292)) * **hooks:** silence successful hook execution ([795d8f0](795d8f0)) * **hooks:** skip JavaScript triggers in projects without JavaScript tests (furedea/dotfiles[#161](#161)) ([dc80e28](dc80e28)) * **hooks:** skip verification for a language whose project was removed ([#6](#6)) ([4a9f325](4a9f325)) * **hooks:** support relocated harness assets (furedea/dotfiles[#82](#82)) ([59057bc](59057bc)) * **hooks:** treat any gh api call without write flags as a read (furedea/dotfiles[#201](#201)) ([3ecb215](3ecb215)) * **hooks:** treat glob characters inside double quotes as literal for literal_words rules ([#41](#41)) ([174a7f9](174a7f9)) * **hooks:** use agent-neutral guidance ([37153ce](37153ce)) * improve agent notifications and session setup (furedea/dotfiles[#92](#92)) ([9bf2349](9bf2349)) * load secret patterns from hook directory ([ca465ef](ca465ef)) * migrate dotfiles path to ghq convention ([faff774](faff774)) * **nix:** build CPython 3.15.2 for the ssl eMudhra denylist ([#113](#113)) ([faba045](faba045)) * **nix:** default editor to Neovim (furedea/dotfiles[#105](#105)) ([2a9a22a](2a9a22a)) * resolve hook directory from bash source ([c6ca454](c6ca454)) * restore SSH signing and reliable Bats verification (furedea/dotfiles[#91](#91)) ([891adce](891adce)) * **sandbox:** deny writes to every repository's git hooks and config (furedea/dotfiles[#298](#298)) ([1941513](1941513)) * **sandbox:** match the Codex plugin script under any numeric version (furedea/dotfiles[#302](#302)) ([a49ddc3](a49ddc3)) * **security:** allow the Go checksum tree head and vulnerability database in the sandbox ([#59](#59)) ([af6e158](af6e158)) * **security:** ask for every script a non-bash shell receives ([#99](#99)) ([f88f8fd](f88f8fd)) * **security:** close quoted-argument and wrapper bypasses in the command guard ([#76](#76)) ([5f72757](5f72757)) * **security:** close the remaining command guard bypasses ([#83](#83)) ([0387739](0387739)) * **security:** decide not-a-fork for project rules on hosts without gh ([#67](#67)) ([acaa758](acaa758)) * **security:** keep agent-browser and agent-desktop calls inside the sandbox ([#64](#64)) ([3f2d578](3f2d578)) * **security:** read more of the scripts handed to fish and PowerShell for deny rules ([#110](#110)) ([2c652bb](2c652bb)) * **skills:** audit Codex skill observations (furedea/dotfiles[#88](#88)) ([f429967](f429967)) * **skills:** refine routing triggers from audit ([cef3b9c](cef3b9c)) * **tests:** make git test wrappers exec the real git binary (furedea/dotfiles[#310](#310)) ([893c405](893c405)) * **tests:** stop shifting past the codex wrapper arguments ([eb0f6d7](eb0f6d7)) ### Performance Improvements * **hooks:** evaluate policy regexes with one grep and run pytest in parallel (furedea/dotfiles[#125](#125)) ([ce80ea3](ce80ea3)) --- 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>
概要
bash 系以外のシェル(
pwsh,powershell,pwsh-preview,nu,nushell,fish,ysh,csh,tcsh,rc,es,elvish,xonsh)は,どう呼んでも最低ask(シェル名だけで判定).スクリプト本文が見えるときは bash として読み,deny ルールに当たればdenyに上げる.あわせて,追加表の 2 件(git commit --no-verif,python3 -W/-X ... -m pip)を deny にした.方針:シェルごとに構文やオプション綴りを解釈しない.5 回のレビューで毎回新しい迂回(大文字小文字,
--,/,Unicode のダッシュ,実行名)が出たため,オプションや入力の経路で判定する方式をやめ,名前だけで ask の下限を保証する(Issue の「決めること」に対する決定).本文の解析は deny へ上げる補助で,読めなくても ask の下限は変わらない.計画コメント
変更前後
pwsh -Command '<ask 対象>'(大文字小文字,--c,/c,Unicode のダッシュを含む)pwsh -e <base64>,-ec,-EncodedCommandnu --commands 'gh repo delete x --yes'echo 'gh repo delete x --yes' | fishfish <<EOF…EOF(deny 対象の本文)fish --version,pwsh --help,nu script.nu,引数なしなど)lolsh -c '…'のように名前がshで終わるだけの未知プログラム-cのみ)lolsh --help)は allow のままrun.sh,ssh,echo fish,man fishgit commit --no-verif -m xpython3 -W ignore -m pip install x,-X dev,-Wignore::X,-Xutf8=0fish -c 'gh repo delete x --yes'(既存)検証
tests/hooks/test_non_bash_shell_input.py)が,修正前に allow のまま通る,または ask で止まり deny に届かない理由で失敗することを確認fish -c,nu -c,csh -c,lolsh -cで本文が deny 対象のものを ask から deny へ範囲と前提
shell_syntax.py(Command.unreviewed,外来シェルの判定とスクリプト抽出),foreign_shell_policy.py(新規,ask の判定),guard_command.py,forbidden_commands.jsonif … end,PowerShell 固有の構文)は ask のまま.下限(ask)は常に保たれるshで終わるだけの未知プログラム(SHELL_LOOKALIKE)は,無害な呼び出しまで ask にしないため,スクリプトを渡す書き方(-c系,パイプ,ヒアドキュメント,here-string)のときだけ ask--no-veri[a-z]*は実在しない綴りも deny にする(git ではエラーになるだけ).--no-v,--no-verは git が verify と verbose のどちらにも取れるとして拒否し,--no-verboseは無害なので,deny にしないPWSHがpwshとして実行されるため).BASH -cの穴も同時に塞がるfish script.fish)は,本文を読まない.ask の下限は保たれ,deny に届かないだけecho '<deny 対象>' | fish -c catは deny になる).シェルごとに標準入力の扱いが違う(fish -cは読まず,fish -Cやpwsh -Command -は読む)ため,読みすぎて誤って deny になる側(安全側)に倒した.読まないと deny が ask に弱まる.レビューの指摘(P2)に対する反論として記録if … end,スクリプトファイル引数,PowerShell の-始まりのコード)は fix(security): improve deny precision for scripts handed to non-bash shells #106 に切り出した.ask の下限は fix(security): ask for every script a non-bash shell receives #99 で固定済み.これらは deny に届かず ask のままになるだけCloses #87
🤖 Generated with Claude Code