Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is Gitleaks?

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.

Illustration for the cybersecurity term Gitleaks
Home / Blog / Cybersecurity Terms / What Is Gitleaks?
17 November 2026

What Is Gitleaks?

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.

Three Modes, Three Jobs

The modes are easy to mix up and they answer different questions.

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.

How Detection Works

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.

Controlling False Positives

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.

What to Do on a Hit

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:

  1. Revoke and rotate the credential at the provider. This is the only step that reduces risk.
  2. Check the logs for use of the credential between the commit date and revocation.
  3. Remove it from history with 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.
  4. Add a rule for that credential format so the next occurrence is caught before the commit lands.

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.

Gitleaks or TruffleHog?

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.

FAQ – Frequently Asked Questions

Does Gitleaks Scan the Whole Git History?

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.

How Do I Add a Rule for Our Own Token Format?

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.

Can Developers Bypass the Pre-Commit Hook?

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.

Is Rewriting Git History Enough to Fix a Leak?

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.

Related Terms

You May Be Interested In These

What Is a Botnet?

Cybersecurity Terms

17 November 2026

What Is a Botnet?

Read More
What Is Bot Management?

Cybersecurity Terms

17 November 2026

What Is Bot Management?

Read More
What Is Satellite Communication Security?

Cybersecurity Terms

17 November 2026

What Is Satellite Communication Security?

Read More