R_REDDYX.XYZ
Code tools2026-08-23

Gitleaks in 2026: finding leaked API keys in a repository in 30 seconds

Gitleaks in 2026: finding leaked API keys in a repository in 30 seconds
TL;DR: Secret accidentally committed to git remains in history forever — deleting the file does not remove the key from past commits. Gitleaks scans the entire repository using regex and entropy, finds leaked API keys, passwords, and tokens in seconds, and it should be integrated into CI before the secret reaches a public repository.

Project card — stars, tech stack, link to sources — in the REDDYX catalog: gitleaks/gitleaks.

WHY SECRETS LEAK EVEN AMONG EXPERIENCED

Typical scenario: the key is written in .env for a quick local test, the file accidentally wasn't added to .gitignore, and the commit was pushed to the shared repository. Or the key is hardcoded 'temporarily' directly in the code for debugging — and forgotten there. GitHub is indexed by bots that look for exactly such leaks in public repositories within minutes after a push.

WHAT GITLEAKS DOES

The tool runs file contents and the entire commit history through a set of rules: signatures of specific providers (AWS, Stripe, GitHub tokens and dozens others by characteristic format) and a general high-entropy detector for unrecognized but secret-like strings. It finds not only in the current repository state but also in deleted files from past commits — something that manually searching with git log -p would be tedious.

INSTALLATION AND FIRST SCAN

# macOS
brew install gitleaks

# или через go
go install github.com/gitleaks/gitleaks/v8@latest

# скан текущего репозитория со всей историей
gitleaks detect --source . --verbose

# скан только незакоммиченных изменений (быстрая проверка перед коммитом)
gitleaks protect --staged

When a secret is found, Gitleaks outputs the file, line, commit, and type of suspected secret — enough to immediately understand what and where leaked.

INTEGRATION INTO CI/CD

The right point of protection is not 'we’ll check manually someday' but an automatic gate before merge. Minimal GitHub Actions workflow:

# .github/workflows/gitleaks.yml
name: gitleaks
on: [pull_request]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: gitleaks/gitleaks-action@v2

Additionally, it makes sense to add a pre-commit hook locally — then the secret is blocked before push, not after the PR is already open:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.18.0
    hooks:
      - id: gitleaks

WHAT TO DO IF THE KEY HAS ALREADY LEAKED

  1. Immediately rotate the key with the provider — this is the first and most important step, more important than any git history cleanup.
  2. Check usage logs of the key for suspicious activity during the leak period.
  3. Only then if necessary, rewrite history (git filter-repo or BFG Repo-Cleaner) — but this does not replace rotation: repository copies with the key may already have been cloned or cached.

FREQUENTLY ASKED QUESTIONS

Does Gitleaks catch secrets in private repositories just as it does in public ones?

Yes, scanning does not depend on repository visibility — it works locally on the content you have access to. Repository privacy does not protect against leakage from an accidental fork or publication.

Are there many false positives?

The entropy detector sometimes flags random strings that resemble secrets (hashes, UUIDs). False positives can be added to an allowlist via config to avoid noise on each scan.

Does Gitleaks replace a secret store (Vault, Secrets Manager)?

No, these are different layers of protection. Gitleaks is a safety net against developer mistakes, while production secrets must still reside in a dedicated store, not in environment variables or code.

We review fresh open-source tools every day — from data pipelines to security scanners. If you want to be among the first to see what actually works in 2026 — subscribe to the REDDYX AI Telegram channel — new repositories every 30-60 minutes.

New repositories every 30 minutes

REDDYX AI scans GitHub 24/7 and ships the best AI/ML/Web3 projects to Telegram.

Join on Telegram

← All articles

Gitleaks in 2026: finding leaked API keys in a repository in 30 seconds | REDDYX AI