10 September 2026·3 min read
Aadhaar, PAN and UPI in Your Logs: How to Find and Mask Them
Indian ID numbers often end up in logs, error reports and support tickets by accident. How to spot them, mask them and keep them out for good.
Open the logs of almost any Indian app, and there's a good chance you'll find personal data that shouldn't be there. Phone numbers in request logs. PAN numbers in error messages. Aadhaar numbers in a debug line someone forgot to remove. UPI IDs in payment callbacks.
Nobody meant to store them. They just leaked in, and under India's DPDP Act that data still needs to be protected.
Why Logs Are a Problem
Logs are often:
- Kept for a long time, sometimes forever
- Copied to many places: log services, error trackers, backups, developers' laptops
- Seen by many people, including people who should never see customer data
That makes them one of the easiest places for personal data to leak.
What These IDs Look Like
To find them, you need to know their shape:
- Aadhaar: 12 digits, often written in groups of four (
XXXX XXXX XXXX). It never starts with 0 or 1, and the last digit is a checksum. - PAN: 10 characters, five letters, four digits and one letter (like
ABCDE1234F) - Mobile number: 10 digits starting with 6, 7, 8 or 9, sometimes with
+91in front - UPI ID: looks like
name@bankhandle
A Simple Way to Mask Them
The basic idea is to replace sensitive patterns before anything is written to a log. In TypeScript, it can be as small as this:
const rules: [RegExp, string][] = [
// Aadhaar: 12 digits, first digit 2-9, optional spaces or dashes
[/\b[2-9]\d{3}[\s-]?\d{4}[\s-]?\d{4}\b/g, "[AADHAAR]"],
// PAN: 5 letters, 4 digits, 1 letter
[/\b[A-Z]{5}\d{4}[A-Z]\b/g, "[PAN]"],
// Indian mobile numbers, with optional +91
[/(?:\+91[\s-]?)?\b[6-9]\d{9}\b/g, "[PHONE]"],
// UPI IDs
[/\b[\w.-]+@[a-zA-Z]{2,}\b/g, "[UPI]"],
];
export function mask(text: string): string {
return rules.reduce((out, [pattern, label]) => out.replace(pattern, label), text);
}
Treat this as a starting point, not a complete solution. Simple patterns like these can miss some values and wrongly match others. Any 12-digit number may look like an Aadhaar number, for example, and the UPI pattern will also catch many email addresses.
A better tool also checks the Aadhaar checksum, understands context and explains why each match was flagged. That's why I built dpdp-india: it finds and masks Aadhaar, PAN, GSTIN, phone, UPI, cards and bank accounts, with checksum-accurate matching.
Where to Mask
Mask data before it leaves your app:
- In your logger. Wrap your logging library so every message passes through the mask first.
- In error tracking. Most error tools let you clean data before it is sent, so use that hook.
- In support exports. CSV exports and support tickets are logs too.
- In AI prompts. If you send text to an AI service, mask it first.
Find What's Already There
Masking new logs is only half the job. You should also:
- Search your existing logs for these patterns
- Shorten how long you keep logs
- Delete old logs you don't need
- Check your code for places that log whole request bodies or user objects
dpdp-scanner can help you find personal data in your code and database schemas.
Conclusion
If you don't need it in the log, it shouldn't be in the log. Mask early, keep logs short-lived, and check regularly.
For the bigger picture, see DPDP Act for Developers: A Plain-English Checklist.
This post is practical guidance for developers, not legal advice.
Newsletter
Get New Posts by Email.
New posts on building, shipping and leading tech teams, sent to your inbox. No spam, and you can unsubscribe any time.
Keep Reading
More Posts.
25 August 2026·3 min
Your Website Is Probably Breaking India's New Privacy Law
India's Digital Personal Data Protection Act changes how websites and apps must handle personal data. A plain-English guide for founders and developers.
Read Post26 October 2026·2 min
Never Paste Customer Data Into AI. Do This Instead.
Pasting customer data into AI tools is fast, and risky. How to get the benefits of AI without leaking personal data, with simple steps any team can follow.
Read Post15 August 2026·3 min
DPDP Act for Developers: A Plain-English Checklist
India's DPDP Act is not just a legal topic. Much of it lands in your code, forms, logs and databases. A practical checklist for developers.
Read Post