AppSec & Secret Hygiene 7 min read Updated

Preventing API Key, GitHub Token, and JWT Leaks in AI Prompts (Plus Incident Response Checklist)

A defense-in-depth checklist for keeping cloud keys and bearer tokens out of AI chats—and the exact rotation steps if a leak already happened.

Key takeaways

  • Secrets leak most often through pasted .env files, curl commands, stack traces, CI logs, and Authorization: Bearer JWT headers.
  • JWTs are Base64URL-encoded, not encrypted—pasting a live JWT exposes both claims (user IDs, roles, tenant IDs) and a usable session credential.
  • Masking secrets locally before prompting prevents exposure; if a live key was already pasted, deleting the chat is NOT enough—revoke and rotate immediately.
  • Use IOC Defang before pasting suspicious callback IPs or domains from post-leak audit logs into incident tickets.

1. Five common ways secrets end up in AI prompts

Most credential leaks to external LLMs are accidental copy-paste mistakes made under time pressure. Developers rarely paste a secret intentionally; they paste a surrounding block that happens to contain one.

Recognizing these five high-risk snippets helps you build a habit of routing them through local redaction first:

  • Copying an entire .env, docker-compose.yml, or Terraform tfvars file to ask why an environment variable is not loading.
  • Pasting browser DevTools "Copy as cURL" output containing live Authorization: Bearer or Cookie headers.
  • Sharing CI/CD build logs or webhook debug payloads containing GitHub PATs (ghp_ / github_pat_), Slack tokens (xoxb-), or Stripe live keys (sk_live_).
  • Pasting raw JWT strings to ask an LLM to decode claims or debug signature mismatches—exposing an active session token.
  • Sharing database connection strings or SDK initialization snippets containing AWS Access Key IDs (AKIA...) and custom service secrets.

2. High-risk credential patterns detected locally

MaskPrompt assigns top matching priority to API keys and tokens so they are redacted before overlapping shorter patterns (such as emails or numbers inside tokens) can interfere.

AWS Access Key ID
Prefix or Structure: AKIA..., ASIA... (20 uppercase alphanumeric)
Risk if Exposed: Cloud account reconnaissance and unauthorized API access if paired with secret key
Masked Token: [API_KEY_1]
OpenAI / LLM Keys
Prefix or Structure: sk-proj-..., sk-...
Risk if Exposed: Immediate billing abuse and quota exhaustion
Masked Token: [API_KEY_2]
GitHub PATs
Prefix or Structure: ghp_..., gho_..., github_pat_...
Risk if Exposed: Private repository exfiltration and unauthorized workflow/code pushes
Masked Token: [API_KEY_3]
Slack / Stripe / Google
Prefix or Structure: xoxb-..., sk_live_..., AIza...
Risk if Exposed: Workspace message access, payment API abuse, or GCP quota hijack
Masked Token: [API_KEY_4]
Bearer Tokens & JWTs
Prefix or Structure: Bearer ..., eyJ...header.payload.sig
Risk if Exposed: Live session hijacking plus exposure of internal user/role claims
Masked Token: [API_KEY_5]

3. Example: sanitizing a debug curl and config snippet

Before asking an AI why a webhook returns 403 Forbidden, pass the curl command and environment snippet through MaskPrompt locally. Every secret is converted to a numbered token while HTTP headers and flags remain intact.

API debugging snippet with mixed credentials
Raw snippet (high leak risk)
curl -X POST https://api.northstar-demo.io/v1/webhooks \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzQ5MjEiLCJyb2xlIjoiYWRtaW4ifQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" \
  -H "X-Client-IP: 203.0.113.42"
# .env excerpt
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
OPENAI_API_KEY=sk-proj-9kLmN0pQrStUvWxYz1234567890abcdEFGH
GITHUB_TOKEN=ghp_1234567890abcdef1234567890abcdef1234
Masked snippet (safe for AI troubleshooting)
curl -X POST https://api.northstar-demo.io/v1/webhooks \
  -H "Authorization: [API_KEY_1]" \
  -H "X-Client-IP: [PUBLIC_IP_1]"
# .env excerpt
AWS_ACCESS_KEY_ID=[API_KEY_2]
OPENAI_API_KEY=[API_KEY_3]
GITHUB_TOKEN=[API_KEY_4]

For non-standard proprietary secrets without a known prefix (such as raw 40-char AWS Secret Access Keys or custom DB passwords), add the value to Custom Terms or replace it before pasting.

4. Already pasted a live key? Immediate response checklist

If a production secret was already pasted into an external AI interface, treat it as compromised right away. Deleting the conversation thread is good hygiene, but it never guarantees the credential was not logged or cached.

  1. 1. Revoke and rotate the exposed credential first

    Disable or delete the exact AWS IAM key, GitHub PAT, OpenAI key, Slack token, or signing secret immediately and issue a replacement with least-privilege scope.

  2. 2. Invalidate active sessions if a JWT or cookie leaked

    Wait times until JWT expiry can leave an open window. Revoke refresh tokens, rotate signing keys if needed, or force session logout for the affected principal.

  3. 3. Audit provider logs for unauthorized usage

    Check AWS CloudTrail, GitHub Audit Log, Stripe event logs, and API billing dashboards from the leak timestamp onward for unfamiliar IPs, user agents, or privilege escalations.

  4. 4. Defang suspicious indicators before sharing incident reports

    If audit logs reveal unfamiliar IPs, callback URLs, or domains, extract and defang them (hxxps://, [.]) with MaskPrompt IOC Defang before posting in Slack, email, or Jira.

  5. 5. Delete the chat history and document a preventive guardrail

    Remove the thread from the AI workspace, verify enterprise zero-data-retention settings, and add local pre-prompt masking to your team runbook.

Run this workflow locally in your browser

Automatically redact AWS, OpenAI, GitHub, Slack, Stripe, Google, Bearer, and JWT tokens in browser RAM.

Frequently asked questions

Does deleting a ChatGPT or Claude conversation undo an API key leak?

No. Always treat any live secret pasted into an external web service as exposed. Revoke and rotate the key first, then audit access logs, and delete the chat thread as a secondary cleanup step.

Can MaskPrompt detect custom internal secrets that do not have standard prefixes?

Standard prefixed secrets (AWS, OpenAI, GitHub, Slack, Stripe, Google, Bearer, JWT) are detected automatically. For unprefixed secrets such as custom webhook secrets or raw passwords, register them in Custom Terms before masking.

More practical guides

All guides