Every sign-up form, server log, analytics script, and support inbox collects information about people. Some of it you need; much of it you don't. This lesson explains what counts as personal data, why some data is treated as sensitive, which principles privacy laws share, and how to apply data minimization in code. The EU's GDPR serves as the worked example, because it's the most widely referenced data protection law and many other countries' laws follow similar principles.
Before you start
Read lesson 1, What Is Web Security and Privacy?, first; it explains how privacy differs from security. No legal background is needed. This lesson explains principles for engineers; it isn't legal advice, and the obligations that apply to you depend on where you operate and what you process.
What counts as personal data
Personal data (some laws say "personal information") is any information that identifies a person, or that could identify them when combined with other information the organization holds or can reasonably get. That definition is wider than most developers expect:
- Obvious identifiers: name, email address, phone number, home address, government ID numbers.
- Online identifiers: IP addresses, account IDs, device identifiers, and cookie IDs, when they can be linked to a person.
- Records about a person: purchase history, booking dates, support tickets, location history.
- Free-text fields: a "notes" box often ends up holding health details, family situations, or other people's names.
A useful test: if you could, with reasonable effort, work out which person a record is about, treat it as personal data.
Sensitive personal data
Laws single out some kinds of data because misuse causes more harm. Article 9 of the GDPR calls them special categories of personal data:
- racial or ethnic origin, political opinions, and religious or philosophical beliefs;
- trade union membership;
- genetic data, and biometric data used to identify a person;
- health data, and data about a person's sex life or sexual orientation.
Other laws draw the line in different places. Some add government ID numbers, financial account details, precise location, criminal records, or even age, so a "date of birth" field you added out of habit may count as sensitive somewhere your users live. Processing sensitive data is allowed only under narrower conditions, such as explicit consent or a legal requirement, so the safest path is often not to collect it.
The principles behind privacy laws
Most data protection laws descend from the same ideas, first set out internationally in the OECD Privacy Guidelines in 1980. Article 5 of the GDPR states them as principles every organization must follow:
- Lawfulness, fairness, and transparency: people must be told what is collected, why, how it's processed, and who it's shared with, in clear and plain language.
- Purpose limitation: data is collected for specified, explicit, and legitimate purposes, and not reused for unrelated ones.
- Data minimization: data must be adequate, relevant, and limited to what the purpose needs.
- Accuracy: data is kept correct and up to date.
- Storage limitation: data is kept in identifiable form only as long as the purpose needs.
- Integrity and confidentiality: data is protected with appropriate security.
- Accountability: the organization can show that it follows these principles.
Laws also give people rights over their data, such as to be informed, to access it, to correct it, to object, and to have it erased in certain cases. Independent regulators enforce them and publish guidance, including on breach notification, covered in lesson 14.
Other laws use different words and set different details, but if you design to these principles, you're well positioned for most jurisdictions. You still need to check the specific rules that apply to you, which depend on where you operate and where your users are.
Data minimization in practice
Data minimization means collecting, keeping, and exposing only the data a purpose actually needs. It's proportionality turned into an engineering habit. Consider a newsletter sign-up form that asks for name, email, birth date, phone number, and city.
For each field, ask: what feature breaks if we don't have this?
- Email: needed to send the newsletter. Keep.
- Name: nice for a greeting, but optional. Make it optional and say why you ask.
- Birth date: no feature uses it. Remove it. If you must confirm an age threshold, ask "Are you 18 or older?" instead of storing a date.
- Phone number: not used for a newsletter. Remove.
- City: perhaps useful for event announcements. If so, offer a short list of regions, optional, and state the purpose.
The result collects one required field instead of five. Each field you remove is one you never have to protect, disclose, correct, export, or delete.
Minimize in your schema and APIs too
Minimization doesn't stop at forms. Apply it where data is stored and where it leaves your system:
// Return an explicit allowlist of fields, never the whole database row.
export function toPublicProfile(user: { id: string; displayName: string | null; email: string; passwordHash: string; createdAt: Date }) {
return { id: user.id, displayName: user.displayName ?? "Member", memberSince: user.createdAt.getFullYear() };
}Returning the whole row "because the front end ignores the extra fields" leaks email addresses and password hashes to anyone who opens the browser's Network panel. Lesson 10 covers this as an API risk.
Minimize in logs and analytics
Logs are where personal data piles up unnoticed. Request logs record IP addresses and full URLs, and URLs often contain email addresses or tokens in query strings. Error trackers capture request bodies. A few habits help:
- Never put personal data or secrets in URLs; send them in the request body.
- Redact known sensitive fields before logging.
- Truncate or drop IP addresses where you don't need them, and keep logs for a defined period.
- Prefer analytics that don't use cross-site identifiers, and don't send personal data to analytics vendors.
const SENSITIVE = new Set(["password", "token", "authorization", "cookie", "email", "phone"]);
/** A copy of an object that is safe to log: sensitive keys are replaced at any depth. */
export function redact(value: unknown): unknown {
if (Array.isArray(value)) return value.map(redact);
if (value && typeof value === "object") {
return Object.fromEntries(Object.entries(value).map(([key, inner]) => [key, SENSITIVE.has(key.toLowerCase()) ? "[redacted]" : redact(inner)]));
}
return value;
}A denylist like this is a safety net, not a guarantee; the stronger habit is to log a small set of chosen fields rather than whole objects.
Write a data inventory
You can't protect or minimize data you don't know you have. A data inventory (sometimes called a record of processing) lists, for each feature, what personal data it handles. A simple table is enough to start:
feature,data,purpose,lawful basis or reason,where stored,who can access,retention,shared with
newsletter,email,send the newsletter,consent,newsletter_subscribers,marketing team,until unsubscribed,email provider
newsletter,display name (optional),greeting in emails,consent,newsletter_subscribers,marketing team,until unsubscribed,email provider
web server,IP address,security and debugging,legitimate interest,access logs,ops team,30 days,noneKeep it next to the code, in the repository, and update it in the same pull request that adds a field. It becomes the basis for your privacy notice, your retention jobs, and your answers when a user asks what you hold about them.
Transparency in the interface
Tell people what you collect at the moment you collect it, not only in a long policy. A short line under a form ("We use your email only to send this newsletter. Unsubscribe any time.") does more for transparency than a page nobody reads. Make optional fields visibly optional. Don't pre-tick consent boxes, and don't bundle consent for unrelated purposes into one checkbox.
Common mistakes and troubleshooting
- "It's not personal data, it's just an ID." If the ID links to a person in your system, it is.
- Collecting for a future feature. Collect when the feature exists and the purpose is real.
- Keeping everything forever. Old data has the same breach risk and little value. Set retention periods.
- Personal data in URLs. It ends up in logs, browser history, and analytics. Use request bodies.
- Copying production data into test environments. Use synthetic or properly anonymized data instead.
- Treating "anonymized" data as safe without checking. Removing names isn't enough when birth date, postcode, and gender together identify most people.
If you're unsure whether a field is necessary, try removing it in a branch and see what breaks. If nothing does, you have your answer.
Practical exercise: minimize one form
Choose a form in an application you work on:
- List every field and mark it required, optional, or unused.
- For each field, write the feature that uses it and the purpose you'd show the user.
- Mark any sensitive personal information, including age or birth date.
- Remove or make optional every field without a clear purpose.
- Add one row per remaining field to a data inventory like the one above, with a retention period.
Key takeaways
- Personal data is anything that can identify a person, including online identifiers and free text.
- Sensitive data, which some laws define to include age or ID numbers, needs stronger justification; often the best choice is not to collect it.
- Transparency, purpose limitation, data minimization, and storage limitation are core principles shared by most data protection laws.
- Minimize at every layer: forms, schemas, API responses, logs, and analytics.
- A data inventory kept with the code makes every other privacy task easier.
References
- European Commission: Data protection in the EU (GDPR) (opens in a new tab)
- OECD Privacy Guidelines (opens in a new tab)
- OWASP Top 10 Privacy Risks (opens in a new tab)
- NIST Privacy Framework (opens in a new tab)
- OWASP Logging Cheat Sheet (opens in a new tab)
What's next
You now have the foundations: security goals, transport and cookies, authentication, and personal data. Your First Website Security and Privacy Audit puts them together into a practical review of a site you own.

