Skip to content

security: check outgoing commits with ggshield before publication - #8

Merged
MTG-Thomas merged 13 commits into
mainfrom
security/ggshield-pre-pr-20261103
Nov 4, 2026
Merged

MTG-Thomas merged 13 commits into
mainfrom
security/ggshield-pre-pr-20261103

Conversation

@MTG-Thomas

@MTG-Thomas MTG-Thomas commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

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.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

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: 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.

Changes: Secret-scanning publication gate

Layer / File(s) Summary
Constrain gate execution
scripts/secret_gate.py, scripts/test_secret_gate.py
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.
Document publication requirements
AGENTS.md, SECRET-SCANNING.md
The instructions specify scan requirements for publication, base selection, and pre-push updates. They retain existing checks and document tool and credential constraints.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant secret_gate.py
  participant Git
  participant ggshield
  Developer->>secret_gate.py: Invoke gate
  secret_gate.py->>Git: Resolve candidate revisions
  Git-->>secret_gate.py: Return revision ranges
  secret_gate.py->>ggshield: Scan revisions
  ggshield-->>secret_gate.py: Return scan status
  secret_gate.py-->>Developer: Return gate status
Loading
Merge Risk: Minimal · previous review c547d

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: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: adding a ggshield security gate for outgoing commits before publication.
Docstring Coverage Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share
Recent 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: 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional comments: 1
scripts/secret_gate.py: 1

64-83: Trivial · Maintainability & Code Quality · Quick win

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():

def pre_push_ranges(stream):
    """Select one range per pre-push ref update; deletions contain no content."""
    result = []
    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))

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.

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix comments: Fix CodeRabbit comments on this PR

Comment thread scripts/secret_gate.py Resolved
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@MTG-Thomas
MTG-Thomas merged commit 025963f into main Nov 4, 2026
6 checks passed
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.

1 participant