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:
| Situation | Example | Risk |
|---|---|---|
| Committed config file | .env missing from .gitignore | Plaintext API keys in the Git history |
| Hardcoded password | password = "admin123" in the code | Access to the database |
| Token in the logs | Authorization: Bearer sk_live_... | Account compromise |
| Base64-encoded secret | YXdzX3NlY3JldF9hY2Nlc3Nfa2V5... | False sense of security |
| Git history | Secret deleted but present in an old commit | Still 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:
- Discovery: Gitleaks walks through the sources (Git, files, archives, stdin).
- Classification: each line is compared with the 220+ built-in rules.
- 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.
| Feature | Detail |
|---|---|
| Speed | Written in Go, very fast |
| Configurability | Customisable TOML rules |
| Decoding | Base64, hex, URL encoding (v8.26+) |
| Archives | ZIP, tar.gz, 7z... (v8.27+) |
| Composite rules | Multi-part secrets (v8.28+) |
| Integration | Pre-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.
VERSION="8.30.1"BASE="https://github.com/gitleaks/gitleaks/releases/download/v${VERSION}"
# Archive + checksums file published by the projectcurl -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 passedtar xzf gitleaks_${VERSION}_linux_x64.tar.gz gitleakssudo install -m 0755 gitleaks /usr/local/bin/gitleaks
# Verificationgitleaks version# 8.30.1With Homebrew:
brew install gitleaks
# Verificationgitleaks versionThe Docker image suits CI well. Do not use the latest tag: it changes without notice and makes your pipelines non-reproducible. Pin the version, and the digest as soon as the scan drives a build block.
# GitHub Container Registry, pinned by digestIMG="ghcr.io/gitleaks/gitleaks:v8.30.1@sha256:c00b6bd0aeb3071cbcb79009cb16a60dd9e0a7c60e2be9ab65d25e6bc8abbb7f"docker pull "$IMG"
# Scan a local directory read-onlydocker run --rm -v "$PWD:/path:ro" "$IMG" dir /path
# The same content is published on Docker Hub as zricethezav/gitleaksWith asdf, the active version is declared in a .tool-versions file, which you can version with the repository to align the team. The asdf set syntax below applies to asdf 0.16 and later; on earlier versions, the equivalent command is asdf global gitleaks <version>.
# Add the pluginasdf plugin add gitleaks
# Install a specific versionasdf install gitleaks 8.30.1
# Set it as the global version (written to ~/.tool-versions)asdf set --home gitleaks 8.30.1Main 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.
# Scan the repository in the current directorygitleaks git
# Scan a specific repositorygitleaks git /path/to/my-repo
# Show the details (verbose mode)gitleaks git -v
# Hide the bannergitleaks git --no-banner
# Mask the value of secrets in the output (use it in CI)gitleaks git -v --redactHere is a sample output, captured with Gitleaks 8.30.1 on a test repository containing a GitHub token, value masked by --redact:
Finding: token = REDACTEDSecret: REDACTEDRuleID: github-patEntropy: 4.771928File: config/app.cfgLine: 1Commit: 343f04f811221ca91b4f3a52eee9355b6cef8e5cAuthor: devEmail: dev@example.comDate: 2026-09-30T19:41:32ZFingerprint: 343f04f811221ca91b4f3a52eee9355b6cef8e5c:config/app.cfg:github-pat:1This 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.
# Scan only the last 10 commitsgitleaks git --log-opts="--max-count=10"
# Scan a range of commitsgitleaks git --log-opts="HEAD~20..HEAD"
# Scan only a specific branchgitleaks 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.
# Scan the staged filesgitleaks git --staged
# Scan with git diff (pre-commit mode)gitleaks git --pre-commitScanning 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.
# Scan a directorygitleaks dir /path/to/folder
# Scan a specific filegitleaks dir config.env
# Scan several pathsgitleaks 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.
# Scan a file through a pipecat config.env | gitleaks stdin
# Scan the output of a commandkubectl logs deployment/my-app | gitleaks stdin
# Scan a file decompressed on the flygunzip -c logs.gz | gitleaks stdinAdvanced 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.
# Limit recursive decoding to depth 2gitleaks dir /path --max-decode-depth=2
# Disable decodinggitleaks dir /path --max-decode-depth=0A base64-encoded Stripe token is detected:
# File containing: c2tfbGl2ZV80ZUMzOUhxTHlqV0Rhcmp0VDF6ZHA3ZGMK
Finding: sk_live_4eC39HqLyjWDarjtT1zdp7dcSecret: sk_live_4eC39HqLyjWDarjtT1zdp7dcRuleID: stripe-access-tokenTags: [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).
# Scan an archive with depth 1gitleaks dir archive.tar.gz --max-archive-depth=1
# Scan nested archives (depth 3)gitleaks dir archives/ --max-archive-depth=3Gitleaks 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/.envThis 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.
-
Create the baseline by generating an initial report
Terminal window gitleaks git --report-path baseline.json -
Use the baseline for the following scans
Terminal window gitleaks git --baseline-path baseline.json --report-path findings.jsonOnly 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.
# JSON (default when --report-path is used)gitleaks git -f json -r report.json
# CSVgitleaks 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 templategitleaks git -f template --report-template custom.tmpl -r report.txt
# JSON output to stdoutgitleaks 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:
--configor-coptionGITLEAKS_CONFIGenvironment variable (file path)GITLEAKS_CONFIG_TOMLenvironment variable (TOML content).gitleaks.tomlfile 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.
# Configuration titletitle = "Custom configuration"
# Extend the default configuration[extend]useDefault = true
# Disable some default rulesdisabledRules = ["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.
[[rules]]# Unique identifierid = "internal-api-key"
# Descriptiondescription = "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 reportingtags = ["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.
# 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.
[[allowlists]]# Apply to specific rulestargetRules = ["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.
[[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 linesIgnoring 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 documentationAWS_KEY = "AKIAIOSFODNN7EXAMPLE" # gitleaks:allowThe .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.
# Format: fingerprint (from the JSON report)fbc14303ffbf8fb1c2c1914e8dda7d0121633aca:config.env:aws-access-token:477b2a3e56973785a52ba4ae4b8dac61d4bac016f:keys:private-key:6CI/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.
repos: - repo: https://github.com/gitleaks/gitleaks rev: v8.30.1 hooks: - id: gitleaks-
Install pre-commit
Terminal window pip install pre-commit -
Create the configuration file
.pre-commit-config.yaml, with the content of the block above -
Install the hooks
Terminal window pre-commit install -
Test
Terminal window git add . && git commit -m "test"# If a secret is detected, the commit will be blocked
To disable the hook temporarily:
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.
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.
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: falseThe 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.
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.sarifTroubleshooting
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.
| Symptom | Likely cause | Solution |
|---|---|---|
| No result on a test AWS key | The 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 bytes | Truncated clone or wrong starting path | fetch-depth: 0 or GIT_DEPTH: 0, and check the scanned path |
| Many false positives | Test secrets, examples | Use .gitleaksignore or allowlists |
| Very slow scan | Large Git history | Use --log-opts="--max-count=100" |
| "no such file" error | Remote URL not supported | Clone the repo locally first |
| Encoded secret not detected | Decoding disabled | Check --max-decode-depth |
| Archive not scanned | Archive scanning disabled | Enable --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.
# Debug levelgitleaks git --log-level=debug
# Trace level (very verbose)gitleaks git --log-level=traceSlow 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.
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:
# Ignore files > 10 MBgitleaks git --max-target-megabytes=10Best 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.
- Pre-commit hooks: block commits that contain secrets
.gitignorefiles: exclude.env,*.pem,credentials.json- Secrets manager: use OpenBao (in French), Vault, AWS Secrets Manager or Passbolt (in French)
- 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.
- CI/CD: scan every pull request and every push
- Periodic scans: audit the whole organisation every week
- 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.
- Immediate rotation: revoke and recreate the exposed secret
- Access audit: check the usage logs of the compromised secret
- History cleanup: use
git filter-repoor BFG Repo-Cleaner - 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:
| Situation | Reasonable choice |
|---|---|
| Pre-commit and CI already in place with Gitleaks | keep Gitleaks, pinned, and follow its security fixes |
| New project that wants the new detections | evaluate Betterleaks, preferably a stable version rather than the 2.0 preview |
| Need to check that a found secret is still active | TruffleHog 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.
| Criterion | Gitleaks 8.30.1 | Betterleaks 1.9.0 | TruffleHog 3.99.7 | Kingfisher 2.16.0 |
|---|---|---|---|---|
| Git repository and history | yes, gitleaks git (via git log -p) | yes, betterleaks git | yes, trufflehog git | yes, history included |
| Remote repository, organization | not documented (three modes: git, dir, stdin) | GitHub (organization, user, PRs, issues, Actions, releases), GitLab (group, project, merge requests), Hugging Face | GitHub (--org), GitLab, Hugging Face | GitHub, GitLab, Azure Repos, Bitbucket, Gitea, Hugging Face |
| Files and directories | yes, gitleaks dir | yes, betterleaks dir | yes, trufflehog filesystem | yes |
| Container image | not documented | not documented | yes, trufflehog docker | yes, kingfisher scan docker |
| Other sources | standard input | standard input, S3 (including Cloudflare R2) | S3, GCS, Postman, Jenkins, Elasticsearch, CircleCI, Travis CI, syslog, standard input | S3, GCS, Azure Blob Storage, Jira, Confluence, Slack, Teams, Postman |
| Checks that a secret is active | not documented | yes, 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, error | yes, 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 radius | not documented | not 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 types | yes, --blast-radius for the supported providers (identities, permissions, resources) |
| Revokes a secret | not documented | not documented in 1.9.0 (revocation only appears there as a status returned by validation); the version 2 preview announces betterleaks revoke | not documented | yes, kingfisher revoke, for the supported providers |
| Pre-commit hook | yes, pre-commit hooks provided | yes, pre-commit hooks provided | yes, documented (hooksPath, pre-commit framework, Husky) | yes, install script and pre-commit framework |
| CI integration | gitleaks-action action (separate repository), Docker image | Docker image ghcr.io/betterleaks/betterleaks; no dedicated action in the README | GitHub action trufflesecurity/trufflehog, Docker image | Docker image ghcr.io/mongodb/kingfisher; no dedicated action in the documentation |
| Output formats | JSON, CSV, JUnit, SARIF, template | JSON, CSV, JUnit, SARIF, template (JSONL for validate) | text, JSON, SARIF, GitHub Actions format | human-readable text, JSON, JSONL, BSON, TOON, SARIF, HTML |
| License | MIT | MIT | AGPL-3.0 | Apache-2.0 |
| Language | Go | Go | Go | Rust |
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
- Three commands cover the uses:
gitfor the history,dirfor files,stdinfor a stream. - More than 220 rules are built in (AWS, Stripe, GitHub, Slack...), and a configuration without
useDefault = truereplaces them instead of complementing them. - Base64, hex and URL decoding is active by default, at depth 5.
- Archive scanning is disabled by default: enable it with
--max-archive-depth. - A baseline sets aside the secrets already dealt with and only reports what is new.
- A pre-commit hook blocks secrets before they reach Git.
- An exposed secret is a compromised secret: rotation comes before cleaning the history.
- In CI, mask the values with
--redact, pin the action by SHA and the image by digest, setpermissions: {}and fetch the full history. - For the GitLab report, declare
artifacts:reports:sarif(notsast), with the Ultimate edition and--exit-code 0: the job then reports instead of blocking. - Gitleaks is frozen (security fixes only since 2026); its author develops Betterleaks, to evaluate for a new project.
- 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
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
Review
(0/0)Result saved on this device. It will be sent to your account at the next sync. Sync now
Score by domain
A domain groups several guides and gets several questions, so its score is more reliable than a per-topic score, which often rests on a single question.
Summary
Strengths
No topic passed at 80% on at least two questions yet.
Weak areas
No topic below the pass mark.
Recommended next
Hints before you try again?
Continue the course: Betterleaks: detect secrets, then check whether they are still active
A new full quiz with random questions
Work again only on the questions you missed
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.
- Official site: github.com/gitleaks/gitleaks
- Default configuration: gitleaks.toml
- GitHub Action: gitleaks-action
- Betterleaks, the author's next project: github.com/betterleaks/betterleaks