Secret scanning and code security
Why a pushed secret is a leaked secret, how secret scanning and push protection catch it, and where CodeQL and dependency review fit.
Creating and publishing a repositoryRemoving secrets from historyDependabot and dependency updates
Secret scanning and code security
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A secret committed and pushed must be treated as leaked, because every clone and every old commit still contains it, so the first response is to revoke and rotate it.
- Secret scanning looks through your repository, including its history, for known credential formats and raises alerts, and on public repositories it is on by default.
- Push protection is the preventive half: it blocks a push that contains a detected secret before it reaches the repository.
- Code scanning with CodeQL looks for vulnerabilities in your own code, and dependency review flags vulnerable dependencies a pull request would add.
- Features and plans differ between public and private repositories, so check what your repository's plan includes before assuming you are covered.
A leaked secret stays leaked
Imagine the notes CLI gets a feature that syncs to a cloud service, and in a hurry you put the service’s API key in a .env file and commit it. A minute later you notice, delete the file, and commit again.
Is the key safe? No, and I checked what the history looks like. In a scratch repository I committed a file with API_KEY=AKIAIOSFODNN7EXAMPLE, which is the placeholder key AWS uses in its documentation, then ran git rm and committed the removal. The file was gone from the working tree. But git log --all -S'AKIAIOSFODNN7EXAMPLE' listed both commits, git show HEAD~1:.env printed the key, and git grep -nE 'AKIA[0-9A-Z]{16}' over every commit found it in the first one.
Git keeps history. A secret that was ever committed is in every clone, and bots scrape public repositories for exactly these strings. So the rule is simple: a secret that reached a remote is a leaked secret. Revoke it and issue a new one first. Removing it from history, covered in removing secrets from history, is the second step. GitHub’s own guidance, in the page I read on 2026-11-23, says the same: rotate immediately, and cleaning history is time-intensive and often unnecessary once the credential is revoked.
Secret scanning
Waiting for a person to notice is unreliable, so GitHub scans for you. Secret scanning checks your repository for strings that look like credentials from known providers, such as cloud keys and API tokens. Per the docs it scans the full Git history on all branches, and also issue and pull request text, discussions and wikis. It rescans when new secret types are added.
Two things to know about how it works:
- Partner patterns. GitHub works with many service providers. When a leaked partner secret is found, GitHub tells the provider, which can revoke it, sometimes before you read the alert. The docs say these partner secrets do not appear in your own alerts.
- Customisation. You can add custom patterns with your own regular expressions, enable generic patterns for things like private keys and connection strings, and turn on validity checks to see if a secret is still active. The docs also mention AI-detected secrets, which are marked as a preview feature that can change.
Availability. The docs say secret scanning runs automatically and at no cost on public repositories. For private and internal repositories owned by an organization it needs GitHub Secret Protection on GitHub Team or Enterprise Cloud. Results appear on the Security and quality tab. I could not see any of this, because I have no GitHub account where I wrote the lesson, so I am working from the docs.
Push protection: stopping it earlier
Scanning after the fact still means the secret has reached the server. Push protection closes that gap. It checks each push as it arrives and blocks it if it contains a detected secret. The contributor has to remove it and push again.
The docs say that by default anyone with write access can bypass the block by choosing a reason: “It’s used in tests”, “It’s a false positive” or “I’ll fix it later”. Each bypass is logged, and “I’ll fix it later” creates an open alert. Organizations can delegate who is allowed to bypass.
Two availability points from the docs. Repository push protection needs GitHub Secret Protection and is off by default. A separate user push protection, tied to your account on github.com, is on by default and stops you pushing secrets to public repositories.
To enable it on a repository, the docs say: Settings, then Advanced Security in the “Security and quality” section, then Enable next to “Secret Protection” if needed, then Enable next to “Push protection”. I could not try it.
Push protection is a safety net and not a guarantee. It catches the formats it knows, and a determined or hurried person can bypass it. The habits that matter are upstream: keep real secrets in environment variables and a secrets manager, add .env to .gitignore before the first commit, and put placeholders in committed examples.
Beyond secrets
Secret scanning is one of several tools in GitHub’s security area. From GitHub’s overview page, read on 2026-11-23:
| Tool | What it does |
|---|---|
| Dependency graph | Lists what your repository depends on |
| Dependabot alerts and updates | Flags vulnerable dependencies and opens fix pull requests, as in the previous lesson |
| Code scanning with CodeQL | Analyses your own code for vulnerabilities and coding errors, with results shown as alerts |
| Secret scanning | Finds committed credentials |
| Dependency review | Shows on a pull request which dependency changes add known vulnerabilities |
| Security advisories | Lets you privately fix a vulnerability in a public repository, then publish it |
CodeQL is GitHub’s analysis engine. The docs describe a default setup, enabled from Settings, Advanced Security, then Set up next to “CodeQL analysis”, and Default, and an advanced setup where you edit a workflow yourself. It needs GitHub Actions enabled and the repository to be public or have GitHub Code Security. The documented default setup runs a workflow when you enable it, and a weekly schedule that stops after six months of no pushes or pull requests.
Dependency review shows dependency changes on a pull request’s Files changed tab. The actions/dependency-review-action fails the check by default when a change adds a vulnerable package, so if you make it a required check, the merge is blocked. I looked up its latest release, v5.0.1, and have not run it. It is free for public repositories and needs Code Security for private ones.
For the notes project, a sensible minimum is: push protection on, CodeQL default setup on, the dependency review action as a required check, and Dependabot from the last lesson.
What the video covers
GitHub’s “Introduction to secret leaks and getting started with GitHub Secret Protection” is about three minutes and was published around 2025. Its description asks whether your secrets have leaked and says it covers mitigating the risk and stopping leaks in the first place. I could not read a transcript or chapters. At three minutes it is an overview. It will not show the full click path or the CodeQL and dependency review material above, which is why those are here. GitHub renamed and repackaged some of these products in 2025, so product names in the video may differ from your settings page. English is judged from the title and the channel. A longer unofficial comparison of scanning versus push protection is linked under deeper.
Where this fits
That finishes the platform features. The remaining group is the engine behind much of this: GitHub Actions. It starts with the smallest useful workflow, workflows, triggers, jobs and steps.
Check yourself
You pushed an API key and deleted it in the next commit. Is it safe now?
No. The key is still in the earlier commit, and anyone who cloned or fetched has it. Revoke and rotate the key first. Cleaning history is optional and comes second.
What is the difference between secret scanning and push protection?
Secret scanning finds secrets already in the repository and alerts you afterwards. Push protection checks pushes as they arrive and blocks them before the secret lands.
Where does CodeQL fit compared to secret scanning?
Secret scanning looks for credentials. CodeQL analyses your code for vulnerability patterns such as injection, so the two catch different problems.
Why might push protection let a commit through that contains a secret?
It only catches formats it knows or that you defined, and a user may choose to bypass the block with a stated reason. It lowers the risk but does not remove it.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.