EasyEnv

Leaked Secret in Git History: A 20-Minute Security Exercise for Every Developer Interview

November 20, 2026·7 min read·By EasyEnv
Leaked Secret in Git History: A 20-Minute Security Exercise for Every Developer Interview

The repository looks clean. git status is empty, the config reads from environment variables, and there is a .env.example with placeholders. Then the candidate runs a secret scanner and it lights up on a commit from months ago, titled "wip: get payments working", that put a live API key into config/settings.py. The next commit, "move config to env", took it out again. The key is still there, in history, on the remote, in every clone.

What does the candidate do first?

That one question sorts developers better than most security quizzes we have seen. This post is for engineering managers hiring any developer, not security specialists. It is a 20 minute hands-on exercise you can add to any loop, with the setup, what good and weak look like in the sessions we review, a time plan and a rubric.

Why this belongs in every developer interview

A committed secret is not a security team problem. It is made by ordinary developers on ordinary days, usually while getting something to work, and the first person who can fix it properly is usually the developer who notices it.

The skill being tested is not cleverness. It is knowing the order of operations, and the order is not obvious. Most developers, asked cold, say "remove it from the history". That is the second step. GitHub's own guide to removing sensitive data says the first step is to "revoke and/or rotate that secret", and that rewriting history afterwards "may not be warranted" in every case. It also lists what a rewrite cannot reach: other people's clones, forks that contain the commit, cached views of the commit on GitHub, and pull requests that reference it (GitHub Docs: Removing sensitive data from a repository).

Once a secret has been pushed, you have to assume someone else has it. Rotation is the fix. The history rewrite is clean-up.

If you are hiring for a security role, this exercise is too small. Use something closer to our attack and defend exercise for security engineers, which puts a real weakness on a live box and asks the candidate to exploit and close it. This one is the baseline every developer should clear.

The exercise setup

The candidate gets a box with one repository and a few tools. The brief is short: "A teammate thinks a credential may have been committed to this repository at some point. Investigate, and leave the repository and the credential in a safe state. Explain each step as you go."

The repository. billing-api, a small service with a few dozen commits and two branches. One older commit adds a fake payments key to config/settings.py; the next commit removes it. A second, quieter leak sits in a committed .env file on a feature branch that was merged and deleted, so only git log --all or a scanner finds it. The working tree is clean. .gitignore does not list .env.

The remote. A bare repository on the same box plays origin, and it already has the leaking commits. This is what makes rotation non-negotiable: the secret has been pushed.

The provider. A small command-line stub, payctl, stands in for the payment provider's console. payctl keys list shows the active key. payctl keys rotate issues a new one and revokes the old. payctl logs shows recent API calls made with each key, including a call from an address the team does not recognise.

The tools. git, git filter-repo, gitleaks and trufflehog are installed. pre-commit is available but not configured.

The Run tests button on the challenge checks the end state: is the leaked key revoked at the provider, is it gone from every ref on origin, is .env ignored, and does a commit containing a key in the same format get blocked locally. It does not check the order the candidate did things in. The recording does.

What strong candidates do

In the sessions we review, strong candidates confirm before they act. They run gitleaks or trufflehog across the whole history, or reach for git log -p --all -S with a fragment of the key's format, and they look at every branch, not just the current one. They find both leaks.

Then they stop and say the important sentence: this has been pushed, so it is compromised, and the key needs rotating before anything else. They run payctl keys rotate, and the best of them also read payctl logs, notice the unfamiliar caller, and say they would raise it with whoever owns incidents rather than treat it as solved.

Only then do they clean history. git filter-repo with --replace-text or --invert-paths on the offending file, a check that the key is gone from every ref, then a force push to origin. They mention, unprompted, that everyone with a clone has to re-clone or reset, that forks and open pull requests may still hold the commit, and that on a hosted platform there may be caches only the platform can clear.

Last, prevention: .env added to .gitignore, a pre-commit hook running a secret scanner, and a suggestion to turn on the hosting platform's secret scanning and push protection. They test the hook by trying to commit a fake key.

What weak candidates do

  • Rewrite first, rotate never. The history is beautiful and the leaked key still works. Of everything on this list, it is the one you most need to catch.
  • Delete the file in a new commit. The key stays in history. This is the mistake the original repository already made, and some candidates repeat it.
  • Only check the current branch. They find the settings file and miss the .env that came in through a deleted branch.
  • Force push without a word about collaborators. Correct command, missing consequence. In a real team that is a morning of confused colleagues.
  • Prevention as a promise. "We should be careful with secrets" instead of a hook that blocks the commit.

The in-session AI panel is available, in Chat, Plan and Agent modes, with a budget ring for the allowance. Asked "how do I remove a secret from git history", a model will often give a correct filter-repo command and skip rotation. The candidates who do well ask what to do about a leaked key, not how to edit history, and they check the answer against the box. The session replay shows the prompts beside the terminal, so you see which kind of candidate you had.

Time plan for 20 minutes

Minutes What happens
0 to 3 Read the brief, scan the full history
3 to 6 Confirm both leaks, state that the key is compromised
6 to 9 Rotate at the provider, read the usage log
9 to 15 Rewrite history, verify every ref, force push
15 to 20 Prevention: .gitignore, pre-commit hook, test it, explain the rest

If someone runs out of time during the rewrite but rotated first, that is a much better session than a perfect rewrite with the old key still live.

Scoring rubric

Score each row 1 to 4 with one line of evidence from the recording.

Area 1 2 3 4
Finding Looked at current files only Found one leak by hand Scanned history, found one Scanned all refs, found both
Rotation Never rotated Rotated after the rewrite Rotated first Rotated first, read the logs, escalated the unknown caller
History Deleted file in a new commit Rewrote one branch Rewrote all refs, force pushed Plus explained clones, forks, caches and pull requests
Prevention None or a promise .gitignore only Hook or scanning added Hook added and tested, platform scanning suggested
Communication Silent Narrated commands Explained why Explained the order and who else must act

A 1 on rotation is a fail for any developer role, whatever the rest of the session shows: it is the one step that actually protects the company. Most hires we would make score 3 or more on finding and rotation. For a general approach to rubrics, see how to write a technical interview rubric.

Running it on EasyEnv

Every candidate gets their own box with the repository, the bare remote and the provider stub, in the same state, and the box is torn down afterwards, so a fake key never outlives the interview. The session is recorded and can be replayed, and AI grading gives a first pass on the end state for the interviewer to confirm or overrule on the scorecard. When several interviewers review, each vote stays hidden until that interviewer has voted.

A limit worth stating: this tells you whether a developer knows what to do with a leaked secret. It does not tell you whether they would notice one in a code review, or avoid writing one. For that side, our post on AI security literacy covers what candidates paste into prompts, and how to assess debugging skill covers the habit of checking evidence before acting, which is the same habit this exercise rewards.

The takeaway

Put an old secret in a repository, push it to a remote, and give a developer 20 minutes. Watch for one thing above all: whether they rotate the key before they touch history.

Would the last developer you hired do it in that order?

For hiring teams

Hire engineers with real-world interviews

Run live coding sessions and take-home challenges in real production environments. Watch sessions back, score consistently, and hire with confidence.

Continue reading

More posts you might like