Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
Gitleaks is an open-source scanner that hunts for hardcoded secrets in git history, working directories, and staged changes using regular expressions and entropy measurement.

What Is Gitleaks?
Gitleaks scans repositories for secrets that should never have been committed: API keys, private keys, database passwords, cloud access tokens. It reads the full git history rather than only the current checkout, which matters because deleting a credential in a later commit leaves it perfectly readable in the one before. The tool is written in Go, MIT licensed, and distributed as a single binary, a Docker image, a GitHub Action, and a pre-commit hook.
The modes are easy to mix up and they answer different questions.
gitleaks git . walks commit history. Use it once when onboarding a repository and then on a schedule, because history does not change but the rule set does.gitleaks dir . scans files on disk without touching git, which is what you want for an unpacked artefact, a configuration directory, or a repository exported without its history.gitleaks git --staged --no-banner inspects what is about to be committed. This is the pre-commit hook mode, and it is the only one that prevents a leak rather than reporting one.Any detection sets a non-zero exit code, so wiring it into continuous integration takes one line. Reports come out as JSON, SARIF, CSV, or a template of your own, and SARIF is worth choosing if your platform annotates pull request diffs.
Rules live in TOML. Each has an identifier, a regular expression, and optional conditions:
[[rules]]
id = "acme-internal-token"
description = "Acme internal service token"
regex = '(?i)acme_(live|test)_[0-9a-z]{32}'
entropy = 3.5
keywords = ["acme_live", "acme_test"]
The default configuration ships with rules for the common providers — AWS, GitHub, Slack, Stripe, Google, private key headers — and those catch the obvious cases. The high-value work is adding rules for your own token formats, because an internal credential with a bespoke prefix is invisible to every generic rule set and is often the one with the widest access.
The entropy condition requires the matched string to look random, which suppresses matches on placeholders such as AKIAIOSFODNN7EXAMPLE. The keywords list is a performance optimisation: Gitleaks skips any chunk that does not contain one of them before running the expensive expression.
Two mechanisms do the work. Allowlists in the configuration exclude paths, commits, regular expressions, or specific stopwords, and they belong in version control where a reviewer can see them. A baseline file, generated once and passed with --baseline-path, records every finding that exists today so that only new secrets fail the build. Baselines are the practical way to introduce scanning to a repository with fifteen years of history, but they are also where real secrets go to be forgotten, so the file should shrink over time rather than sit untouched.
The instinct to rewrite history is the wrong first move. Assume the secret is compromised the moment it reaches a shared remote, and act in this order:
git filter-repo or BFG Repo-Cleaner if the repository is private and the rewrite is coordinated. Forks, clones, and pull request refs often retain the old objects regardless.The urgency is not theoretical. Toyota disclosed in October 2022 that an access key published to a public GitHub repository by a subcontractor in December 2017 had exposed data relating to roughly 296,000 customers of its T-Connect service, undetected for nearly five years. Where a leaked key gives access to personal data, a UK organisation also has the ICO’s 72-hour breach notification clock to consider.
They overlap, and the distinction is verification. Gitleaks tells you a string matches a secret pattern; TruffleHog additionally calls the provider to establish whether the credential is live, which dramatically shortens triage. Gitleaks is lighter, faster across large histories, and easier to extend with custom rules, so many teams run it in the commit path and reserve verification-based scanning for periodic deep sweeps.
Neither replaces server-side enforcement. Client-side hooks are bypassed with --no-verify, so the scan that counts is the one in the pipeline, alongside platform push protection. At Privia Security, we look for exposed credentials across public code and infrastructure as part of our penetration test services.
Yes, in git mode it walks every commit on every branch it can reach, which is the point. A secret removed in a later commit stays readable in the earlier one and in every clone of the repository. You can limit the range with log options when a full scan is too slow, but the first scan of a repository should always cover the complete history.
Write a rule block in a Gitleaks TOML configuration with an identifier, a regular expression matching your token, and a keyword list so the scanner can skip irrelevant content quickly. Add an entropy threshold if your tokens are random strings, which filters placeholders out of the results. Keep the configuration in the repository or a shared internal location so every project uses the same rules.
Easily, by committing with the no-verify flag, by using a client that does not run hooks, or by never installing the hook at all. Treat the hook as a convenience that saves developers from an embarrassing mistake, and put the enforcing scan in continuous integration where it cannot be skipped. Platform-level push protection adds a third layer that blocks the push itself.
No. By the time you notice, the credential may exist in clones, forks, pull request refs, continuous integration caches, and any mirror of the repository, and search engines index public repositories quickly. Rotate the credential first and treat history rewriting as housekeeping. If the key could reach personal data, assess whether the incident is reportable to the ICO within 72 hours.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.