Skip to content

fix(hooks): stop asking for gh calls whose target and arguments are known at hook time - #254

Merged
furedea merged 5 commits into
mainfrom
fix/gh-ask-known-at-hook-time
Nov 19, 2026
Merged

furedea merged 5 commits into
mainfrom
fix/gh-ask-known-at-hook-time

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

概要

hook の時点で確定できる事実がある gh 呼び出しが確認(ask)になり,lane が承認待ちで止まっていた.文字列の解析を深くせず,確定できる 3 種類だけを allow 側に直す.

Closes #253
Refs #197, #181

変更

  • 変更 1:-R owner/repo(--repo)で対象を明示した読み取りは,作業ディレクトリの remote を理由に確認にしない(gh_repository.names_repository_option,gh_invocation._classify_words).host は -R の値で決まり,host 部分が無ければ github.com.github.com 以外の host,run time の値,別の option の値になりうる -R(直前が option)は従来どおり確認.
  • glob(Issue の受け入れ条件 3 つ目)は,この PR から外した. ユーザーの決定:hook でシェルの glob を再現する方式は収束しない(POSIX 文字クラス,nocaseglob,走査範囲と指摘が続いた.feat(hooks): judge shell function bodies instead of asking for every function #200 と同じ教訓).未一致 glob の「文字どおり扱い」とそのテストを削除し,glob を含む引数(?ref= など)は従来どおり確認.feat(agent-runtime): build persistent, isolated, provider-neutral agent infrastructure #181 で扱う.
  • -R の許可は,行にほかのコマンドがあれば従来どおり確認(writable な PATH に git を置きうるコマンドの検査を迂回しない).GhCall.names_repository を足し,gh_policy._ungranted で行全体の検査を残した.
  • 変更 2:1 コマンドだけの行で,hook の環境に設定済みの $TMPDIR / $HOME だけで書かれた body / input ファイルの path は展開し,リテラルの path と同じく存在・読み取り・サイズ・秘密のスキャンにかける(gh_options.expand_environment,environment_files).未設定の変数,$TMPDIR / $HOME 以外の変数,単独の $f,同じ行で代入した変数,ループ,コマンド置換は従来どおり確認.
  • allow になる効果の区分は feat(hooks): judge gh calls by effect through a policy table #201 の policy table のまま変えていない.gh_policy.py の変更は,-R の許可に行全体の検査を残す 1 行とコメントだけ.?ref= を含む read は feat(agent-runtime): build persistent, isolated, provider-neutral agent infrastructure #181 まで確認のまま.

テスト

  • tests/hooks/test_gh_known_at_hook_time.py(新規):-R の 7 つの書き方が remote に関わらず allow,host 違い・run time の値・option に食われうる -R・値なし・後続の別 host の -R は ask,GH_HOST 違いは ask.glob を含む read endpoint(?ref=)と,cp x later/git; gh pr list -R … は ask.
  • tests/hooks/test_gh_run_time_body_files.py:$TMPDIR の body file が allow,ほかの変数・未設定・単独変数・存在しないファイル・コマンド置換・同じ行の代入・ループ・stdin のリダイレクトは ask,秘密を含むファイルは展開後に ask.
  • 旧仕様(-R でも remote を見る,環境変数の body path は ask)を確かめていた既存テストを新しい仕様に合わせた.
  • uv run pytest tests(6135 件),ruff,ty は通過.

記録(範囲外・前提)

🤖 Generated with Claude Code

…nown at hook time

- A read that names its repository with a literal -R or --repo no longer
  asks because of the working directory's remotes.
- On a line that is one gh call, a plain glob that matches no file in the
  working directory is the argument as written.
- On such a line, a body or input file named by environment variables set
  in the hook's environment is expanded, then scanned like a literal path.

Closes #253
Refs #197, #181

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T09:38:12.134699Z ac6d21e Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread agents/hooks/lib/gh_options.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

I found one issue (P2) and nothing that should block the merge. This was a read-only review. I did not run the test suite.

What I checked

  • -R / --repo now skips the working-directory remote check for reads. A positional URL or HOST/OWNER/REPO on another host still goes through _check_read_repositories. An -R that follows another option, or has no value, still asks. Later -R values are still checked. These cases are covered by the new tests.
  • Unmatched globs become literal words only on a single-command line. The word has to match PLAIN_GLOB_WORD, and Path.glob has to find no file. Dotfiles resolve conservatively to "matched".
  • Environment expansion is gated by stays_one_word, needs all variables set, and only runs on single-call lines. The expanded path then goes through the existing exists / readable / size / secret-scan checks.

Finding

  • P2 (gh_options.expand_environment): the old premise was that the hook's environment may differ from the sandboxed shell's, so a body path expanded in the hook could scan a different file than gh sends. This PR drops that premise for any set variable, including $TMPDIR. The comment in gh_policy._file_problem still states the old premise, and no test or check covers the new one. If the hook and sandbox TMPDIR differ, a clean file at the hook's path can hide a secret at the sandbox's path. The PR description lists this as an assumption. I suggest allowing only variables known to be identical on both sides, and updating the stale comment.

Tests cover the new paths well, both allow and ask cases, including a secret in an expanded file.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: caa18645f0

ℹ️ 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".

Comment thread agents/hooks/lib/gh_options.py Resolved
Any other variable may hold a different value in the sandboxed shell than
in the hook, so a path using one keeps asking.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review of #254: I found no P0 or P1 problems, and I didn't post any inline comments. I read the diff and the surrounding code. I did not run the test suite.

What I checked:

  • -R / --repo reads (names_repository_option). It only counts a literal, non-dynamic github.com repository. It skips an -R that directly follows another option. Foreign hosts, run-time values and a missing value still ask. The GH_HOST case is tested.
  • Unmatched globs (is_unmatched_glob). The word pattern is tight. It rejects quotes, ~, {}, $, (, !, ^ and a leading =. Path.glob also matches dotfiles, so a doubtful case resolves to "matched", which asks. The check applies only to a lone call.
  • Environment expansion (expand_environment). It is limited to TMPDIR and HOME. PLAIN_PARAMETER_WORD excludes backslashes and unquoted glob characters, so \$HOME and $TMPDIR/*.md don't expand to a different path than the shell would use. Single-quoted text stays literal. The expanded path then goes through the same existence, size and secret checks as a literal path.

Optional (P3) test gaps:

  • The * and [...] unmatched-glob forms are never tested as allow cases. The removed tests (gh api repos/o/r/contents/*, --jq .[0]) had covered them as ask.
  • HOME in PATH_VARIABLES has no test, and neither does an absolute-path glob (the Path("/") branch).
  • -R evil.example/o/r -R furedea/agent-config is untested. The reverse order is covered.

Assumptions the PR already lists, which keep me from marking this fully safe:

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 20b3ce87f6

ℹ️ 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".

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review of #254 (read-only): no blocking findings.

I read the diff for gh_invocation, gh_options, gh_repository and the tests. I didn't run the test suite or the new helpers, because the sandbox blocked those commands. This is a read-through only.

Checked and fine:

  • single_call rejects prefix assignments such as TMPDIR=/x gh ..., lists, pipes, wrappers, and substitutions that do more than print. expand_environment and is_unmatched_glob only run when it is true.
  • names_repository_option skips an -R that follows another option, ignores dynamic values, and goes through repository(), so other hosts still ask.
  • The glob matcher errs toward 'matched' (dotfiles, **, unreadable paths), which means ask.

Not blocking, for awareness:

  • (P3) is_unmatched_glob checks the hook process's Path.cwd(). If the sandboxed shell's cwd has drifted (the Bash tool carries cd across calls), the shell could expand a glob the hook saw as unmatched. PLAIN_GLOB_WORD also lets the first character be -, so a pattern like -* could expand to option-like file names. This sits in the same TOCTOU/cwd-assumption area the PR already marks as out of scope (feat(agent-runtime): build persistent, isolated, provider-neutral agent infrastructure #181), and I'm not asking for a change.
  • The HOME/TMPDIR expansion relies on the hook and the sandbox sharing those values. The PR states this assumption explicitly.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bc14ea15cc

ℹ️ 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".

Comment thread agents/hooks/lib/gh_options.py Resolved
…tory

A literal -R only settles the host; another command on the line that may
write a git onto PATH still makes the call ask.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/gh_options.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary (read-only; I ran no tests and did not execute the guard against probe commands).

No P0 or P1 findings.

I read the three new behaviours against the existing guards:

  • -R / --repo reads: names_repository_option skips dynamic words and any -R that directly follows an option, including --. _check_read_repositories still rejects a foreign-host or run-time -R or --repo before the new flag is used, and GH_HOST / GH_REPO are still checked elsewhere. I found no way to make a foreign host pass as github.com.
  • Unmatched globs: The match is limited to one-command lines, plain characters, and no match in the hook's cwd. Wrong guesses mostly fall back to ask, because Path.glob also matches dotfiles. The nullglob and TOCTOU assumptions are stated in the PR.
  • $TMPDIR / $HOME expansion: It only applies when stays_one_word holds and the variable is set in the hook's environment. Unset variables and other names return the word unchanged, so they still ask.

P3 (inline): is_unmatched_glob can walk a very large tree when the pattern has ** or an absolute path and nothing matches.

P3 (description): The PR body says gh_policy.py is unchanged. It changes _ungranted, so a read with names_repository now skips _remotes_on_github(). That is the intended behaviour, but the description should say so.

Tests: Coverage of the new cases looks good. Three unmatched-glob and ?ref= cases were deleted from the old ask lists and are re-covered as allow cases in test_gh_known_at_hook_time.py.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1fd52ef38f

ℹ️ 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".

Comment thread agents/hooks/lib/gh_options.py Resolved
Emulating shell globbing in the hook does not converge (POSIX classes,
nocaseglob, walk bounds), the same lesson as #200. A glob stays a run-time
word and asks until #181. The removed still-ask tests are restored.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

Comment thread agents/hooks/lib/gh_options.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

I found no P0 or P1 problems. I read the diff and the code around it, but I could not run the test suite in this environment because the commands were not approved. The pass/fail claims in the PR description are therefore unverified by me.

What I checked

  • -R handling (names_repository_option): a -R right after another option is skipped, so it is never trusted when an unlisted option might take it as a value. _check_read_repositories still rejects any -R/--repo that names another host, so a later foreign -R cannot ride on an earlier valid one. It applies only to the read branch. The planted-git case is still covered by gh_environment (the has_writable_path_entry_before check on non-single-call lines), which runs independently of this change.
  • ``//home/runner expansion: expansion happens only when `single_call` is true, the word passes `stays_one_word`, every parameter is in `PATH_VARIABLES` and set non-empty, and unquoted values have no blank or glob characters. Single-quoted `$` stays literal. The expanded word then goes through the normal existence, read, size and secret checks.

Findings

  • P3 (inline): HOME expansion has no test coverage.

Residual risk (a decision already recorded in the PR, not a defect)
The expansion is only correct if the hook's TMPDIR/HOME equal those of the sandboxed shell. The old code comment said the hook may not share that environment. If they differ, the hook scans one file and gh sends another. That is the same TOCTOU class as the PR's "out of scope" note, and it is worth confirming against the real harness before relying on it.

🤖 Generated with Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac6d21eef9

ℹ️ 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".

Comment thread agents/hooks/lib/gh_repository.py Resolved
Comment thread agents/hooks/lib/gh_repository.py Resolved
@furedea
furedea merged commit f4aa355 into main Nov 19, 2026
29 checks passed
@furedea
furedea deleted the fix/gh-ask-known-at-hook-time branch November 19, 2026 10:39
furedea pushed a commit that referenced this pull request Nov 20, 2026
🤖 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>
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.

fix(hooks): stop asking for gh calls whose target and arguments are known at hook time

1 participant