Prerequisites
- Target system, dependencies and environment configured.
Usage
Purpose
Secrets leak into repos constantly — a key pasted for a quick test, a .env committed by accident. Once pushed, the credential is compromised even after you delete it, because history and mirrors keep the copy. This skill covers catching them at two chokepoints (before the commit, and in CI) so they never reach a shared branch.
It's the preventive counterpart to the OSINT github-secret-recon skill: that one finds leaks after the fact, this one stops them happening.
When to use it
Setting up a new repo, or hardening an existing one that's had a leak scare. High value for low effort — a pre-commit hook plus a CI job blocks the overwhelming majority of accidental secret commits.
Procedure
- Add a pre-commit hook so the scan runs on the developer's machine before the secret ever leaves it — the earliest and cheapest catch:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.30.1
hooks:
- id: gitleaks
pre-commit install
- Add a CI job as the backstop — not every developer will have the hook installed, so the pipeline enforces it for the whole team:
# ci step
- run: gitleaks git --redact --exit-code 1 .
The job must fetch the commits it intends to scan. A shallow checkout cannot support a claim that the entire repository history was checked.
- Scan full history once when adopting this on an existing repo — you want to know what's already leaked, not just what's new:
gitleaks git --redact --log-opts="--all" .
- Tune to cut false positives without going blind. Add a
.gitleaks.toml allowlist for known test fixtures and example values, but keep it tight — an over-broad allowlist defeats the point.
- Turn on the platform's native push protection where available as a third layer that blocks at the server regardless of local setup.
- Define the response for a real hit (see below) so a caught secret is actually remediated, not just un-committed.
Cheatsheet
gitleaks git --pre-commit --staged --redact .
gitleaks git --redact .
gitleaks git --redact --log-opts="--all" .
gitleaks dir --redact .
gitleaks git --redact --exit-code 1 --report-format sarif --report-path gl.sarif .
Reading the output
- A finding that may be a live credential needs prompt owner-side validation and rotation. Do not paste or test its value in an unrelated service.
- A hit in history but not the current tree still counts: the secret must be rotated, deletion isn't remediation.
- Repeated false positives on the same fixture mean it's time for a scoped allowlist entry — don't let noise train the team to ignore the scanner.
- A clean CI run is only as good as the ruleset and the scanned range.
gitleaks git inspects commits; gitleaks dir inspects current files, including files outside Git history. Check which one your pipeline actually runs.
The response when a real secret is caught
Rotate first — the credential is burned the moment it was committed, so revoke and reissue immediately. Then purge it from history (git filter-repo/BFG) and force-push, understanding that mirrors and forks may still hold the old commit (rotation is what actually protects you). Move the secret into a proper secret manager and inject it at runtime so it never lives in the repo again.
Pitfalls
- CI-only, no pre-commit. Catching it in CI means it's already pushed — rotation required. The hook stops it before that.
- Deleting the commit and calling it done. Without rotation, the leaked key is still valid to anyone who saw the push.
- Over-broad allowlists. One sloppy ignore rule and real secrets slip through silently.
- No response plan. A scanner that finds secrets nobody rotates is theatre. Wire the rotation step in.
References
Inputs
- Relevant source code, logs, network traces, or system specifications.
Outputs
- Analysis findings, security audit report, or generated code artifacts.
1---2format: "v2"3name: "secrets-scanning-in-pipelines"4title: "Secrets Scanning In Pipelines"5title_fr: "Détection de secrets dans les pipelines"6description: "Use when you want to stop credentials from being committed or built into artifacts — wiring secret scanning into pre-commit and CI so leaks are caught before they ship."7description_fr: "À utiliser pour empêcher que des identifiants soient commités ou embarqués dans des artefacts — en intégrant la détection de secrets au pre-commit et à la CI pour intercepter les fuites avant qu'elles ne partent en production."8domain: "08-devsecops-and-cicd-security"9tags: [cybersecurity, engineering, best-practices]10maturity: "stable"11audience: ["backend-engineer", "security-engineer", "coding-agent"]12requires: ["bash", "git"]13updated: "2026-10-13"14metadata:15 source: https://skillmd.com/skills/jihedbfr-art/secrets-scanning-in-pipelines16---17181920## Prerequisites21- Target system, dependencies and environment configured.2223## Usage24### Purpose2526Secrets leak into repos constantly — a key pasted for a quick test, a `.env` committed by accident. Once pushed, the credential is compromised even after you delete it, because history and mirrors keep the copy. This skill covers catching them at two chokepoints (before the commit, and in CI) so they never reach a shared branch.2728It's the preventive counterpart to the OSINT github-secret-recon skill: that one finds leaks after the fact, this one stops them happening.2930### When to use it3132Setting up a new repo, or hardening an existing one that's had a leak scare. High value for low effort — a pre-commit hook plus a CI job blocks the overwhelming majority of accidental secret commits.3334### Procedure35361. Add a **pre-commit hook** so the scan runs on the developer's machine before the secret ever leaves it — the earliest and cheapest catch:37 ```yaml38 # .pre-commit-config.yaml39 repos:40 - repo: https://github.com/gitleaks/gitleaks41 rev: v8.30.142 hooks:43 - id: gitleaks44 ```45 ```46 pre-commit install47 ```482. Add a **CI job** as the backstop — not every developer will have the hook installed, so the pipeline enforces it for the whole team:49 ```yaml50 # ci step51 - run: gitleaks git --redact --exit-code 1 .52 ```53 The job must fetch the commits it intends to scan. A shallow checkout cannot support a claim that the entire repository history was checked.543. Scan **full history** once when adopting this on an existing repo — you want to know what's already leaked, not just what's new:55 ```56 gitleaks git --redact --log-opts="--all" .57 ```584. Tune to cut false positives without going blind. Add a `.gitleaks.toml` allowlist for known test fixtures and example values, but keep it tight — an over-broad allowlist defeats the point.595. Turn on the platform's native **push protection** where available as a third layer that blocks at the server regardless of local setup.606. Define the response for a real hit (see below) so a caught secret is actually remediated, not just un-committed.6162### Cheatsheet6364```bash65gitleaks git --pre-commit --staged --redact .6667gitleaks git --redact .6869gitleaks git --redact --log-opts="--all" .7071gitleaks dir --redact .7273gitleaks git --redact --exit-code 1 --report-format sarif --report-path gl.sarif .74```7576### Reading the output7778- **A finding that may be a live credential** needs prompt owner-side validation and rotation. Do not paste or test its value in an unrelated service.79- **A hit in history but not the current tree** still counts: the secret must be rotated, deletion isn't remediation.80- **Repeated false positives on the same fixture** mean it's time for a scoped allowlist entry — don't let noise train the team to ignore the scanner.81- **A clean CI run** is only as good as the ruleset and the scanned range. `gitleaks git` inspects commits; `gitleaks dir` inspects current files, including files outside Git history. Check which one your pipeline actually runs.8283### The response when a real secret is caught8485Rotate first — the credential is burned the moment it was committed, so revoke and reissue immediately. Then purge it from history (`git filter-repo`/BFG) and force-push, understanding that mirrors and forks may still hold the old commit (rotation is what actually protects you). Move the secret into a proper secret manager and inject it at runtime so it never lives in the repo again.8687### Pitfalls8889- **CI-only, no pre-commit.** Catching it in CI means it's already pushed — rotation required. The hook stops it before that.90- **Deleting the commit and calling it done.** Without rotation, the leaked key is still valid to anyone who saw the push.91- **Over-broad allowlists.** One sloppy ignore rule and real secrets slip through silently.92- **No response plan.** A scanner that finds secrets nobody rotates is theatre. Wire the rotation step in.9394### References9596- [Gitleaks usage and pre-commit hook](https://github.com/gitleaks/gitleaks#usage)97- [Gitleaks release v8.30.1](https://github.com/gitleaks/gitleaks/releases/tag/v8.30.1)98- OWASP DevSecOps Guideline — secrets management99- GitHub/GitLab secret scanning and push protection docs100101## Inputs102- Relevant source code, logs, network traces, or system specifications.103104## Outputs105- Analysis findings, security audit report, or generated code artifacts.