Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

gitleaks

> DevOps
Open source

Find secrets with Gitleaks šŸ”‘

28.4K stars0 likes2 views
WebsiteGitHub

About

Find secrets with Gitleaks šŸ”‘

Gitleaks

ā”Œā”€ā—‹ā”€ā”€ā”€ā”
│ │╲  │
│ │ ā—‹ │
│ ā—‹ ā–‘ │
ā””ā”€ā–‘ā”€ā”€ā”€ā”˜

[!WARNING] Gitleaks is feature complete. I'm not merging new features into Gitleaks. Future releases will be security patches only. I'm shifting my focus to Betterleaks

GitHub Action Test Docker Hub Gitleaks Action GoDoc GoReportCard License

Gitleaks is a tool for detecting secrets like passwords, API keys, and tokens in git repos, files, and whatever else you wanna throw at it via stdin. If you wanna learn more about how the detection engine works check out this blog: Regex is (almost) all you need.

āžœ  ~/code(master) gitleaks git -v

    ā—‹
    │╲
    │ ā—‹
    ā—‹ ā–‘
    ā–‘    gitleaks

Finding:     "export BUNDLE_ENTERPRISE__CONTRIBSYS__COM=cafebabe:deadbeef",
Secret:      cafebabe:deadbeef
RuleID:      sidekiq-secret
Entropy:     2.609850
File:        cmd/generate/config/rules/sidekiq.go
Line:        23
Commit:      cd5226711335c68be1e720b318b7bc3135a30eb2
Author:      John
Email:       [email protected]
Date:        2022-08-03T12:31:40Z
Fingerprint: cd5226711335c68be1e720b318b7bc3135a30eb2:cmd/generate/config/rules/sidekiq.go:sidekiq-secret:23

Getting Started

Gitleaks can be installed using Homebrew, Docker, or Go. Gitleaks is also available in binary form for many popular platforms and OS types on the releases page. In addition, Gitleaks can be implemented as a pre-commit hook directly in your repo or as a GitHub action using Gitleaks-Action.

Installing

bash
# MacOS
brew install gitleaks

# Docker (DockerHub)
docker pull zricethezav/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest [COMMAND] [OPTIONS] [SOURCE_PATH]

# Docker (ghcr.io)
docker pull ghcr.io/gitleaks/gitleaks:latest
docker run -v ${path_to_host_folder_to_scan}:/path ghcr.io/gitleaks/gitleaks:latest [COMMAND] [OPTIONS] [SOURCE_PATH]

# From Source (make sure `go` is installed)
git clone https://github.com/gitleaks/gitleaks.git
cd gitleaks
make build

Pre-Commit

  1. Install pre-commit from https://pre-commit.com/#install

  2. Create a .pre-commit-config.yaml file at the root of your repository with the following content:

    repos:
      - repo: https://github.com/gitleaks/gitleaks
        rev: v8.24.2
        hooks:
          - id: gitleaks

    for a native execution of gitleaks or use the gitleaks-docker pre-commit ID for executing gitleaks using the official Docker images

  3. Auto-update the config to the latest repos' versions by executing pre-commit autoupdate

  4. Install with pre-commit install

  5. Now you're all set!

āžœ git commit -m "this commit contains a secret"
Detect hardcoded secrets.................................................Failed

Note: to disable the gitleaks pre-commit hook you can prepend SKIP=gitleaks to the commit command and it will skip running gitleaks

āžœ SKIP=gitleaks git commit -m "skip gitleaks check"
Detect hardcoded secrets................................................Skipped

Usage

…

Commands

āš ļø v8.19.0 introduced a change that deprecated detect and protect. Those commands are still available but are hidden in the --help menu. Take a look at this gist for easy command translations. If you find v8.19.0 broke an existing command (detect/protect), please open an issue.

There are three scanning modes: git, dir, and stdin.

Git

The git command lets you scan local git repos. Under the hood, gitleaks uses the git log -p command to scan patches. You can configure the behavior of git log -p with the log-opts option. For example, if you wanted to run gitleaks on a range of commits you could use the following command: gitleaks git -v --log-opts="--all commitA..commitB" path_to_repo. See the git log documentation for more information. If there is no target specified as a positional argument, then gitleaks will attempt to scan the current working directory as a git repo.

Dir

The dir (aliases include files, directory) command lets you scan directories and files. Example: gitleaks dir -v path_to_directory_or_file. If there is no target specified as a positional argument, then gitleaks will scan the current working directory.

Stdin

You can also stream data to gitleaks with the stdin command. Example: cat some_file | gitleaks -v stdin

Creating a baseline

When scanning large repositories or repositories with a long history, it can be convenient to use a baseline. When using a baseline, gitleaks will ignore any old findings that are present in the baseline. A baseline can be any gitleaks report. To create a gitleaks report, run gitleaks with the --report-path parameter.

gitleaks git --report-path gitleaks-report.json # This will save the report in a file called gitleaks-report.json

Once as baseline is created it can be applied when running the detect command again:

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

After running the detect command with the --baseline-path parameter, report output (findings.json) will only contain new issues.

Pre-Commit hook

You can run Gitleaks as a pre-commit hook by copying the example pre-commit.py script into your .git/hooks/ directory.

Load Configuration

The order of precedence is:

  1. --config/-c option:
    bash
    gitleaks git --config /home/dev/customgitleaks.toml .
  2. Environment variable GITLEAKS_CONFIG with the file path:
    bash
    export GITLEAKS_CONFIG="/home/dev/customgitleaks.toml"
    gitleaks git .
  3. Environment variable GITLEAKS_CONFIG_TOML with the file content:
    bash
    export GITLEAKS_CONFIG_TOML=`cat customgitleaks.toml`
    gitleaks git .
  4. A .gitleaks.toml file within the target path:
    bash
    gitleaks git .

If none of the four options are used, then gitleaks will use the default config.

Configuration

Gitleaks offers a configuration format you can follow to write your own secret detection rules:

…

Refer to the default gitleaks config for examples or follow the contributing guidelines if you would like to contribute to the default configuration. Additionally, you can check out this gitleaks blog post which covers advanced configuration setups.

Additional Configuration

Composite Rules (Multi-part or required Rules)

In v8.28.0 Gitleaks introduced composite rules, which are made up of a single "primary" rule and one or more auxiliary or required rules. To create a composite rule, add a [[rules.required]] table to the primary rule specifying an id and optionally withinLines and/or withinColumns proximity constraints. A fragment is a chunk of content that Gitleaks processes at once (typically a file, part of a file, or git diff), and proximity matching instructs the primary rule to only report a finding if the auxiliary required rules also find matches within the specified area of the fragment.

Proximity matching: Using the withinLines and withinColumns fields instructs the primary rule to only report a finding if the auxiliary required rules also find matches within the specified proximity. You can set:

  • withinLines: N - required findings must be within N lines (vertically)
  • withinColumns: N - required findings must be within N characters (horizontally)
  • Both - creates a rectangular search area (both constraints must be satisfied)
  • Neither - fragment-level matching (required findings can be anywhere in the same fragment)

Here are diagrams illustrating each proximity behavior:

…
Some final quick thoughts on composite rules.This is an experimental feature! It's subject to change so don't go sellin' a new B2B SaaS feature built ontop of this feature. Scan type (git vs dir) based context is interesting. I'm monitoring the situation. Composite rules might not be super useful for git scans because gitleaks only looks at additions in the git history. It could be useful to scan non-additions in git history for `required` rules. Oh, right this is a readme, I'll shut up now.

gitleaks:allow

If you are knowingly committing a test secret that gitleaks will catch you can add a gitleaks:allow comment to that line which will instruct gitleaks to ignore that secret. Ex:

class CustomClass:
    discord_client_secret = '8dyfuiRyq=vVc3RRr_edRk-fK__JItpZ'  #gitleaks:allow

.gitleaksignore

You can ignore specific findings by creating a .gitleaksignore file at the root of your repo. In release v8.10.0 Gitleaks added a Fingerprint value to the Gitleaks report. Each leak, or finding, has a Fingerprint that uniquely identifies a secret. Add this fingerprint to the .gitleaksignore file to ignore that specific secret. See Gitleaks' .gitleaksignore for an example. Note: this feature is experimental and is subject to change in the future.

Decoding

Sometimes secrets are encoded in a way that can make them difficult to find with just regex. Now you can tell gitleaks to automatically find and decode encoded text. The flag --max-decode-depth enables this feature (the default value "0" means the feature is disabled by default).

Recursive decoding is supported since decoded text can also contain encoded text. The flag --max-decode-depth sets the recursion limit. Recursion stops when there are no new segments of encoded text to decode, so setting a really high max depth doesn't mean it will make that many passes. It will only make as many as it needs to decode the text. Overall, decoding only minimally increases scan times.

The findings for encoded text differ from normal findings in the following ways:

  • The location points the bounds of the encoded text
    • If the rule matches outside the encoded text, the bounds are adjusted to include that as well
  • The match and secret contain the decoded value
  • Two tags are added decoded:<encoding> and decode-depth:<depth>

Currently supported encodings:

  • percent - Any printable ASCII percent encoded values
  • hex - Any printable ASCII hex encoded values >= 32 cha

IssuesĀ· 488 open

View all issuesOpen on GitHub
  • #2239

    .gitleaksignore fingerprint (file:rule:line) matches by position, not secret content

    bugUpdated Sep 28, 2026
  • #1085

    Private key regex is greedy

    Updated Sep 23, 2026
  • #2281

    gitleaks git --pre-commit --staged does not detect secrets in staged files

    bugUpdated Sep 23, 2026
  • #1715

    Create rule for SQL Server connection strings

    enhancementUpdated Sep 19, 2026
  • #2225

    Add detection rules for Supabase secret API keys and personal access tokens

    Updated Sep 19, 2026
  • #2279

    Rule request: detect database connection strings with inline credentials (postgres/mysql/mongodb)

    Updated Sep 19, 2026
  • #2278

    Rule request: detect Supabase `service_role` JWTs (distinct from safe `anon` keys)

    Updated Sep 19, 2026
  • #2276

    Add Composio API key rules (ak_, oak_, uak_)

    Updated Sep 17, 2026
  • #2129

    `gitleaks git` silently reports "no leaks found" with exit 0 when `git log` writes anything to stderr (git-crypt repos affected by default)

    Updated Sep 15, 2026
  • #2121

    perf: detectRule() calls r.Regex.FindAllStringIndex twice per match cycle, doubling regex work on every scan

    bugUpdated Sep 11, 2026

> Tags

Goai-poweredci-cdcicdcli

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 30, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
å®¹å™ØåŒ–å¹³å°ļ¼Œę ‡å‡†åŒ–åŗ”ē”Øäŗ¤ä»˜
G
GitHub Actions
GitHub åŽŸē”Ÿ CI/CD 巄作流
N
Nginx
é«˜ę€§čƒ½ Web ęœåŠ”å™ØäøŽåå‘ä»£ē†