chore(security): 🔒 Gitleaks カスタムルール拡張 による コミット前検知・CI 強化 - #511
Conversation
Co-authored-by: genzouw <29957+genzouw@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning Review limit reached
Next review available in: 6 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughGitleaksに、Basic認証URL、LINEトークン、Notionトークン、Bearerトークンの検知ルールを追加しました。誤検知を抑制するallowlistを設定し、検知対象をセキュリティ文書に追記しました。 Changes認証情報漏洩検知
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
PR Summary by QodoGitleaksカスタムルール拡張でBearer/Basic認証URL/LINE/Notion検知を強化
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.gitleaks.toml:
- Around line 200-202: Update the gitleaks rule id “monopo-notion-api-key” in
.gitleaks.toml (lines 200-202) to detect both current ntn_ tokens and legacy
secret_ tokens while preserving the existing token lengths and character
constraints. Update the corresponding documentation in
docs/security/leak-prevention.md (lines 130-133) to describe both supported
Notion token prefixes; no other behavior changes are needed.
- Around line 186-189: Update the regex in the [rules.allowlist] configuration
to restrict Basic Authentication URL exemptions to test-only hosts such as
localhost and reserved test domains, rather than allowing any host via @.*.
Preserve the existing test credential patterns while ensuring production hosts
remain detectable.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: d7d50e7e-096c-4b21-aa3e-d23b0ee54779
📒 Files selected for processing (2)
.gitleaks.tomldocs/security/leak-prevention.md
`monopo-basic-auth-url` ルールの allowlist が `@.*` でホストを一切制限しておらず、 test/dummy 資格情報を含む Basic認証URLであれば本番ホスト(例: production.example.com) であっても検知対象から除外されてしまっていた。既存の `monopo-connection-string` ルールと同様に、allowlist の対象を `localhost` / `127.0.0.1` のみに限定し、 本番ホストへの漏洩検知を阻害しないようにした。 レビューコメント: #511 (comment) レビュアー: coderabbitai 優先度: high
Notion は2024年9月25日以降、新規発行するPublic APIトークンのプレフィックスを `secret_` から `ntn_` に変更している。`monopo-notion-api-key` ルールは レガシー形式 `secret_` のみを検知対象としており、新形式トークンが コミットされても検知できない状態だった。両プレフィックスを検知対象に含め、 ドキュメントにも両形式を検知する旨を追記した。 レビューコメント: #511 (comment) レビュアー: coderabbitai 優先度: high
`monopo-generic-bearer-token` は `bearer` の後ろが1文字以上あれば一致するため、 ドキュメント上のプレースホルダ文言(例: `Bearer token`)まで検知し、 コミット前フックやCIのgitleaksチェックを誤って失敗させ得た。他ルールと同様に 最小文字数(20文字以上)の制約を設け、実際のトークン相当の長さの文字列のみを 検知対象とするよう修正した。 レビューコメント: #511 (comment) レビュアー: qodo-code-review 優先度: medium
`monopo-line-token` の `(?:line|channel)` に前方境界が無く、`pipeline_access_token` のように `line` を部分文字列として含む無関係な識別子まで誤検知していた。 先頭に単語境界 `\b` を追加し、`line` / `channel` を独立した単語として 扱うよう修正した。gitleaksで実際に動作確認し、`pipeline_access_token` が 誤検知されないこと、および `line_access_token` 等の正規のキー名は 引き続き検知されることを確認済み。 レビューコメント: #511 (comment) レビュアー: qodo-code-review 優先度: medium
`monopo-notion-api-key` は末尾境界が無いため、より長い英数字文字列の 先頭43文字だけに部分一致し、曖昧な検知結果を招き得た。末尾に単語境界 `\b` を追加し、トークン全体との一致を保証するよう修正した。 レビューコメント: #511 (comment) レビュアー: qodo-code-review 優先度: low
背景
事前調査の結果、本リポジトリでは
.pre-commit-config.yamlや CI ワークフローを通じて Gitleaks や TruffleHog などの強力なシークレットスキャンツールがすでに設定されています。しかし、プロジェクトの拡大に伴い利用が増加しうる汎用的な Bearer トークンや、Basic 認証のURL直書き、各種SaaS(LINE、Notion等)のAPIキーについては既存のカスタムルールでカバーされていないため、開発者のハードコードによる意図せぬ情報露出リスクが存在します。現状認識
gitleaks.yml,trufflehog.yml,trivy.yml,.pre-commit-config.yamlによるローカル/CIの多層防御が導入済みこのPRで導入・強化するもの
.gitleaks.tomlおよびdocs/security/leak-prevention.mdの更新monopo-basic-auth-url: 開発中に記述しがちなBasic認証情報付きのURLを検知・ブロック。monopo-line-token/monopo-notion-api-key: 特定SaaSに紐づくキー形式を明示的に検知・ブロック。monopo-generic-bearer-token: 上記に該当しない汎用的な Bearer トークンを検知・ブロック。検知漏れリスクと補完策
detect-secrets(エントロピーベース検知)、およびGitHubネイティブの Secret Scanning と併用することで多層防御を維持マージ前に必要な手動作業(チェックリスト)
レビュアーは PR をマージする前に必ず以下を実施してください。本 PR の CI は手動作業完了を前提に通る設計です。
pre-commit run --all-filesなどを実行して確認するマージ後の確認手順
secret_dummy123456...等のNotion形式)をテスト的にコミットしようとした際、ローカルの pre-commit フックで正しくブロックされるかを確認するロールバック手順
git revert <commit-hash>)PRを作成・マージすることで以前の状態に復元できます。参考情報
PR created automatically by Jules for task 12435543589279923108 started by @genzouw
Summary by CodeRabbit