Library › Cybersecurity AI › Software developers

Fix a hardcoded API key the way your repo expects

  • For Software developers
  • You practice Giving the right context
  • Time about 5 minutes

About this exercise

A teammate pushed a payments API key in code. Give the replacement line in exactly 1 code block (at most 3 lines) that reads the key the way the repo already does it, then under 50 words outside the code saying the key must be rotated because it was pushed. Never repeat the key value.

Common mistakes when you ask AI for this

  • Inventing a new pattern. The AI adds dotenv or a new env var name instead of using config.paymentsApiKey. Try: Say: "Use the repo's existing config.paymentsApiKey."
  • Forgetting the leak. The AI fixes the code but doesn't say the pushed key is now exposed. Try: Add: "Say the key must be rotated because it was pushed."
  • Echoing the secret. The AI quotes the old line, key and all, in its answer. Try: Say: "Never repeat the key value."
  • Too much around the code. The AI writes a tutorial on secret management. Try: Limit it: "1 code block of up to 3 lines, under 40 words outside it."

What a strong prompt includes

  • Uses the repo's pattern
  • Asks about rotating the key
  • Keeps the secret out
  • Asks for one code block
  • Limits the explanation

Practice this now ↑

Related exercises