• We've moved. Our community is now at ownd.sh — latest discussions and updates live there.

[METHOD] FIND API KEYS & PASSWORDS HIDDEN IN DELETED GIT COMMITS [2026]

Kinder

Divine
Divine
Kinder Rep
0
0
0
Rep
1714
Kinder Vouches
41
0
0
Vouches
41
Posts
6,022
Likes
8,716
4 YEARS
4 YEARS OF SERVICE
Hidden Content

Think deleting an API key from your source code means it's gone forever?

Not if it's still sitting in Git history.

A developer might accidentally commit a password, database connection string or API token, then delete the line in their next commit.

The secret can still exist inside earlier Git revisions.

There's an open-source tool called Gitleaks that scans repositories and their commit history for accidentally exposed credentials.

It can identify potential secrets that aren't visible in the current version of a project's files.

This is useful when auditing your own codebases, checking security before publishing a repository, or investigating accidentally leaked credentials.

WHAT CAN GITLEAKS FIND?Depending on its detection rules, Gitleaks can flag:
- API keys

- Authentication tokens

- Private keys

- Database connection credentials

- Cloud service secrets

- Password-like strings

- Credentials embedded in configuration files

- Secrets from previous Git commits

The interesting part is that a deleted line can still be detected if its original commit remains in Git history.

OFFICIAL LINKSGitHub Repository:

https://github.com/gitleaks/gitleaks

Releases:

https://github.com/gitleaks/gitleaks/releases

Configuration Documentation:

https://github.com/gitleaks/gitleaks#configuration

Git Download:

https://git-scm.com/downloads

STEP 1 — DOWNLOAD GITLEAKSVisit the official releases page:

https://github.com/gitleaks/gitleaks/releases

Download the appropriate archive for Windows, Linux or macOS.

On Windows, extract the executable and place it somewhere convenient.

Open PowerShell and navigate to its directory.

Run:

 

Code:

Code:
.\gitleaks.exe version

You should see the installed version.

The examples below use the modern

Code:

Code:
git

and

Code:

Code:
dir

subcommands.Older tutorials using

Code:

Code:
gitleaks detect

may be outdated because the project deprecated that command in v8.19.0.STEP 2 — CREATE A PRIVATE PRACTICE REPOSITORYWe'll create our own example using a deliberately fake credential.

Open PowerShell:

 

Code:

Code:
mkdir SecretAuditLab cd SecretAuditLab git init git config user.name "Practice User" git config user.email "[email protected]"

This creates a local Git repository.

Nothing needs to be uploaded to GitHub.

STEP 3 — CREATE A FAKE LEAKCreate a file containing a dummy private-key block:

 

Code:

Code:
@' -----BEGIN OPENSSH PRIVATE KEY----- THIS_IS_ONLY_A_FAKE_DEMONSTRATION_VALUE -----END OPENSSH PRIVATE KEY----- '@ | Set-Content -Encoding ascii demo-key.txt

Now commit it:

 

Code:

Code:
git add demo-key.txt git commit -m "Add example configuration"

Important: This isn't a real SSH private key. It contains only demonstration text.

The point is to create a record resembling something a secret scanner might identify.

STEP 4 — DELETE THE FILENow remove the practice file:

 

Code:

Code:
Remove-Item demo-key.txt git add -A git commit -m "Remove example configuration"

Look at the current folder:

 

Code:

Code:
Get-ChildItem

The deleted file shouldn't appear.

However, Git still retains the earlier commit containing its contents.

STEP 5 — PROVE THE DATA EXISTS IN HISTORYRun:

 

Code:

Code:
git log --oneline

You should see two commits.

To inspect historical changes:

 

Code:

Code:
git log -p --all

The output includes the content added and subsequently deleted.

That's the underlying reason why deleting a committed credential doesn't necessarily eliminate its exposure.

Anyone with a copy of the relevant repository history may still have access to the old content.

STEP 6 — SCAN THE REPOSITORYFrom your practice repository, run Gitleaks.

If the executable is available on your PATH:

 

Code:

Code:
gitleaks git . --redact

Or use the full path to the downloaded executable.

Gitleaks examines Git history for strings matching its detection rules.

A matching rule may flag the fake key block, although detection isn't guaranteed because the test data isn't a valid credential.

To see how the installed version operates:

 

Code:

Code:
gitleaks git --help

STEP 7 — CREATE A MACHINE-READABLE REPORTRun:

 

Code:

Code:
gitleaks git . --redact --report-format json --report-path findings.json

If findings are detected, the report can contain information including:

 

Code:

Code:
RULE IDENTIFIER FILE PATH COMMIT IDENTIFIER LINE NUMBER DETECTION DESCRIPTION

The

Code:

Code:
--redact

flag reduces the risk of exposing the secret value itself in scanner output.Do not publish unredacted reports containing real credentials.

STEP 8 — COMPARE CURRENT FILES WITH GIT HISTORYGitleaks offers different scanning modes.

Scan current directory contents:

 

Code:

Code:
gitleaks dir . --redact

Scan Git commit history:

 

Code:

Code:
gitleaks git . --redact

The first examines present files.

The second examines changes recorded in Git history.

This distinction is especially important when sensitive information was committed and later deleted.

STEP 9 — CHECK ALL GIT REFSTo include additional reachable Git history, use:

 

Code:

Code:
gitleaks git . --redact --log-opts="--all"

The

Code:

Code:
--log-opts

argument controls how Gitleaks invokes Git's history inspection.This helps include commits reachable from other local branches and tags.

It doesn't guarantee recovery of unreachable, garbage-collected or otherwise unavailable commits.

BONUS — CREATE A CUSTOM DETECTION RULEDefault detection rules won't identify every secret.

You can add a project-specific rule to detect your own credential format.

Create:

 

Code:

Code:
.gitleaks.toml

Add:

 

Code:

Code:
[extend] useDefault = true [[rules]] id = "practice-private-key" description = "Detect practice SSH private-key header" regex = '''-----BEGIN OPENSSH PRIVATE KEY-----''' keywords = ["OPENSSH PRIVATE KEY"]

Now run:

 

Code:

Code:
gitleaks git . --redact --config .gitleaks.toml

The custom rule can match the deliberately inserted marker in the repository history.

Note: In this exercise, create the configuration after the fake-key commits so the demonstration remains easy to follow.

This shows how detection can be tailored to a project rather than relying exclusively on built-in signatures.

BONUS #2 — SCAN BEFORE PUSHING CODEOne practical use is checking changes before publishing a repository.

For example:

 

Code:

Code:
gitleaks git . --redact

Or scan a working directory:

 

Code:

Code:
gitleaks dir . --redact

You can also integrate Gitleaks with Git hooks and continuous-integration workflows to detect potential credential leaks before deployment.

BONUS #3 — WHAT IF YOU FIND A REAL SECRET?If you discover a live credential in your own repository, treat it as compromised.

Recommended response:

- Revoke or rotate the exposed credential immediately.

- Check service logs for unexpected use.

- Replace the credential with a new value.

- Store secrets in an appropriate secret manager or environment configuration.

- Prevent the credential from being committed again.

- Assess whether repository history needs remediation.

Deleting the line isn't enough.

Even rewriting Git history can't revoke copies that others already downloaded.

Credential rotation is the essential step.

IMPORTANT — LIMITATIONSGitleaks identifies potential secrets using configured detection rules.

It doesn't automatically prove that every match is a genuine, working credential.

False positives are possible.

False negatives are also possible.

Some secrets may be encoded, encrypted or formatted in ways that aren't recognised by the default rules.

A clean scan doesn't prove a repository contains no secrets.

IS GITLEAKS STILL MAINTAINED IN 2026?The official repository remains available and provides downloadable binaries and documentation.

However, the maintainer currently describes Gitleaks as feature complete and states that future Gitleaks releases will focus on security patches.

New feature development is moving towards a separate project called Betterleaks.

This makes Gitleaks useful as an established scanner, but readers should check the latest project status before adopting it for a new long-term workflow.

SOURCEShttps://github.com/gitleaks/gitleaks

https://github.com/gitleaks/gitleaks/releases

https://github.com/gitleaks/gitleaks#configuration

https://git-scm.com/docs/git-log

Deleting a sensitive file from the latest commit doesn't erase its earlier versions.

Gitleaks makes it easier to audit that forgotten history and identify credentials that shouldn't have been committed in the first place.

 

WANT MORE HIGH QUALITY SHIT FOR FREE?

CLICK HERE > (MY PROFILE)

Haven't made a account yet? register here (REF LINK)




 

ninja011

Veteran Member
ninja011 Rep
0
0
Rep
0
ninja011 Vouches
0
0
0
Vouches
0
Posts
907
Likes
1
Bits
3 MONTHS
3 3 MONTHS OF SERVICE
Thanks for sharing this.
 

regular69tr

Well-known member
regular69tr Rep
0
0
Rep
0
regular69tr Vouches
0
0
0
Vouches
0
Posts
140
Likes
0
Bits
5 MONTHS
5 5 MONTHS OF SERVICE
Thx boss...
 

Jsjjs8

Well-known member
Jsjjs8 Rep
0
0
Rep
0
Jsjjs8 Vouches
0
0
0
Vouches
0
Posts
101
Likes
0
Bits
3 YEARS
3 YEARS OF SERVICE

FineShyt

Well-known member
FineShyt Rep
0
0
Rep
0
FineShyt Vouches
0
0
0
Vouches
0
Posts
165
Likes
1
Bits
7 MONTHS
7 7 MONTHS OF SERVICE

179,168

126,023

1,405,739

Top