Vulnerability Analysissecretssastgitpasswordsapi-keystokens

Gitleaks

Gitleaks is a SAST tool for detecting and preventing hardcoded secrets like passwords, API keys, and tokens in git repositories. It provides an easy-to-use solution for finding secrets, past or present, in code.

Description

Gitleaks protects and discovers secrets in git repos by scanning code for hardcoded sensitive information such as passwords, API keys, and tokens. As a Static Application Security Testing (SAST) tool, it helps developers and security teams identify vulnerabilities before code is committed or deployed.

Use cases include pre-commit hooks to block secrets from entering repositories, auditing existing repos for leaked credentials, and integrating into CI/CD pipelines for automated secret detection. It scans both current and historical git commits to uncover secrets that may have been removed but still exist in the repo history.

The tool is particularly valuable for organizations managing large codebases where manual review is impractical, ensuring compliance with security best practices and reducing the risk of credential exposure.

How It Works

Gitleaks scans git repositories, including current code and full commit history, using pattern matching and regex rules defined in configuration files to detect hardcoded secrets. It supports custom configs with precedence order: command-line flag, environment variable, or .gitleaks.toml in source. Baseline files allow ignoring known issues, and it exits with configurable codes when leaks are found.

Installation

bash
sudo apt install gitleaks

Flags

-b, --baseline-path stringpath to baseline with issues that can be ignored
-c, --config stringconfig file path
--exit-code intexit code when leaks have been encountered (default 1)

Examples

Display help information for Gitleaks
gitleaks -h
Detect secrets in code
gitleaks detect
Protect secrets in code
gitleaks protect
Display Gitleaks version
gitleaks version
Generate the autocompletion script for the specified shell
gitleaks completion
Detect secrets using a custom config file
gitleaks detect --config .gitleaks.toml
Detect secrets ignoring issues from baseline
gitleaks --baseline-path baseline.json detect
Updated 2026-04-16kali.org ↗