# Secret Scanning

> A check for keys and passwords left in code. It runs before others see it.

**Field:** Software Development  
**Category:** Security  
**Also known as:** Secret Detection, Push Protection, Leaked Secret Scanning

## Think of it like

Think of it like a guard who looks in your bag for keys.

## Definition

Secret scanning looks through code for passwords, API keys and tokens that should not be there. It runs on each change, often before the code is pushed. If it finds one, it warns you or blocks the push. Many code hosts and tools offer it. Once a secret has reached a shared repository, you must replace it, because deleting the line does not erase the history.

## Example

Lucy pushes a commit with a cloud key pasted into a test file. GitHub blocks the push and shows her the exact line.

## Why it matters

Bots search public code for leaked keys all the time. One key can run up a big bill or open your data.

## Common mistake

Deleting the secret in a new commit and moving on. It is still in the history, so the key must be replaced.

## Three principles

- **Scan every change.** Catch keys before they are shared.
- **Block or warn.** Stop the push or flag it.
- **Replace leaked keys.** The history keeps the old one.

## Related terms

- [Secrets Management](https://learn.benibix.com/term/development/secrets-management)
- [.env File](https://learn.benibix.com/term/development/env-file)
- [Dependency Scanning](https://learn.benibix.com/term/development/dependency-scanning)
- [API Key](https://learn.benibix.com/term/development/api-key)
- [Commit](https://learn.benibix.com/term/development/commit)

![Five steps in a row: design, write code, push, build and launch. Lit-up boxes hang under four of them: threat modeling under design asks what could go wrong, secret scanning under push asks if keys were left in the code, a dependency scan under build asks if packages have known holes, and a pen test under launch asks if a skilled attacker can get in. A note says the earlier a hole is caught, the cheaper it is to fix.](https://learn.benibix.com/diagrams/dev2-security-checks.svg)

---

Source: https://learn.benibix.com/term/development/secret-scanning
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
