Update Best Practices badge to dynamic JSON#4
Conversation
WalkthroughThe PR updates the "Best Practices" badge in README.md to use a Shields.io dynamic endpoint, and adjusts the gitleaks workflow to use Badge URL Update
Gitleaks Workflow Security Configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 @.github/workflows/gitleaks-scanning.yml:
- Line 3: Change the workflow trigger from pull_request_target back to
pull_request. The pull_request_target trigger causes gitleaks-action v3 to scan
only the base branch instead of the PR head commits (since no explicit ref
parameter is provided to actions/checkout), missing the actual PR contents that
need to be scanned. Additionally, pull_request_target unnecessarily exposes
repository secrets like GITLEAKS_LICENSE and the GITHUB_TOKEN to fork PRs. Since
gitleaks only requires read access to the PR diff and does not need elevated
permissions, reverting to the pull_request trigger solves both the incomplete
scanning and the security exposure issues.
🪄 Autofix (Beta)
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
Run ID: ffa6d3ea-3cba-4c91-8efe-3b7c08eafe07
📒 Files selected for processing (1)
.github/workflows/gitleaks-scanning.yml
| name: gitleaks | ||
| on: | ||
| pull_request: | ||
| pull_request_target: |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major
🧩 Analysis chain
🌐 Web query:
gitleaks-action v3 pull_request_target supported commit scanning checkout ref behavior
💡 Result:
The gitleaks-action v3, like its predecessor v2, is primarily designed for the pull_request and push events [1][2]. There is no specialized support or specific behavior implemented for the pull_request_target event [3]. When using gitleaks-action within a GitHub Actions workflow, the action relies on the repository state established by the preceding actions/checkout step [1][2]. The behavior regarding commit scanning is as follows: 1. Checkout Requirement: To properly scan commits, you must use actions/checkout with fetch-depth: 0 [1][4]. This ensures the full git history is available for gitleaks to perform its analysis [1][2]. 2. Scan Scope: For pull_request events, gitleaks-action automatically calculates the commit range (typically using baseRef^..headRef) to scan only the changes introduced by the pull request [5]. 3. pull_request_target behavior: While you can technically configure a workflow to run on pull_request_target, the action does not have explicit logic to handle the nuances of that event type [3]. Users who previously requested support for pull_request_target determined that it was not necessary for typical secret scanning use cases [3]. If you choose to use pull_request_target, you must manually manage the checkout ref (e.g., using with: ref: ${{ github.event.pull_request.head.sha }} in actions/checkout) to ensure the runner is scanning the actual pull request code rather than the base branch, as the default behavior of pull_request_target is to check out the base branch of the pull request. Note that running security-sensitive actions on pull_request_target requires caution due to the elevated permissions associated with that event [3].
Citations:
- 1: https://github.com/gitleaks/gitleaks-action
- 2: https://github.com/marketplace/actions/gitleaks
- 3: Support running gitleaks-action on
pull_request_targetgitleaks/gitleaks-action#94 - 4: https://github.com/gitleaks/gitleaks-action/blob/master/README.md
- 5: https://deepwiki.com/gitleaks/gitleaks-action/3.2-gitleaks-integration-layer
Switching to pull_request_target breaks the scan and exposes secrets to fork PRs.
Two distinct problems with this trigger change, both confirmed by gitleaks-action v3 behavior:
-
Scan will miss PR contents. gitleaks-action v3 does not have specialized support for
pull_request_targetand relies on the checkout step to establish the scanning scope. Forpull_request, it automatically calculates the commit range (baseRef^..headRef). Forpull_request_target, it defaults to scanning whatever ref is checked out—which is the base branch whenactions/checkouthas no explicitrefparameter (as here). Without manually settingref: ${{ github.event.pull_request.head.sha }}, the PR head commits are never checked out locally, so gitleaks scans only base-branch code, defeating the purpose of PR secret scanning. -
Secrets now reachable from fork PRs.
pull_request_targetexposes repository secrets (GITLEAKS_LICENSE, write-scopedGITHUB_TOKENat lines 18–19) to runs triggered from forks. While scanning a file does not execute untrusted code, the elevated permissions and secret availability create an unnecessary attack surface.
The gitleaks use case does not justify pull_request_target. Unlike danger.yml (which needs write permissions to post comments), gitleaks only needs to read the PR diff and requires no elevated permissions. Keep pull_request instead.
🤖 Prompt for 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.
In @.github/workflows/gitleaks-scanning.yml at line 3, Change the workflow
trigger from pull_request_target back to pull_request. The pull_request_target
trigger causes gitleaks-action v3 to scan only the base branch instead of the PR
head commits (since no explicit ref parameter is provided to actions/checkout),
missing the actual PR contents that need to be scanned. Additionally,
pull_request_target unnecessarily exposes repository secrets like
GITLEAKS_LICENSE and the GITHUB_TOKEN to fork PRs. Since gitleaks only requires
read access to the PR diff and does not need elevated permissions, reverting to
the pull_request trigger solves both the incomplete scanning and the security
exposure issues.
Addressed Issues:
Fixes #(issue number)
Screenshots/Recordings:
Additional Notes:
Checklist
We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.
Summary by CodeRabbit