Skip to content
spot_the_ai_bug

Leaked secrets: interview questions

A leaked secret is a credential that ends up somewhere it can be read: source control, a browser bundle, logs or error messages.

How to spot it in code review

  • Search diffs for keys, tokens and passwords in literals.
  • Ask where each value ends up: bundle, logs, repo?
  • Check that secrets come from a secret store or server-side env.
  • Remember that leaked keys must be rotated, not just removed.

Why AI-generated code gets this wrong

Models are trained to make code work out of the box, and a hard-coded fallback or a verbose log line does exactly that.

Leaked secrets: 3 practice questions

Q1Pythoneasy

Logging every request header

This middleware was added to debug a production issue. What should a reviewer flag?

import logging logger = logging.getLogger(__name__)  def log_request(request) -> None:    logger.info("%s %s", request.method, request.path)    logger.info("headers: %s", dict(request.headers))
Show answer

line 8 · Leaked secret

Request headers include Authorization bearer tokens, session cookies and API keys. Writing them to logs leaks live credentials to everyone with log access and to every log pipeline they pass through.

Fix
    SENSITIVE = {"authorization", "cookie", "x-api-key"}    safe = {k: ("[redacted]" if k.lower() in SENSITIVE else v) for k, v in request.headers.items()}    logger.info("headers: %s", safe)

Interview follow-up: Mention that leaked tokens must be rotated, not just deleted from logs.

Secret key in front-end code

This runs in the browser when the user clicks "Pay". What's the problem?

const STRIPE_SECRET_KEY = "sk_live_51Hx9EXAMPLEf3kL0rEmIpSuM"; export async function createCharge(amountCents, token) {  const res = await fetch("https://api.stripe.com/v1/charges", {    method: "POST",    headers: { Authorization: `Bearer ${STRIPE_SECRET_KEY}` },    body: new URLSearchParams({ amount: amountCents, currency: "usd", source: token }),  });  return res.json();}
Show answer

line 1 · Leaked secret

Everything shipped to the browser is public. Anyone can read the live secret key from the bundle or the network tab and use it to issue refunds, read customers, or create charges. Secret keys belong on the server; the browser should call your own endpoint.

Fix
// Browser: call your backend, which holds the secret key.export async function createCharge(amountCents, token) {  const res = await fetch("/api/charges", {    method: "POST",    headers: { "Content-Type": "application/json" },    body: JSON.stringify({ amountCents, token }),  });  return res.json();}

Interview follow-up: Distinguish publishable keys (safe in the browser) from secret keys (never).

Q3Goeasy

Hard-coded JWT signing key

This signs session tokens for the API. What should block this PR?

var jwtSecret = []byte("super-secret-change-me") func SignToken(userID string) (string, error) {	claims := jwt.MapClaims{		"sub": userID,		"exp": time.Now().Add(24 * time.Hour).Unix(),	}	return jwt.NewWithClaims(jwt.SigningMethodHS256, claims).SignedString(jwtSecret)}
Show answer

line 1 · Leaked secret

The signing key is in source control. Anyone who can read the repo (or a leaked copy) can mint valid tokens for any user, including admins. Load it from a secret store or environment at startup, and fail if it's missing.

Fix
var jwtSecret = mustEnv("JWT_SECRET") func mustEnv(key string) []byte {	v := os.Getenv(key)	if v == "" {		log.Fatalf("%s is not set", key)	}	return []byte(v)}

Interview follow-up: Mention key rotation and that a guessable HS256 secret can be brute-forced offline from any issued token.

Every day, everyone gets the same pull request written by AI. It looks clean. It has comments. It has exactly one real bug.

  1. 1

    Find the line

    Tap the buggy line, then hit Submit. You get 3 attempts.

  2. 2

    Read the hints

    A miss within 2 lines is 🔥 Warm. Anything further is ❄️ Cold.

  3. 3

    Name the bug

    Found it? Bonus round: pick the bug type from 4 options. It doesn't affect your win, just your bragging rights.

// your share card

found in 3/3

🟥 cold miss · 🟨 warm miss · 🟩 found · ⬛ unused

Keyboard: ↑ ↓ to move between lines, Enter to submit. A new bug drops every day at midnight IST.

0
Played
0
Win %
0
Streak
0
Max

Attempts distribution