Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Gitleaks: scan your Git repositories for exposed secrets

By updated

Improve this page

Logo Gitleaks

Gitleaks detects the secrets exposed in your Git repositories, files and archives. Fast and configurable through a TOML file, it is often used in pre-commit hooks (scripts that Git runs automatically before each commit) and in CI/CD pipelines. Since 2026 it has been functionally frozen: its author now only publishes security fixes and develops Betterleaks instead, see the dedicated section. With more than 220 built-in rules (222 in the default configuration of v8.30.1), it identifies AWS keys, GitHub, Stripe and Slack tokens, and many more.

What you will learn

  • Understand how Gitleaks detects secrets with regex rules
  • Scan different sources: Git repositories, files, archives, standard input
  • Configure custom rules and exclusions
  • Integrate Gitleaks into your CI/CD pipelines (GitHub Actions, GitLab CI)
  • Use the advanced features: decoding, archives, baseline
  • Tie the lesson to the SOCLE: the requirement SOCLE-SEC-GEN-6 (in French), secret leak detection and response procedure, finds its detection tooling here.

The problem of secrets in code

A secret pushed to a public repository does not stay confidential long enough for you to notice. Crawling bots continuously watch GitHub's public events and test the credentials they find, sometimes before the author of the commit has even noticed the mistake. GitHub has industrialised the response with secret scanning and automatic revocation partnerships with cloud providers, which says a lot about how often this happens.

Secrets end up exposed for several reasons:

SituationExampleRisk
Committed config file.env missing from .gitignorePlaintext API keys in the Git history
Hardcoded passwordpassword = "admin123" in the codeAccess to the database
Token in the logsAuthorization: Bearer sk_live_...Account compromise
Base64-encoded secretYXdzX3NlY3JldF9hY2Nlc3Nfa2V5...False sense of security
Git historySecret deleted but present in an old commitStill reachable through git log

Deleting a secret from the code therefore does not erase it from the Git history, and malicious scanners analyse the whole history, not just the main branch.

How Gitleaks solves this problem

Gitleaks detects secrets with regex rules (regular expressions) preceded by a keyword filter. Unlike other tools, it does not check whether secrets are active: it favours speed and configurability.

How it works, in three steps

Gitleaks chains three steps, from reading the sources to displaying the result:

  1. Discovery: Gitleaks walks through the sources (Git, files, archives, stdin).
  2. Classification: each line is compared with the 220+ built-in rules.
  3. Report: the secrets found are displayed with their exact location.

The classification step is the one that determines the quality of the results, and it relies on two stacked mechanisms. Gitleaks first looks for keywords that are cheap to spot (AKIA, sk_live_, ghp_), then applies the complete regular expression only to the lines that passed this first filter. This pre-filtering explains the tool's speed, and it is also why a custom rule without a keywords field noticeably slows down a large repository.

Gitleaks strengths

Two rows of the table below matter more than the others: automatic decoding and archive scanning, which a plain regex search on raw text does not offer. Decoding finds base64-encoded secrets, and archive scanning covers build artifacts shipped as .tar.gz where configuration files linger. On the other hand, TOML configurability has a downside: without a team convention, every repository ends up with its own .gitleaks.toml and allowlists (lists of exceptions) that drift apart.

FeatureDetail
SpeedWritten in Go, very fast
ConfigurabilityCustomisable TOML rules
DecodingBase64, hex, URL encoding (v8.26+)
ArchivesZIP, tar.gz, 7z... (v8.27+)
Composite rulesMulti-part secrets (v8.28+)
IntegrationPre-commit, GitHub Actions, GitLab CI

What Gitleaks detects

Coverage is broad on recognisable token formats, that is, those with a fixed prefix and a constant length. It is much weaker on secrets with no identifiable shape: a database password or a home-made internal key will only be detected by the generic rule generic-api-key, which relies on entropy (a measure of how random a string looks) and generates many false positives. That is precisely the case where you need to write your own rules.

Gitleaks ships more than 220 rules to detect:

  • Cloud providers: AWS, GCP, Azure, DigitalOcean
  • Payments: Stripe, PayPal, Square
  • Authentication: GitHub, GitLab, Slack, Discord
  • Databases: PostgreSQL, MySQL, MongoDB in URLs
  • Private keys: RSA, DSA, ECDSA, OpenSSH
  • AI/ML: OpenAI, Anthropic, HuggingFace, Perplexity

Installation

Gitleaks is a static Go binary with no dependency, which makes the four methods below equivalent in their result. The choice criterion is traceability: on a development workstation, a version manager such as asdf or mise lets the whole team align on the same version. In CI, the container image pinned by digest (the fingerprint that identifies an image immutably) is preferable, otherwise an upstream version change can break a pipeline overnight on newly added rules.

Download the binary from the GitHub releases. The project publishes a checksums file next to each archive: fetch both and verify the checksum before extracting anything.

Terminal window
VERSION="8.30.1"
BASE="https://github.com/gitleaks/gitleaks/releases/download/v${VERSION}"
# Archive + checksums file published by the project
curl -fsSLO "${BASE}/gitleaks_${VERSION}_linux_x64.tar.gz"
curl -fsSLO "${BASE}/gitleaks_${VERSION}_checksums.txt"
# Checksum verification: must print "... : OK"
sha256sum --check --ignore-missing gitleaks_${VERSION}_checksums.txt
# Extract and install only if the check passed
tar xzf gitleaks_${VERSION}_linux_x64.tar.gz gitleaks
sudo install -m 0755 gitleaks /usr/local/bin/gitleaks
# Verification
gitleaks version
# 8.30.1

Main commands

Since version 8.19.0, Gitleaks uses three main commands: git, dir and stdin. The old detect and protect commands are deprecated but still functional.

Scanning a Git repository

The git command scans the full history of a Git repository, including all branches.

Terminal window
# Scan the repository in the current directory
gitleaks git
# Scan a specific repository
gitleaks git /path/to/my-repo
# Show the details (verbose mode)
gitleaks git -v
# Hide the banner
gitleaks git --no-banner
# Mask the value of secrets in the output (use it in CI)
gitleaks git -v --redact

Here is a sample output, captured with Gitleaks 8.30.1 on a test repository containing a GitHub token, value masked by --redact:

Finding: token = REDACTED
Secret: REDACTED
RuleID: github-pat
Entropy: 4.771928
File: config/app.cfg
Line: 1
Commit: 343f04f811221ca91b4f3a52eee9355b6cef8e5c
Author: dev
Email: dev@example.com
Date: 2026-09-30T19:41:32Z
Fingerprint: 343f04f811221ca91b4f3a52eee9355b6cef8e5c:config/app.cfg:github-pat:1

This output tells you four things:

  • The secret type: github-pat, a GitHub personal access token
  • The location: file config/app.cfg, line 1
  • The commit: hash, author, date
  • The fingerprint (Fingerprint): the identifier to reuse in a .gitleaksignore

Without --redact, the full value of the secret is displayed in plaintext: in a CI log, kept and readable by the whole team, that is a second leak.

To test your hooks, prefer a ghp_ token or a PEM private key to a fake AWS key: the aws-access-token rule requires AKIA followed by 16 characters from A-Z and 2-7, with an entropy of at least 3, and the sample key AKIAIOSFODNN7EXAMPLE from the AWS documentation is not detected (measured with v8.30.1).

Filtering by commit range

--log-opts passes its value as is to git log, without validation by Gitleaks. A misspelled option therefore makes git fail, not the scanner, and the error message you get is Git's. It is a lever to make a scan bearable on an old repository: limiting the range reduces the scan time, at the cost of a blind spot on the history that is not covered. Keep this reduction for pull request CI, and keep a scheduled full scan alongside it.

Terminal window
# Scan only the last 10 commits
gitleaks git --log-opts="--max-count=10"
# Scan a range of commits
gitleaks git --log-opts="HEAD~20..HEAD"
# Scan only a specific branch
gitleaks git --log-opts="--all develop..main"

Scanning before a commit (pre-commit)

These two options do not cover the same scope. --staged analyses what is in the Git index, that is, exactly what the commit is going to record. --pre-commit relies on a git diff and serves the project's official hook, which actually combines both. One point to watch: a secret already present in an earlier commit will be seen by neither of them; only gitleaks git on the full history will find it.

Terminal window
# Scan the staged files
gitleaks git --staged
# Scan with git diff (pre-commit mode)
gitleaks git --pre-commit

Scanning files or directories

dir ignores Git entirely: no history, no commit, no author in the report, only the path and the line. It is the command to use on a build artifact, an exported configuration folder or a directory extracted from a container image. Two behaviours to know: the .git/ directory is excluded from the walk, but hidden files and files listed in .gitignore are scanned, which often surfaces a local .env that gitleaks git would never see. The file and directory aliases designate the same command.

Terminal window
# Scan a directory
gitleaks dir /path/to/folder
# Scan a specific file
gitleaks dir config.env
# Scan several paths
gitleaks dir file1.log file2.env /etc/config/

Scanning standard input (stdin)

stdin opens the scan to anything that produces text, and that is where the leaks nobody looks for live: application logs, kubectl describe outputs, environment variable exports. The report obviously cannot point to a file or a commit, only to the line number in the stream. Be careful, however, with the command that feeds the pipe: kubectl logs on a chatty pod can send a considerable volume of text.

Terminal window
# Scan a file through a pipe
cat config.env | gitleaks stdin
# Scan the output of a command
kubectl logs deployment/my-app | gitleaks stdin
# Scan a file decompressed on the fly
gunzip -c logs.gz | gitleaks stdin

Advanced features

The four features that follow answer two needs. Decoding and archive scanning reveal secrets that a naive scan cannot see. The baseline and the output formats make the results usable day to day, without drowning teams in alerts that are already known.

Automatic decoding (v8.26+)

Gitleaks can automatically decode secrets encoded in base64, hexadecimal or URL encoding. By default, decoding is enabled with a depth of 5.

Terminal window
# Limit recursive decoding to depth 2
gitleaks dir /path --max-decode-depth=2
# Disable decoding
gitleaks dir /path --max-decode-depth=0

A base64-encoded Stripe token is detected:

# File containing: c2tfbGl2ZV80ZUMzOUhxTHlqV0Rhcmp0VDF6ZHA3ZGMK
Finding: sk_live_4eC39HqLyjWDarjtT1zdp7dc
Secret: sk_live_4eC39HqLyjWDarjtT1zdp7dc
RuleID: stripe-access-token
Tags: [decoded:base64 decode-depth:1]

The decoded:base64 and decode-depth:1 tags indicate that the secret was found after decoding.

Archive scanning (v8.27+)

Archive scanning is disabled by default (--max-archive-depth is 0), which surprises anyone who believes their .tar.gz files are covered: you have to enable it explicitly. Raise the depth sparingly: each additional level means an extraction to disk, and a booby-trapped archive containing thousands of nested files can saturate the temporary space of the runner (the machine that executes the pipeline).

Terminal window
# Scan an archive with depth 1
gitleaks dir archive.tar.gz --max-archive-depth=1
# Scan nested archives (depth 3)
gitleaks dir archives/ --max-archive-depth=3

Gitleaks reads, among others, the zip, tar, tar.gz, tar.bz2, tar.xz, 7z and rar formats.

The path in the results shows the location inside the archive:

File: nested.tar.gz!inner/files.tar!config/.env

This means: .env is in files.tar, which is in nested.tar.gz.

Baseline: ignoring known secrets

The baseline lets you ignore, in later scans, the secrets already identified. It is useful for a project whose history contains secrets that have already been dealt with (revoked) and where you only want to see new leaks; it does not exempt you from having revoked them.

  1. Create the baseline by generating an initial report

    Terminal window
    gitleaks git --report-path baseline.json
  2. Use the baseline for the following scans

    Terminal window
    gitleaks git --baseline-path baseline.json --report-path findings.json

    Only new secrets will be reported.

Output formats

The choice of format depends on who reads the report. SARIF (Static Analysis Results Interchange Format, a standard JSON format for analysis results) is the one that feeds the GitHub Code Scanning dashboard and, with GitLab Ultimate, the GitLab Security dashboard, JUnit makes leaks appear as failed tests in the interface of many CI systems, and JSON is the format to keep since it holds the fingerprint values you can reuse in a .gitleaksignore. The template format is reserved for internal reports that must follow an in-house template.

Terminal window
# JSON (default when --report-path is used)
gitleaks git -f json -r report.json
# CSV
gitleaks git -f csv -r report.csv
# SARIF (for GitHub Code Scanning)
gitleaks git -f sarif -r report.sarif
# JUnit (for CI/CD)
gitleaks git -f junit -r report.xml
# Custom template
gitleaks git -f template --report-template custom.tmpl -r report.txt
# JSON output to stdout
gitleaks git -f json -r -

Configuration

Gitleaks is configured through a .gitleaks.toml file versioned with the code. Two mistakes are costly here. The first is writing a configuration without useDefault = true, which silently disables the 222 built-in rules. The second is piling up exclusions until the scan returns nothing, which gives you a green pipeline and no security. Treat this file as production code: mandatory review, and a written justification for each exclusion.

Order of precedence

Gitleaks looks for its configuration in the order below, and the first source found wins:

  1. --config or -c option
  2. GITLEAKS_CONFIG environment variable (file path)
  3. GITLEAKS_CONFIG_TOML environment variable (TOML content)
  4. .gitleaks.toml file in the scanned directory

If no configuration is found, Gitleaks uses the default rules.

This order explains a frequent failure in CI: a correctly written .gitleaks.toml that is ignored, because a GITLEAKS_CONFIG variable lingers in the runner's environment and takes over. Note point 4 as well: the file is looked for in the scanned directory, not in the current directory. Scanning /opt/app from your $HOME therefore does not load the .gitleaks.toml in your $HOME. When in doubt, --log-level=debug shows the configuration actually used.

Extending the default configuration

The reflex to adopt is useDefault = true. Without this line, your file replaces the built-in rule set entirely instead of complementing it, and you end up with a scanner that only looks for your own patterns. disabledRules then lets you remove a rule that is too noisy, generic-api-key being the usual first candidate. Disable it only after writing your own rules, otherwise you lose the only detection that covers secrets with no known format.

.gitleaks.toml
# Configuration title
title = "Custom configuration"
# Extend the default configuration
[extend]
useDefault = true
# Disable some default rules
disabledRules = ["generic-api-key"]

Creating a custom rule

Three elements of this rule deserve attention. keywords is not decorative: it is the pre-filter that avoids applying the regex to every line of the repository, and forgetting it can multiply the scan time. entropy sets a disorder threshold below which a match is rejected, which discards test values such as int_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa. Finally, the regex follows Go's RE2 syntax, which supports neither backreferences nor lookahead: an expression copied from PCRE can be rejected on load.

.gitleaks.toml
[[rules]]
# Unique identifier
id = "internal-api-key"
# Description
description = "Company internal API key"
# Regular expression (Go syntax)
regex = '''int_[a-zA-Z0-9]{32}'''
# Keywords for pre-filtering (optimisation)
keywords = ["int_", "internal_api"]
# Minimum entropy (optional)
entropy = 3.5
# Tags for reporting
tags = ["internal", "api-key"]

Allowlists: excluding false positives

An allowlist is an accepted risk, not a fix: everything it covers stops being checked, including real secrets that might later land in the same place. Prefer the narrowest criteria possible. Excluding tests/ wholesale, as in the example below, is convenient but broad; targeting a specific fixtures file or a known value pattern, through regexes and stopwords, keeps the rest of the directory under watch. Document each entry with description: that is the field you reread six months later when wondering why a rule is silent.

.gitleaks.toml
# Global allowlist (applies to all rules)
[[allowlists]]
description = "Test files and documentation"
paths = [
'''tests/''',
'''fixtures/''',
'''\.md$''',
]
# Allowlist for a specific rule
[[rules]]
id = "aws-access-token"
[[rules.allowlists]]
description = "AWS test keys"
regexes = ['''AKIAIOSFODNN7EXAMPLE''']
stopwords = ["example", "test", "demo"]

Shared allowlists (v8.25+)

targetRules solves a concrete problem: before v8.25, excluding the same test directory for ten rules meant duplicating ten allowlist blocks, with the drift that follows when one is forgotten. The scope stays explicit, only the named rules are affected, which avoids the side effect of a global allowlist that also blinds the rules added later.

.gitleaks.toml
[[allowlists]]
# Apply to specific rules
targetRules = ["aws-access-token", "generic-api-key"]
description = "Test files"
paths = ['''tests/.*\.json$''']

Composite rules (v8.28+)

Composite rules address the case where one half of the secret is worthless on its own. An AWS identifier AKIA... alone allows nothing; combined with its secret key a few lines below, it gives full access. The withinLines parameter defines the accepted proximity window. A welcome side effect: by requiring both parts, this kind of rule reduces false positives on public identifiers quoted in documentation.

.gitleaks.toml
[[rules]]
id = "aws-keypair"
description = "AWS key/secret pair"
regex = '''AKIA[0-9A-Z]{16}'''
# Required rule: the secret must be close by
[[rules.required]]
id = "aws-secret-pattern"
withinLines = 5 # The secret must be within the next 5 lines

Ignoring a specific secret in the code

The gitleaks:allow comment, placed on the line concerned, tells Gitleaks to ignore it. This annotation lives in the code, which makes it visible in code review, unlike an allowlist buried in a configuration file. That is its main benefit. It is also its main danger: anyone who proposes a change can stick it on a real leak to get a pipeline through. On a sensitive repository, the --ignore-gitleaks-allow option lets you run an audit scan that neutralises these annotations and reveals what they hide.

# This key is an example for the documentation
AWS_KEY = "AKIAIOSFODNN7EXAMPLE" # gitleaks:allow

The .gitleaksignore file

The .gitleaksignore file, versioned with the repository, lists the fingerprints (fingerprint) of the findings to ignore. The fingerprint combines the commit, the file, the rule identifier and the line number. This precision is a strength, since each exception is surgical, but also a weakness: rewriting the history or moving the line changes the fingerprint, and the exception silently stops applying. Take these values from a JSON report rather than composing them by hand, and remember that an entry here never exempts you from revoking the secret concerned.

.gitleaksignore
# Format: fingerprint (from the JSON report)
fbc14303ffbf8fb1c2c1914e8dda7d0121633aca:config.env:aws-access-token:4
77b2a3e56973785a52ba4ae4b8dac61d4bac016f:keys:private-key:6

CI/CD integration

The three integrations below do not replace each other, they complement each other. The pre-commit hook is fast and local but can be bypassed with git commit --no-verify, whereas the CI only acts after the push but cannot be bypassed from the developer's workstation. A healthy chain combines both: the hook for developer comfort, the CI as a safety net.

Pre-commit hook

Block secrets before they are committed. The Gitleaks repository publishes three hook identifiers: gitleaks compiles the binary in Go, gitleaks-docker goes through the container image, gitleaks-system reuses the binary already installed on the workstation. The first is the simplest, the third the fastest if your team already manages the version through asdf or mise.

.pre-commit-config.yaml
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.30.1
hooks:
- id: gitleaks
  1. Install pre-commit

    Terminal window
    pip install pre-commit
  2. Create the configuration file .pre-commit-config.yaml, with the content of the block above

  3. Install the hooks

    Terminal window
    pre-commit install
  4. Test

    Terminal window
    git add . && git commit -m "test"
    # If a secret is detected, the commit will be blocked

To disable the hook temporarily:

Terminal window
SKIP=gitleaks git commit -m "skip check"

GitHub Actions

Use the official Gitleaks action. Three points of this workflow deserve your attention. fetch-depth: 0 is mandatory: without it, the checkout fetches only one commit and the history scan sees nothing. The actions are pinned by SHA rather than by tag, because a Git tag can be moved to another commit by the maintainer or by an attacker who took over the repository. Finally, permissions: {} at the workflow level removes all default permissions, and each job gets back only what it needs: contents: read to clone, pull-requests: write because the action comments on pull requests.

.github/workflows/gitleaks.yml
name: Gitleaks
on:
push:
branches: [main]
pull_request:
permissions: {}
jobs:
gitleaks:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # Important: fetch the whole history
persist-credentials: false
- uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Only for repositories owned by an organisation
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}

persist-credentials: false prevents actions/checkout from leaving the authentication token in the runner's .git/config file, where a later step of the job could read it back and exfiltrate it.

GitLab CI

Integrate Gitleaks into your merge requests. Two details determine whether the job works. First, the path to scan is a positional argument of the git command, not an option: the old --source flag has disappeared and now returns unknown flag. Second, GIT_DEPTH: 0 is essential, because GitLab clones with a limited depth by default, and a history scan on a truncated clone proves nothing.

.gitlab-ci.yml
stages:
- security
gitleaks:
stage: security
image: ghcr.io/gitleaks/gitleaks:v8.30.1@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9ab65d25e6bc8abbb7f
variables:
GIT_DEPTH: 0 # full history, otherwise the scan is blind
script:
- gitleaks git "$CI_PROJECT_DIR" --verbose
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == "main"'
allow_failure: false

The exit code is 1 by default when a leak is found, so --exit-code is only useful to change that value. Combined with allow_failure: false, the pipeline does stop on detection.

To feed the GitLab Security dashboard, generate a SARIF report and declare it under the sarif key of artifacts:reports (not sast, which is reserved for reports in the GitLab format). This ingestion requires GitLab Ultimate (introduced in 18.11 behind a feature flag, generally available in 19.2).

Another constraint: GitLab only ingests the findings of a job that succeeds. Yet gitleaks exits with code 1 as soon as it finds a secret, which fails the job and prevents the report from coming up. Hence the --exit-code 0 in the script below, which defines a second job, gitleaks-rapport, to add next to the first one and not in its place. This choice changes its role: it reports instead of blocking, and the blocking job above remains the one that stops the pipeline.

Keep the paths key in addition to reports: without it, the file cannot be downloaded from the interface, which complicates the analysis when the dashboard is not available in your GitLab edition.

.gitlab-ci.yml
gitleaks-rapport:
stage: security
image: ghcr.io/gitleaks/gitleaks:v8.30.1@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9ab65d25e6bc8abbb7f
variables:
GIT_DEPTH: 0
script:
- gitleaks git "$CI_PROJECT_DIR" -f sarif -r gl-gitleaks.sarif --exit-code 0
artifacts:
reports:
sarif: gl-gitleaks.sarif
paths:
- gl-gitleaks.sarif

Troubleshooting

One point before reading this table: "no results" is not enough to conclude. Before stating that a repository is clean, check that the scan actually saw something: the scanned ~N bytes line of the output must show a volume consistent with the size of the repository. A 0 bytes almost always signals a truncated clone in CI or a wrong starting path, not the absence of secrets.

SymptomLikely causeSolution
No result on a test AWS keyThe fake key does not satisfy the aws-access-token rule (character outside A-Z2-7, entropy too low, ...EXAMPLE sample key)Test with a ghp_ token or a PEM private key
No result in CI, scanned ~0 bytesTruncated clone or wrong starting pathfetch-depth: 0 or GIT_DEPTH: 0, and check the scanned path
Many false positivesTest secrets, examplesUse .gitleaksignore or allowlists
Very slow scanLarge Git historyUse --log-opts="--max-count=100"
"no such file" errorRemote URL not supportedClone the repo locally first
Encoded secret not detectedDecoding disabledCheck --max-decode-depth
Archive not scannedArchive scanning disabledEnable --max-archive-depth=1

Debug logs

The debug level answers the first question to ask when behaviour is unexpected: which configuration was loaded and which rules are active. The trace level goes down to the detail of every match tested and quickly floods a terminal; keep it for analysing a custom rule that does not fire, redirecting the output to a file.

Terminal window
# Debug level
gitleaks git --log-level=debug
# Trace level (very verbose)
gitleaks git --log-level=trace

Slow file to scan

A scan that drags is often caused by a few specific files rather than by general slowness: large archives, single-line minified files, datasets committed by mistake. Since v8.26, Gitleaks reports them in the debug logs, which lets you know what you are excluding before reducing the scan coverage.

Terminal window
gitleaks git --log-level=debug 2>&1 | grep "slow"

Once the files are identified, you have two options: add them to an allowlist, or cap the analysed size with --max-target-megabytes. In both cases they are no longer examined, so exclude only what cannot contain a secret:

Terminal window
# Ignore files > 10 MB
gitleaks git --max-target-megabytes=10

Best practices

Detecting a secret costs more than preventing it from existing. The three areas below therefore follow this order of value: prevention first, detection next, remediation as a last resort, because at that stage the secret is already compromised.

Prevention: keep secrets out of Git

These four measures reinforce one another, but only one really changes the game: the secrets manager. As long as a secret exists as a string in a file on the development workstation, it will sooner or later be committed by accident. Hooks and .gitignore reduce that probability; the secrets manager, with injection at runtime, removes the cause: the secret is no longer written to a file in the repository.

  1. Pre-commit hooks: block commits that contain secrets
  2. .gitignore files: exclude .env, *.pem, credentials.json
  3. Secrets manager: use OpenBao (in French), Vault, AWS Secrets Manager or Passbolt (in French)
  4. Environment variables: inject secrets at runtime

Detection: scan regularly

The pull request scan and the periodic scan do not look for the same thing. The first works on the changes of the pull request and must stay fast so as not to slow teams down. The second goes over the full history again and catches what yesterday's rules could not detect: every new version of a scanner that is still developed adds rules, so a repository declared clean last year is not necessarily clean today. Gitleaks, being frozen, will not add any: that is an argument for evaluating Betterleaks on periodic scans.

  1. CI/CD: scan every pull request and every push
  2. Periodic scans: audit the whole organisation every week
  3. New repositories: plug in the secrets scanner from day one

Remediation: act on findings

The order of this list is an order of priority, not a set of options. Rotation comes before everything else, including before cleaning the history: as long as the secret remains valid, rewriting the commits does not protect you from clones made in the meantime. For step 3, git filter-branch is deprecated by the Git project itself in favour of git-filter-repo, faster and less error-prone; BFG Repo-Cleaner remains a valid alternative.

  1. Immediate rotation: revoke and recreate the exposed secret
  2. Access audit: check the usage logs of the compromised secret
  3. History cleanup: use git filter-repo or BFG Repo-Cleaner
  4. Post-mortem: understand how the secret was exposed

Gitleaks or Betterleaks: should you switch tools?

Gitleaks remains usable and maintained for security, but it will no longer evolve: its README declares it "feature complete", and its author announces that he is putting his efforts into Betterleaks. The repository's exact sentence is "Gitleaks is feature complete. I'm not merging new features into Gitleaks. Future releases will be security patches only." The latest version, 8.30.1, dates from 21 March 2026; since then the repository has only received dependency updates. The project is not archived: a pre-commit or a CI that uses it today keeps working.

Betterleaks (GitHub repository, MIT licence) is, according to its README, maintained "by the folks who made Gitleaks, including the original author", with the backing of Aikido Security. It is active: version 1.9.0 on 29 September 2026, then a 2.0 in preview (five preview releases between 30 September and 28 October 2026). It offers betterleaks git /path/to/repo to scan a repository and betterleaks dir /path for files, a syntax close to Gitleaks. Version 1 reads a .gitleaks.toml and accepts a .gitleaksignore, but the equivalence of the results is not guaranteed and its README mentions no dedicated action: do not take the migration to be seamless. The Betterleaks guide covers its versions, its installation and its differences with Gitleaks; this section only says whether to switch tools.

Depending on your situation, the choice boils down to this:

SituationReasonable choice
Pre-commit and CI already in place with Gitleakskeep Gitleaks, pinned, and follow its security fixes
New project that wants the new detectionsevaluate Betterleaks, preferably a stable version rather than the 2.0 preview
Need to check that a found secret is still activeTruffleHog or Kingfisher, or Betterleaks with its validation turned on, compared in the section below

Gitleaks, Betterleaks, TruffleHog or Kingfisher: which one should you choose?

Gitleaks is the most minimal of the four: it detects secrets in the Git history, in files and in standard input, and its documentation announces neither verification of whether a secret is active nor revocation. The table sets it against its three neighbours, two of which (Betterleaks and Kingfisher) are more recent.

The table compares the four scanners on what matters when you choose: where they look, what they do with a secret they find, and how they fit into a delivery pipeline. Every cell comes from the tool's own documentation at the version shown in the header. When that documentation says nothing about a capability, the cell reads "not documented": this does not prove the tool is unable to do it, only that its documentation does not announce it.

CriterionGitleaks 8.30.1Betterleaks 1.9.0TruffleHog 3.99.7Kingfisher 2.16.0
Git repository and historyyes, gitleaks git (via git log -p)yes, betterleaks gityes, trufflehog gityes, history included
Remote repository, organizationnot documented (three modes: git, dir, stdin)GitHub (organization, user, PRs, issues, Actions, releases), GitLab (group, project, merge requests), Hugging FaceGitHub (--org), GitLab, Hugging FaceGitHub, GitLab, Azure Repos, Bitbucket, Gitea, Hugging Face
Files and directoriesyes, gitleaks diryes, betterleaks diryes, trufflehog filesystemyes
Container imagenot documentednot documentedyes, trufflehog dockeryes, kingfisher scan docker
Other sourcesstandard inputstandard input, S3 (including Cloudflare R2)S3, GCS, Postman, Jenkins, Elasticsearch, CircleCI, Travis CI, syslog, standard inputS3, GCS, Azure Blob Storage, Jira, Confluence, Slack, Teams, Postman
Checks that a secret is activenot documentedyes, through a validate expression in the rule, opt-in only, --validation in 1.9.0 (-v or --validate in version 2); statuses valid, invalid, revoked, unknown, erroryes, by calling the provider's API, enabled by default (--no-verification turns it off)yes, enabled by default (--no-validate turns it off)
Measures the blast radiusnot documentednot documented in 1.9.0; the version 2 preview adds -a or --analyze (account, capabilities and severity of valid tokens)yes, trufflehog analyze (permissions and reachable resources) for some credential typesyes, --blast-radius for the supported providers (identities, permissions, resources)
Revokes a secretnot documentednot documented in 1.9.0 (revocation only appears there as a status returned by validation); the version 2 preview announces betterleaks revokenot documentedyes, kingfisher revoke, for the supported providers
Pre-commit hookyes, pre-commit hooks providedyes, pre-commit hooks providedyes, documented (hooksPath, pre-commit framework, Husky)yes, install script and pre-commit framework
CI integrationgitleaks-action action (separate repository), Docker imageDocker image ghcr.io/betterleaks/betterleaks; no dedicated action in the READMEGitHub action trufflesecurity/trufflehog, Docker imageDocker image ghcr.io/mongodb/kingfisher; no dedicated action in the documentation
Output formatsJSON, CSV, JUnit, SARIF, templateJSON, CSV, JUnit, SARIF, template (JSONL for validate)text, JSON, SARIF, GitHub Actions formathuman-readable text, JSON, JSONL, BSON, TOON, SARIF, HTML
LicenseMITMITAGPL-3.0Apache-2.0
LanguageGoGoGoRust

Survey carried out on 2026-10-30 on the latest published version of each tool. Versions move fast: check the date before relying on a cell.

The right tool depends first on what you want to do with a secret once it is found. To block a commit or a merge, all four will do, and Gitleaks is enough when its rules are mastered and it is already in place. To tell live secrets from leftover examples, you need a tool that validates: Betterleaks (opt-in), TruffleHog or Kingfisher. To know what an active token opens up, TruffleHog (analyze) and Kingfisher (--blast-radius) answer, each on the providers it supports; Betterleaks adds a comparable analysis in its version 2, still a preview. To act without waiting for the owner of the secret, only Kingfisher documents revocation from the command line in the stable versions surveyed; Betterleaks announces one for its version 2 as well.

If the target goes beyond the repository (issues, chat, images, buckets), look at the "Other sources" row: the scope varies a lot from one tool to another. An AGPL-3.0 license can also weigh in the choice depending on how your organization uses the tool. Finally, a scanner that finds nothing proves nothing: test the one you pick on a repository containing a known fake secret before wiring it into CI. To freeze what already exists and block only new findings, the detect-secrets guide (in French) covers a baseline approach, and the comparison of secret detection tools widens the view to other candidates.


Key points

  1. Three commands cover the uses: git for the history, dir for files, stdin for a stream.
  2. More than 220 rules are built in (AWS, Stripe, GitHub, Slack...), and a configuration without useDefault = true replaces them instead of complementing them.
  3. Base64, hex and URL decoding is active by default, at depth 5.
  4. Archive scanning is disabled by default: enable it with --max-archive-depth.
  5. A baseline sets aside the secrets already dealt with and only reports what is new.
  6. A pre-commit hook blocks secrets before they reach Git.
  7. An exposed secret is a compromised secret: rotation comes before cleaning the history.
  8. In CI, mask the values with --redact, pin the action by SHA and the image by digest, set permissions: {} and fetch the full history.
  9. For the GitLab report, declare artifacts:reports:sarif (not sast), with the Ultimate edition and --exit-code 0: the job then reports instead of blocking.
  10. Gitleaks is frozen (security fixes only since 2026); its author develops Betterleaks, to evaluate for a new project.
  11. For the SOCLE-SEC-GEN-6 requirement, the expected evidence is a detection system, here a Gitleaks scan wired as a hook and in CI on your repositories, together with a written response procedure: who revokes, who renews, within what time. The scanner only provides the first half of this evidence.

Knowledge check

Check that you have the essentials of this guide. The questions only cover what has just been explained here.

Knowledge check

Check what you have learned with this interactive quiz

6 questions
6 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer

Resources

The links below point to the official sources: the project, its default configuration (where the built-in rules are listed), the GitHub action, and Betterleaks, the successor project covered above.