NextGenLab

Lesson 5 · AI Security & Privacy

API keys and account security: guard your digital keys

Recognise digital secrets (API keys, passwords, sessions), know what to do when a key leaks, and review third-party app access.

You’ll be able to

  • Recognise API keys, passwords and sign-in codes as secrets to protect.
  • Know the steps to take when a key leaks.
  • Review and revoke third-party apps you no longer use.

01. The problem

Two very common situations:

  • An API key gets pasted into a shared document or pushed to a public repo. Whoever has it can use the service on your account and your money.
  • A third-party “AI-powered” app asks for very broad access to your email, Drive or social accounts.

Working with AI means handling more of these “digital keys”. Protect them like your house keys.

02. The key idea

What counts as a digital secret

  • Passwords and recovery questions.
  • API keys and access tokens: strings that let software use a service on your behalf.
  • One-time codes, recovery codes, backup codes.
  • Sign-in sessions (cookies) on shared computers.

Rules for protecting them

  1. Never paste secrets into prompts or public files. When asking AI to fix code, remove the key first and use YOUR_API_KEY.
  2. Store them properly: a password manager; for projects, a private config file that never goes online (such as a .env listed in .gitignore) or the platform’s secret store.
  3. Turn on two-factor sign-in wherever it’s offered.
  4. Don’t reuse passwords across services.
  5. Set limits on spending or scope for API keys where the platform allows.

When a key leaks

  1. Revoke the old key and create a new one immediately; deleting the file isn’t enough.
  2. Update the new key wherever it’s used.
  3. Check usage history and billing for unusual activity.
  4. Tell the person responsible if it’s an organisation account.

Review third-party apps

Regularly open your account’s “Connected apps” / “Security” page (Google, Microsoft, GitHub, social networks…). Revoke apps you no longer use or that ask for more than they need.

03. Example

First attempt: paste a whole config file with API_KEY=sk-... into the chat and ask “why does my code fail?”.

Improved: replace the value with API_KEY=YOUR_API_KEY before pasting, and describe the problem with the error message.

Why it’s better: AI has enough to help, and the real key never leaves your machine.

04. Practice · 15 minutes

Fictional config (every value is fake):

# config shared in team-notes.md (public link)
OPENAI_API_KEY=sk-demo-1234567890abcdef
ADMIN_PASSWORD=Summer2026
EMAIL_APP_SCOPE=read,send,delete,manage_settings
PAYMENT_LIMIT=unlimited
  1. Find every problem in this config (hint: there are at least 4).
  2. For each one, suggest a fix.
  3. Open the “connected apps” page of one of your own real accounts (just look; share it with no one), count the apps, and revoke at least one you no longer use.
Show suggested answers
  • API key in a publicly linked document → revoke, create a new one, keep it in a secret store.
  • Weak, guessable, shared admin password → change to a strong, unique one; turn on two-factor sign-in.
  • Email access far too broad (send, delete, manage settings) → reduce to what’s needed, e.g. read only.
  • No payment limit → set a spending cap.

05. Check your result

  • You found all 4 problems and proposed revoking the key, not just “deleting that line”.
  • You turned on two-factor sign-in for at least one important account (if it wasn’t already).
  • You revoked at least one unused connection.

06. Remember

  • API keys, passwords, one-time codes are digital keys: never in prompts or public files.
  • A leaked key is a lost key: revoke and replace it now.
  • Use a password manager, don’t reuse passwords, turn on two-factor sign-in.
  • Review and revoke third-party apps regularly.

Quick check

Pick an answer. You can try again as often as you like.

Question 1You accidentally pushed a file with an API key to a public repo, then deleted the file right away. Are you safe?
Question 2A free “AI email summariser” app asks to read, send and delete all your email. What do you do?

Keep going

Sources & review date

Content checked on Nov 12, 2026