You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
security: check outgoing commits with ggshield before publication - #8
Catch secrets before publication by scanning every commit outside the fetched PR base that is reachable from the current candidate with ggshield. Other refs, multi-ref pushes and rewritten history require the complete pre-push ref-update stream. Missing tooling, authentication, scan errors and skipped scans block publication. Existing GitGuardian App, CI and Gitleaks checks remain enabled.
The gate handles explicit and remote-default bases, initial/orphan branches, force pushes and multiple ref updates. It rejects incomplete/grafted history and unsafe Git arguments, suppresses sensitive scanner output and uses existing authentication. Agent guidance and established local tooling require it before publication.
Validation: 51 offline regression tests, focused lint and diff checks passed. Authenticated ggshield scanning passed for 2a124b0c46e42454212197ee8fd372987a168164..d60375e8cc42a7facaf0ca87f73e4e390f70b10f. Commits are signed and the isolated worktree is clean. Repository CI and review remain required.
Explicit --base accepts only fully qualified refs or full commit SHAs; short names block to prevent local-ref shadowing. Unsupported metadata path encodings return a classified BASE_ERROR.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 20d923b1-c0ea-4694-933d-3ee7dfe8bd7a
Commits
Reviewing files that changed from the base of the PR and between c547d9e and d60375e.
Files selected for processing: 4
AGENTS.md
SECRET-SCANNING.md
scripts/secret_gate.py
scripts/test_secret_gate.py
No actionable comments were generated in the recent review.
Walkthrough
The change adds a local secret-scanning gate that selects candidate commits, runs ggshield, and checks scan results. Repository instructions and documentation describe scan requirements before publication and retain existing checks.
The gate confines Git metadata reads, sanitizes child environments, restricts Git and ggshield executable lookup, and validates Git invocation. Tests cover environment overrides, metadata layouts, and tool lookup.
Select commits to scan scripts/secret_gate.py, scripts/test_secret_gate.py
The gate selects commits from an explicit base, the remote default tip, all HEAD history, or pre-push ref updates. It rejects unavailable or unsupported history. Tests cover base selection and pre-push input.
Run scans and return gate status scripts/secret_gate.py, scripts/test_secret_gate.py
The gate scans selected revisions with a temporary strict configuration, classifies results, and checks the scanned snapshot. Tests cover scanner outcomes, output redaction, and failure cases.
The instructions specify scan requirements for publication, base selection, and pre-push updates. They retain existing checks and document tool and credential constraints.
The previously reported tool-location blocker is fixed, and the gate detects a base that changes during scanning. No identified issue prevents merging after normal checks.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: adding a ggshield security gate for outgoing commits before publication.
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 23 functions across 2 files. (2 skipped: 2 unsupported.)
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: a16ebcc4-398c-49e6-ab1e-01eb82a53125
Commits
Reviewing files that changed from the base of the PR and between 2a124b0 and c547d9e.
Files selected for processing: 4
AGENTS.md
SECRET-SCANNING.md
scripts/secret_gate.py
scripts/test_secret_gate.py
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Split pre-push parsing out of ranges() to clear the SonarCloud failure.
SonarCloud reports Cognitive Complexity 17 for ranges(), above the allowed 15. The pre-push loop adds most of the nesting. Move it into a helper so the PR and pre-push paths read separately. The behavior stays the same.
Verify the existing offline tests still pass after the move. test_prepush_multiple_refs_and_new_branch and test_prepush_delete_malformed_and_unknown_tip cover this path.
♻️ Proposed refactor
- if not args.pre_push:- head = commit("HEAD")- base = commit(args.base) if args.base else None- if not base and not args.all_history:- base = remote_base(args.remote)- return [f"{base}..{head}" if base else head]- result = []- # Validate all updates before scanning. Deletions contain no content.- for line in stream:- fields = line.split()- if len(fields) != 4 or not all(re.fullmatch(r"[0-9a-f]{40,64}", fields[i]) for i in (1, 3)):- raise GateError(20, "BASE_ERROR: malformed Git pre-push input.")- _, local, _, old = fields- if set(local) == {"0"}:- continue- head = commit(local)- # New refs have no previous tip: scan all reachable history, including- # the root. No hook commit limit, final-diff-only scan or HEAD~1 fallback.- result.append(head if set(old) == {"0"} else f"{commit(old)}..{head}")- return list(dict.fromkeys(result))+ if args.pre_push:+ return pre_push_ranges(stream)+ head = commit("HEAD")+ base = commit(args.base) if args.base else None+ if not base and not args.all_history:+ base = remote_base(args.remote)+ return [f"{base}..{head}" if base else head]
Add this helper above ranges():
defpre_push_ranges(stream):
"""Select one range per pre-push ref update; deletions contain no content."""result= []
forlineinstream:
fields=line.split()
iflen(fields) !=4ornotall(re.fullmatch(r"[0-9a-f]{40,64}", fields[i]) foriin (1, 3)):
raiseGateError(20, "BASE_ERROR: malformed Git pre-push input.")
_, local, _, old=fieldsifset(local) == {"0"}:
continuehead=commit(local)
# New refs have no previous tip: scan all reachable history, including# the root. No hook commit limit, final-diff-only scan or HEAD~1 fallback.result.append(headifset(old) == {"0"} elsef"{commit(old)}..{head}")
returnlist(dict.fromkeys(result))
Source: Linters/SAST tools
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 917b13b1-7214-49a4-8095-9b6b8db888bf
Commits
Reviewing files that changed from the base of the PR and between 2a124b0 and 7bbd585.
Files selected for processing: 4
AGENTS.md
SECRET-SCANNING.md
scripts/secret_gate.py
scripts/test_secret_gate.py
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Catch secrets before publication by scanning every commit outside the fetched PR base that is reachable from the current candidate with ggshield. Other refs, multi-ref pushes and rewritten history require the complete pre-push ref-update stream. Missing tooling, authentication, scan errors and skipped scans block publication. Existing GitGuardian App, CI and Gitleaks checks remain enabled.
The gate handles explicit and remote-default bases, initial/orphan branches, force pushes and multiple ref updates. It rejects incomplete/grafted history and unsafe Git arguments, suppresses sensitive scanner output and uses existing authentication. Agent guidance and established local tooling require it before publication.
Validation: 51 offline regression tests, focused lint and diff checks passed. Authenticated ggshield scanning passed for
2a124b0c46e42454212197ee8fd372987a168164..d60375e8cc42a7facaf0ca87f73e4e390f70b10f. Commits are signed and the isolated worktree is clean. Repository CI and review remain required.Explicit --base accepts only fully qualified refs or full commit SHAs; short names block to prevent local-ref shadowing. Unsupported metadata path encodings return a classified BASE_ERROR.
Production Release Notes
No production-facing change.