Credential & Access Security · Lesson 2 of 6
Part 1 of 10
A secret committed to Git
About 7 minutes
You push a quick fix to a client's repository, then spot it in the diff: their live payments API key.
You delete the line and push again. The key is gone from the code.
A secret committed to Git: the whole lesson
The situation
You push a quick fix to a client's repository, then spot it in the diff: their live payments API key.
You delete the line and push again. The key is gone from the code.
Your move
Is that enough?
- Yes. The key isn't in the code any more.
- Rewrite the history to remove it, then carry on.
- Revoke or rotate the key now, then report it.
Git remembers everything
A later commit deletes the line, not the history. The key stays in earlier commits, in every clone and fork, and in any copy a tool or a person already made.
Assume someone has it
Once a key is pushed, you can't know who has copied it, so treat it as compromised. If it could reach personal data, your organisation may also need to assess a personal data breach under UK GDPR.
What good looks like
- Revoke or rotate the key straight away.
- Report it through your security process.
- Let the security team decide about cleaning the history.
- Keep the new key in a secrets manager.
Saying it well
Weak and strong
Weak
I deleted it in the next commit, so we're fine.
Strong
I committed a key at 14:05. I've rotated it and reported it.
Quick check 1 of 3
A database password was pushed to a private repository an hour ago. Only your team can see it. What's the first step?
- Nothing, because the repository is private.
- Change the password and report it.
- Ask the team not to look at that commit.
Quick check 2 of 3
Which catches a secret before it ever reaches the repository?
- A pre-commit hook that scans for secrets.
- A weekly backup of the repository.
- A longer commit message.
Quick check 3 of 3
Where should an application's API keys live?
- In the source code, in a file called secrets.js.
- In a secrets manager the application reads when it runs.
- In the README, so new starters can find them.
Take it with you
A secret pushed is a secret exposed.
Revoke or rotate it first, then report it.
Keep secrets in a secrets manager, never in code.
Make it useless first; tidy up second.
Who do you tell when a secret leaks, and does your team scan commits for secrets?
