Skip to content

fix(hooks): match static words by their single-quoted form in precise command rules - #147

Merged
furedea merged 1 commit into
mainfrom
fix/judge-precise-command-rules-by-parsed-literal-values
Nov 10, 2026
Merged

furedea merged 1 commit into
mainfrom
fix/judge-precise-command-rules-by-parsed-literal-values

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

概要

guard_command.py の精密ルールが,クォートの書き方だけが違う同じ静的な値(-f body="Fixed." など)を「確認」に回していたため,ADR-0015 の①に沿って判定を直す.

  • 展開を含まない静的な語('…',"…",\ エスケープ)を,各部分を一定の形(シングルクォート)に書き直した正規形で並べ直し,パターンを生の語と正規形の両方に照合する(どちらかが一致すれば allow)
  • 展開を含む語($,バッククォート,\,! を含むダブルクォートなど)と動的な語は従来どおり生の語だけで照合するため,ask のまま
  • allowed_commands.json にルールは追加していない

Closes #143

判定の変化

書き方 変更前 変更後
gh api …/replies -f body="Fixed." ask allow
gh api …/replies -f body=Fixed\. ask allow
curl -s -w "status" http://localhost/ ask allow(-w 'status' と同一の値.既存の ask テスト 1 行を allow テストへ移動)
gh run list --commit "$sha" allow allow
gh run list --commit $sha ask ask
gh run list --commit $(git rev-parse HEAD) ask ask

同一コマンド内の固定値代入(sha=…; gh … $sha)は 2026-11-11 の決定どおり扱わず,ADR-0015 に既知の穴として追記した.

テスト

  • tests/hooks/test_quote_normalization.py を追加(allow 側と,展開・!・バッククォート・エスケープ・未クォート変数・コマンド置換・代入が ask のままであること)
  • tests/hooks は test_formatter_config.py(サンドボックスが plugins.dprint.dev を遮断するため実行不可)を除いて通過

🤖 Generated with Claude Code

@furedea

furedea commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-10T18:04:02.186034Z
We couldn’t complete this review. Comment @codex review to try again.
163d62d 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown

Review summary

No P0 or P1 findings, and no inline comments.

What I checked:

  • The two-way match stays safe. single_quoted_source only rewrites words the shell passes through unchanged:

    • single-quoted parts
    • double-quoted parts with no $, backticks, backslashes or !
    • unquoted text with backslash escapes

    It leaves anything dynamic, spreading, $HOME, $'…' or a line continuation as the original text. So the rewritten text is a valid shell spelling of the same values. A rule that is safe on raw text stays safe on it, including the escaped-apostrophe form in the gh … /replies rule and the curl -d check against @file.

  • The other checks are unchanged. hides_options, the check that automation programs are listed with quotes removed, the curl -w/-H checks on decoded values, and the deny path all still run as before. An option written in quotes like "-K" still asks.

  • quoted_words stays in sync. rebased carries it forward, and every other Command falls back to words. without_option_values does not mask quoted_words, but that function is only used on the deny path. The length never changes, so zip(strict=True) will not raise.

Not blocking, and older than this PR: a word that starts with ~/ and contains a backslash escape is rewritten inside single quotes, which turns off tilde expansion. literal_word also ignores bash expanding ~ after = in arguments like name=~/x. No current rule can be bypassed this way.

I could not run the tests here: the sandbox would not run pytest without approval.

🤖 Generated with Claude Code

@furedea
furedea merged commit c432a20 into main Nov 10, 2026
22 of 24 checks passed
@furedea
furedea deleted the fix/judge-precise-command-rules-by-parsed-literal-values branch November 10, 2026 18:19
furedea pushed a commit that referenced this pull request Nov 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.1.1](v0.1.0...v0.1.1)
(2026-11-11)


### Features

* **hooks:** judge session changes with jev-lint model rules at Stop
([#150](#150))
([946e976](946e976))


### Bug Fixes

* **hooks:** ask for zsh's $=name and $~name expansions
([#152](#152))
([9255c87](9255c87))
* **hooks:** judge a ~user path by the secret-path rules of the own home
([#129](#129))
([64221f6](64221f6))
* **hooks:** match static words by their single-quoted form in precise
command rules
([#147](#147))
([c432a20](c432a20))
* **hooks:** run verification tools through the flake dev shell
([#132](#132))
([63dd2f5](63dd2f5))
* **hooks:** start trusted model-rule programs and send only
in-repository regular files
([#156](#156))
([183496b](183496b))

---
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): judge precise command rules by parsed literal values

1 participant