fix(hooks): bound force-push patterns to avoid chained-command false positives - #794
Conversation
…positives block_dangerous_commands は normalize 時に改行を空白へ潰すため、`.*` が push の引数を越えて後続コマンドや flatten された heredoc 本文中の `-f` までマッチし、`git push -u … 2>&1 | tail -4` 等を誤ブロックしていた。 - force-push 3 パターンの `.*` を `[^|&;<>]*` に変更し、pipe/redirect/ separator をまたがない(push 自身の引数内のみ)よう限定 - 実 force push(--force / 短縮形 / --force-with-lease / origin +branch)は 引き続きブロック。誤検知は解消(.context の behavioral テストで8ケース確認) - hooks-integrity: パターン文字列アサーション更新 + 退行防止テスト追加 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR tightens regex patterns in a Git hook that detects dangerous ChangesGit push force-detection regex bounding
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
test/hooks-integrity.test.jsOops! Something went wrong! :( ESLint: 10.4.1 ReferenceError: describe is not defined Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Claude finished @keito4's task in 1m 50s —— View job コードレビュー
概要
Verdict: ✅ APPROVE(minor / recommendation のみ) Security(セキュリティ)問題なし。検出の穴ではなく「スコープの限定」であり、実際の force push は引き続きブロックされます。 品質(Quality)✅ 正しい挙動の確認
Recommendation:
|
| 観点 | 評価 |
|---|---|
| Security | ✅ 問題なし |
| Performance | ✅ 影響なし |
| Quality | git clean -f の .* も将来的に修正推奨 |
| Accessibility | N/A |
| AI Residuals | ✅ 問題なし |
修正の方向性・実装ともに正しく、リスクは低いです。LGTM 🚀
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 579a6c3751
ℹ️ 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".
| (r"git\s+push\s+[^|&;<>]*--force", "git push --force (force push)"), | ||
| (r"git\s+push\s+[^|&;<>]*-f\b", "git push -f (force push)"), | ||
| (r"git\s+push\s+[^|&;<>]*--force-with-lease", "git push --force-with-lease"), |
There was a problem hiding this comment.
Block force pushes with inline redirections
When a redirection appears before the force option in the same simple command, this negated class stops scanning at >/< and misses the later force flag. Bash still treats later words as arguments after a redirection (e.g. f 2>/dev/null --force origin main passes --force), and the hook now exits 0 for git push 2>/dev/null --force origin main, allowing the force-push policy to be bypassed while still executing a real force push.
Useful? React with 👍 / 👎.
|
🎉 This PR is included in version 1.114.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Why
block_dangerous_commands.pyは normalize 時に" ".join(cmd.split())で改行を空白へ潰す。その状態で force-push 検出のgit\s+push\s+.*-f\b系が.*貪欲マッチするため、push の引数を越えて後続コマンドや flatten された heredoc 本文中の-fにまでマッチし、安全なコマンドを誤ブロックしていた。実例(このセッションで遭遇):
What
force-push 3 パターンの
.*を[^|&;<>]*に変更し、**pipe / redirect / separator をまたがない(push 自身の引数内のみ)**よう限定。検証
behavioral テスト 8 ケースで確認:
--force/ 短縮形 /--force-with-lease/origin +branch-f/echo … -f && git status/ 通常のpush -uhooks-integrity.test.jsのパターン文字列アサーション更新 + 退行防止テスト追加。jest 111 / 全 jest green。Risk
低。検出を緩めるのではなく「push 引数内に限定」する変更で、実 force push の検出は維持。
🤖 Generated with Claude Code
Summary by CodeRabbit