My AI Chatbot's Logs Leaked a Customer's Card Number
A customer typed her card number into an AI support chat, and the next user to sign in got it back. SupportBot is a shop's customer support chat. It runs on a third-party model provider and logs every conversation for qu
A customer typed her card number into an AI support chat, and the next user to sign in got it back. SupportBot is a shop's customer support chat. It runs on a third-party model provider and logs every conversation for quality checks.
Priya types her card number and phone number into the chat, as customers do. Three things happen. The raw message, card number included, is sent to the model provider. It's written to a log file that 40 staff and an analytics vendor can read, and kept forever. Then someone else signs in and asks what card and phone number the last customer gave. SupportBot searches the logs for context, and answers.
No jailbreak is involved. The data was stored, shared and searchable, and the model was just helpful.
Why it worked
- Raw personal data went to a third-party model provider.
- Full conversations were logged forever, readable by staff and vendors.
- The bot could search everyone's conversations, for anyone.
(OWASP LLM02, Sensitive Information Disclosure.)
The fix, in code
CARD = re.compile(r"\b(?:\d[ -]?){12}(\d{4})\b")
PHONE = re.compile(r"\+91[ -]?\d{5}[ -]?\d(\d{4})\b")
EMAIL = re.compile(r"\b[\w.+-]+@[\w-]+\.[\w.]+\b")
def redact(text):
"""FIX 1: strip personal data at the edge, before the model, the provider or the logs see it."""
text = CARD.sub(lambda m: f"[CARD ending {m.group(1)}]", text)
text = PHONE.sub(lambda m: f"[PHONE ending {m.group(1)}]", text)
return EMAIL.sub("[EMAIL]", text)
def search_logs(args, state):
# FIX 3: you can only search your own conversations.
lines = open(LOG).read().splitlines()[:-1]
mine = [ln for ln in lines if ln.startswith(f"[{state['user']}]")]
if not mine and lines:
return "BLOCKED: you can only search your own conversations"
return "\n".join(mine) or "no logs"
Fix 2: the log keeps only redacted text, with short retention. Same conversation, run again: the provider and the log only ever see [CARD ending 1111], and the second user gets nothing.
Run the lab yourself
git clone https://github.com/usinha79/hack-it-then-fix-it
cd hack-it-then-fix-it/ep19-sensitive-data-in-logs
pip install -r requirements.txt
python vulnerable/app.py # http://localhost:5000, then ./attack.sh (switches user in between)
python fixed/app.py # same messages, redacted everywhere
All personal data here is fake, and 4111 1111 1111 1111 is a standard test card number. Full lab: github.com/usinha79/hack-it-then-fix-it
Take-home checklist
- Redact personal data before it reaches the model, third parties and logs.
- Log less, keep it for less time, and restrict who can read it.
- Scope every retrieval tool to the signed-in user's own data.
- Check your model provider's data retention and training settings.
Keep going
This episode is part of Module 3 of Hack It, Then Fix It. Every lab in the season, vulnerable and fixed, is free to run on your own machine: github.com/usinha79/hack-it-then-fix-it.
Hack It, Then Fix It is a series where I build a small AI app with a real flaw, break it, fix it in code, and run the same attack again to prove the fix holds. Everything shown uses fake data on my own machine. Only test systems you own or are authorised to test.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.