Skip to content

Sensitive Data and Product Safety Rules

Summary

Covers what personal data to collect and keep, retention and deletion, encryption and hashing, privacy basics, and product rules that protect the people an app is about.

Concepts Covered

This chapter covers the following 25 concepts from the learning graph:

Concept Concept Impact Score
Personal Data 74
Sensitive Data 64
Data Minimization 8
Data Retention 12
Retention Period 9
Data Deletion 2
Purge Job 1
Signed URL 6
Expiring Link 5
Private Bucket 5
Encryption in Transit 6
HTTPS 5
Encryption at Rest 1
Hashing 4
Password Hashing 1
Salted Hash 2
Pseudonymization 1
Privacy Law Basics 9
Consent 8
Privacy Policy 7
Data Flow Map 2
Product Safety Rule 29
No-Locate Rule 5
Verify Before Naming Rule 5
Abuse Prevention 1

Prerequisites

This chapter builds on concepts from:


The Coat Check

At a wedding reception, the coat check is a folding table by the door with a rail of hangers behind it. A guest walks up and hands over a heavy wool coat. The attendant hangs it on hook 112 and gives the guest a small paper ticket with 112 printed on it. She doesn't ask for the guest's name. She doesn't ask for a phone number or an address. That ticket is all she needs to give the right coat back.

Late in the evening, a guest comes up without a ticket. He says he lost it, and he points to a gray coat near the end of the rail. The attendant doesn't just hand it over. She asks what's in the left pocket. He says a set of car keys on a red ring and a folded program from the ceremony. She checks, finds both, and gives him the coat.

Welcome to Chapter 8

Sawyer waving welcome Your app holds things that belong to other people, and some of those people never signed up. This chapter shows you how to hold less, keep it for a set time, lock it up, and write down the few things the app must never do. Gate or wall? For data about people, it is almost always wall.

At the end of the night, three coats are still hanging. The attendant puts them in a box marked with the date and leaves it with the hall manager. Lost coats stay at the hall for thirty days. After that, they go to a shelter.

The coat check runs on a few rules that nobody wrote down. Take only what you need to give the coat back. Hand a coat over only when you can confirm who owns it. Don't keep other people's things forever. The last rule matters most. The attendant never tells anyone which car the keys belong to, or where the owner lives. A set of keys and a parking stub in a pocket could lead a stranger straight to a person's home.

This chapter is about the same rules, applied to an app. Your app holds things that belong to other people. Some of what it holds could hurt someone if it reached the wrong hands. Most of the engineering in this chapter is about holding less, holding it for a set time, locking up what you hold, and writing down the few things your app must never do.

What Counts as Personal Data

Personal data is any information about a person who can be identified, either from that information alone or by combining it with other information. A name is personal data. So is an email address, a phone number, a photo of a face, a voice clip, a home address and an account ID. Less obvious items count too. An IP address, a device ID or a list of the times someone used the app can all point back to one person when they are put together with something else.

What matters is whether someone could work out who the data is about, with or without a name attached. A row that says "user 4471, uploaded a photo at 11:02 p.m. from a phone in Duluth" names nobody, and it may still identify one person.

Sensitive data is personal data that can do serious harm if it leaks or is misused: harm to a person's safety, health, money, job, relationships or reputation. Privacy laws give certain kinds of it extra protection. Europe's General Data Protection Regulation, for example, lists health data, biometric data used to identify a person, and data about a person's sex life or sexual orientation as special categories that need stronger reasons to collect. Most builders don't need the legal list to recognize sensitive data. They need to ask what would happen to the person if this piece of data were posted on a public website tomorrow.

A Worked Inventory: Two Kinds of People

The dating-safety app holds personal data about two groups of people, and only one group signed up.

The first group is the members. A member gives the app an email address, a password, a payment method through Stripe, and a history of scans. Then there are the matches: the people the members are worried about. A member uploads a match's photos, voice clips and messages. The checks then pull more about the match from outside services, such as where the photos appear on the web and whether a phone number belongs to the name the match gave. None of the matches agreed to any of this. Most of them will never know the app exists.

That second group is easy to forget, because they never appear on a sign-up screen. They are also the group with the least ability to protect themselves. Here is an inventory of what the app holds, with a rough sense of how much harm each item could do if it leaked.

Item Whose Personal? Sensitive? Why
Member's email address Member Yes Somewhat It links a person to a dating-safety service, which can reveal that they are dating and worried
Member's password Member Yes Yes Leaked passwords get tried on other sites
Member's card details Member Yes Yes Held by Stripe, never by the app, which is the point
Scan history Member Yes Yes It shows who a member is dating and what they feared
Match's photos Match Yes Yes Faces identify people, and the photos may be intimate
Match's voice clips Match Yes Yes A voice identifies a person and can be used to fake one
Messages between member and match Both Yes Yes Private conversations about romance, money and plans
Match's phone number Match Yes Yes It leads to the person directly
Results from people-search vendors Match Yes Very These can include addresses, relatives and past records
The trust score Match Yes Yes A low score is a claim about a person that could be wrong

Almost every row is sensitive, which is normal for a safety app. A recipe app's favorites list could leak and harm nobody much. This app holds people's private lives, including the lives of people who never chose to be in it. In Chapter 1's terms, every row above is a must-be-right part, because a leak can't be undone.

The guests who never checked a coat

Sawyer thinking Think of the matches as guests who never handed over a coat. Their things are on your rail anyway, and they can't come to the table to ask for them back. When a rule in this chapter feels like extra work, check who it protects.

Tell your agent

"Make an inventory of every kind of personal data this app stores or receives: database columns, files in storage, logs, and anything we get back from an outside service. For each item, tell me whose data it is (a member or someone who never signed up), where it's stored, and whether it would harm the person if it were posted publicly. Put it in docs/data-inventory.md. Don't change any code."

Collect Less

The coat check attendant never asks for a name, because she doesn't need one to do her job. Data minimization is the practice of collecting, keeping and sharing only the personal data an app needs for a stated purpose, and nothing more. It is the cheapest privacy protection there is. Data you never collected can't leak, can't be demanded by a court, doesn't need deleting later, and doesn't need to be explained in a privacy policy.

AI agents tend to work against minimization, without anyone meaning them to. Ask an agent to "store the results from the people-search vendor," and it will usually save the whole response, because that's the simplest code and it might be useful later. That response can hold a match's full name, age, past addresses, relatives' names and phone numbers. Yet the member needed one answer: does the phone number belong to the name the match gave?

Keeping One Answer

Here is how the phone check looks before and after minimization. The vendor's response arrives with a dozen fields. The check needs to decide one thing.

Field in the vendor's response Needed to answer the question? Keep it?
Name on the phone account Yes, to compare with the name the match gave Use it for the comparison, then drop it
Carrier and line type (mobile, landline, internet phone) Yes, internet phone lines are a common scam sign Keep the line type
Current street address No Never store it, never show it
Past addresses No Never store them
Relatives' names No Never store them
Age No Don't store it
Email addresses linked to the number No Don't store them

After minimization, the app stores three facts: whether the name matched, the line type, and the date of the check. The member sees the same useful answer as before. If the database leaked tomorrow, a stranger would learn that some phone number was an internet line and didn't match a name. They would not learn where anyone lives.

Minimization also applies to what you send out. Before a match's photo goes to an image-search vendor, ask whether the vendor needs the full-resolution file with its hidden location data, or a smaller copy with that data stripped. Many phone photos carry the GPS position where they were taken, stored inside the file. Stripping that data before upload is a few lines of code. Chapter 9 covers sharing data with vendors in more depth.

Tell your agent

"For every outside service this app calls, show me which fields of its response we store. For each stored field, tell me which feature reads it. For any field no feature reads, write a plan to stop storing it and to clear it from rows we already have. Show me the plan before you change or run anything. Also check whether we strip location data from photos before we store or send them."

Keep It for a Set Time

The coat check keeps lost coats for thirty days. That gives a guest time to call, and it means the hall isn't storing coats forever.

Data retention is the set of rules for how long an app keeps each kind of personal data and what happens to it afterward. A retention period is the length of time one kind of data is kept before it is deleted or made anonymous. A retention period answers two questions at once. How long does the person who gave us this need us to keep it? And how long would we be holding risk for no reason after that?

Apps built quickly usually have no retention rules at all. Nothing is ever deleted, because deleting was never anyone's task. This was one of the gaps found in the dating-safety app after launch: there was no retention period or purge for data about people who never signed up. Matches' photos, voice clips and check results stayed in the database and storage bucket for as long as the app existed, because nobody had been asked to decide otherwise.

Setting retention periods is a judgment call, and the right numbers depend on what members need and what the law says where they live. These periods are illustrative, to show how the reasoning works.

Data Illustrative retention period Reasoning
A match's photos and voice clips 30 days after the scan Members review results within days; after that the files are pure risk
Check results and the trust score 90 days after the scan A member may want to look back before a second date
A member's account and scan list Until the member closes the account The member chose to keep a history
Payment records As long as tax and accounting rules require Set by law, not by preference
Server logs 14 days Long enough to debug a problem; Chapter 12 covers logs

Data Deletion

Data deletion is removing personal data so that it can no longer be read or recovered by the app or anyone who gets into it. Deletion sounds simple and usually isn't, because personal data tends to live in more than one place. A match's photo might sit in the storage bucket, in a thumbnail, in a row that points to it, in a log line, in a nightly database backup, and in a vendor's systems after a search. Deleting the database row and leaving the file in the bucket deletes nothing that matters.

Some apps use a "soft delete," where a row is marked as deleted and hidden from screens but stays in the database. Soft deletes are useful for an undo button. They aren't deletion, and an app that uses them for personal data needs a second step that removes the row for good.

Backups are the hardest copy to reach, and the usual answer is to let them age out. If backups are kept for fourteen days, deleted data is fully gone fourteen days after it leaves the live database. Chapter 11 covers backups.

Test the delete

Sawyer sharing a tip Here's a quick way to test a delete. Upload a photo, delete the scan, then open the photo's link again right away and search the logs and the bucket for the scan's ID. If anything still turns up, the delete only hid the data.

Purge Job

A purge job is a background job that runs on a schedule and deletes data whose retention period has ended. It is how a retention rule happens, because nobody will delete expired scans by hand every morning.

The sketch below shows the shape of a purge job for match files. It finds scans older than the retention period, deletes their files from the storage bucket first, then deletes the rows that pointed at them. Files go first for a reason. If the job fails halfway, a row pointing at a missing file is easy to find and retry. A file that nothing points at is easy to forget. RETENTION_DAYS is the retention period. lt means "less than," so the query finds files created before the cutoff, and deleteFromBucket removes one stored file.

// Runs once a day. Deletes match files older than the retention period.
const RETENTION_DAYS = 30;

const expired = await db.select().from(scanFiles)
  .where(lt(scanFiles.createdAt, daysAgo(RETENTION_DAYS)));

for (const file of expired) {
  await deleteFromBucket(file.storageKey);   // the photo or voice clip itself
  await db.delete(scanFiles).where(eq(scanFiles.id, file.id));
}

log.info("purge finished", { deleted: expired.length });

Two habits make a purge job trustworthy. Log how many items it deleted each run, so you can see it working. And watch for the day it doesn't run at all. A purge job that silently stops looks exactly like one with nothing to delete. Chapter 12 covers how to notice a job that never ran.

The dating-safety app already had a sweep for orphaned scans, which cleans up scans that crashed partway through. A purge job is a different job: it removes finished scans that have been kept long enough.

Tell your agent

"Propose a retention period for each kind of personal data in docs/data-inventory.md, and say why. Stop there until I've approved the periods. Then write a purge job that runs daily, deletes expired files from storage and then their database rows, and logs how many it deleted. Write a test that creates an expired scan and a fresh one, runs the purge, and checks that only the expired one is gone, in both the database and storage. Don't schedule it in production until I've seen the test pass."

Lock Up the Photos

Chapter 3 introduced the storage bucket, the place where an app keeps files such as photos and voice clips. How that bucket is set up decides who can open what's inside it.

A private bucket is a storage bucket whose files can't be opened by anyone on the internet who has the address. Every request has to carry proof that the app allowed it. A public bucket is the opposite: anyone who knows or guesses a file's address can open it. Public buckets are fine for a logo or a marketing image. For a match's photo they are a leak waiting for someone to look.

If the bucket is private, how does the member's browser show the photo on the results page? The app hands out a key for that one file, and only for a short time.

A signed URL is a link to one file in a private bucket that carries a signature, a code the app makes with its secret key, proving the app approved this request. The storage service checks the signature before it sends the file. Nobody can make a valid signature without the app's secret key, so nobody can forge a link to a file the app didn't approve. Change one character of the file name in the link and the signature no longer matches.

An expiring link is a link that stops working after a set time. Signed URLs are almost always expiring links too, because the expiry time is part of what gets signed. After it passes, the storage service refuses the link even though the signature is valid.

Showing One Photo

This is one of the things the dating-safety app got right. Here is what happens when a member opens a results page with three of a match's photos.

  1. The member's browser asks the server for scan 8812's results.
  2. The server checks that the member is signed in and that scan 8812 belongs to this member. Chapter 7 covers these checks. If the scan belongs to someone else, the server answers "not found."
  3. For each of the three photos, the server asks the storage service for a signed URL that expires in 15 minutes.
  4. The server sends back the results with the three signed URLs.
  5. The browser loads the three photos straight from storage using those links.
  6. If the member copies a link and pastes it into a chat, the person who opens it after 15 minutes gets an error.

The 15 minutes is a choice, and an illustrative one here. Shorter is safer and occasionally annoying, if a member leaves the page open and comes back later. In that case the page should ask for fresh links, rather than the links lasting a week.

A signed URL works for anyone who holds it until it expires. It is a bearer key, the same way a coat check ticket is. So signed URLs should never be written to logs, emailed, or stored in the database. The app should make a new one each time a page needs it.

Tell your agent

"Check every storage bucket this app uses. Tell me which are public and which are private, and list what kinds of files are in each. Any bucket that holds member or match files must be private. Then find every place we create a link to a stored file and tell me how long each link lasts and whether we ever log or save the link."

Encryption on the Wire and on the Disk

Encryption scrambles data so that only someone with the right key can read it. It protects data in two places: while it travels between computers, and while it sits on a disk.

Encryption in transit is protection for data while it moves across a network, from a browser to a server, from a server to a database, or from a server to an outside service. Without it, anyone on the path can read the data or change it. That includes the person running a coffee shop's Wi-Fi.

HTTPS is the secure version of HTTP, the protocol browsers use to talk to web servers, covered in Chapter 2. It wraps every request and response in encryption using a system called TLS, and it lets the browser confirm it is talking to the right server rather than an impostor. The padlock in the address bar means the page came over HTTPS. Most hosting platforms, including the kind the dating-safety app uses, turn on HTTPS for you. What to check is the connections the browser doesn't see: the server's connection to the database, and its calls to outside services. Those should use encrypted connections too.

Encryption at rest is protection for data stored on a disk, so that someone who gets hold of the disk or a copy of its files can't read them without the key. Most managed database and storage services encrypt data at rest by default. That protects against a stolen drive or a copy of the provider's own backups. It doesn't protect a backup you export yourself, such as a database dump file, unless you encrypt that file too. And it does nothing against a bug in your app, because your app holds the key and reads the data in plain form every time it runs a query.

Each kind of protection stops some threats and not others.

Threat HTTPS (in transit) Encryption at rest Server-side access checks (Chapter 7)
Someone on the coffee-shop Wi-Fi reads a member's upload Stops it Doesn't help Doesn't help
A copy of the provider's disk or backup storage is stolen Doesn't help Stops it Doesn't help
A member changes a number in a link and opens another member's scan Doesn't help Doesn't help Stops it
A leaked database password lets someone log in and query the tables Doesn't help Doesn't help Doesn't help; rotating the password does (Chapter 6)

Encryption is a must-have and mostly a solved problem, provided the defaults are on. It isn't a substitute for minimization, retention or access checks, because most leaks come through the app's own front door.

Tell your agent

"Confirm three things and show me the evidence for each: that the app only serves pages over HTTPS and redirects plain HTTP, that the connection from our server to the database is encrypted, and whether our database and storage provider encrypt data at rest. Link me to the provider's documentation for the last one."

Hashing: Remembering Without Keeping

Sometimes an app needs to recognize a piece of data later without keeping the data itself. Hashing makes that possible.

Hashing is running data through a one-way function that turns it into a fixed-length string of characters, called a hash. The same input always gives the same hash. A tiny change in the input gives a completely different hash. And there is no way to run the function backward to get the input from the hash. A common hash function is called SHA-256. Here is what it does to two phone numbers that differ by one digit:

Input SHA-256 hash (first 16 characters shown)
+15555550134 462301934abe5e04
+15555550135 73c7c7d3210ce3cb

Hashing has one weakness that matters here. If the set of possible inputs is small, someone can hash every possible input and compare. There are only about ten billion ten-digit phone numbers, and a laptop can hash all of them in minutes. So a plain hash of a phone number protects almost nothing. Anyone who steals the table can build a lookup list and read the numbers back.

Password Hashing

Password hashing is storing a password as a hash made by a function built to be slow, so that an app can check a password at sign-in without ever storing the password itself. When a member signs in, the app hashes what they typed and compares it to the stored hash. Slow functions such as bcrypt, scrypt and Argon2 are used on purpose, because they make guessing millions of passwords expensive. A fast function like SHA-256 alone is the wrong tool for passwords. If your app uses a sign-in provider, as Chapter 7 describes, the provider does this for you and your database holds no passwords at all, which is better still.

Salted Hash

A salted hash is a hash made from the input combined with an extra value, called a salt, so that the same input can't be matched against a list of precomputed hashes. Salts come in two kinds, and they solve different problems.

For passwords, each password gets its own random salt, stored next to its hash. Two members with the same password get different hashes, and an attacker has to guess each one separately. Password hashing functions handle this salt for you.

For recognizing a repeat value, such as a banned phone number, the app needs the same input to give the same hash every time, so it can look it up. Here the app uses one secret salt for the whole table, kept in the app's secrets and never in the database (Chapter 6 covers where secrets live). Someone who steals the table can't build a lookup list, because they don't have the salt. Your agent may call this kind of salt a key or a pepper, and the result a keyed hash.

Two salts, one question

Sawyer encouraging Two kinds of salt in one section is a lot, and most people need a second read. One question sorts them: does the app need to find this exact value again later? If yes, use one secret salt for the table; if it only checks what someone typed, let the password function's random salt do the work.

The Abuse Ledger

This is another thing the dating-safety app did well. The app keeps an abuse ledger: a list of accounts that were banned for abusing the service, so that the same person can't simply sign up again. An obvious design is a table of banned phone numbers and email addresses. That table would be a list of people's contact details, kept forever, labeled "abuser." If it leaked, it would harm the people on it, and a few of them might have been banned by mistake.

The app stores a salted hash instead, never the account itself. When someone is banned, the app hashes their phone number with the secret salt and stores only the hash. When someone signs up, the app hashes their phone number the same way and checks whether that hash is in the ledger.

What the ledger needs to do Plain list of numbers Plain hash Salted hash with a secret salt
Spot a banned number at sign-up Yes Yes Yes
Keep a thief with the table from reading numbers No No, they can hash every number Yes, without the salt they can't
Avoid storing a list of people's contact details No Looks like it, but no Yes

The ledger does its whole job while holding nothing a thief could read.

Pseudonymization

Pseudonymization is replacing the details that identify a person with a stand-in value, such as a random ID or a salted hash, and keeping the link between the two separate and locked away. A coat check ticket is a pseudonym. It stands for a guest without naming one. The scan list could refer to members by a random ID, and the analytics that count scans per day need nothing more than that ID.

Pseudonymized data is still personal data, because whoever holds the link, or the salt, can connect it back to a person. It lowers the harm of a leak. It doesn't remove the duty to protect the data. Data that can never be linked back to anyone is called anonymous, and that is much harder to achieve than most people expect.

The simulation below lets you choose how to store five kinds of data and see what a thief would get from each choice.

Diagram: Pick the Right Way to Store It

Run the Pick the Right Way to Store It MicroSim Fullscreen

Pick the Right Way to Store It

Type: microsim sim-id: storage-method-chooser
Library: p5.js
Status: Specified
Bloom Level: Evaluate
Bloom Verb: recommend
Learning Objective: The learner will recommend a storage method for each of five kinds of data in the dating-safety app, choosing the method that lets the app do its job while giving a thief who steals the table the least, with at least four of five correct.

Prerequisites: hashing, password hashing, salted hash with a secret salt, salted hash with a random salt per record, encryption at rest, pseudonymization, abuse ledger (all defined in the sections "Encryption on the Wire and on the Disk" and "Hashing: Remembering Without Keeping").

Evidence of Mastery: For each of five data jobs, the learner picks one of six storage methods and presses Check. A pick is correct when it matches the answer column in Content. Mastery is 4 of 5 correct on the first attempt. Viewing the thief's view before committing is exploration, not evidence.

Misconceptions: (1) Hashing protects any data, including short inputs like phone numbers. (2) Encryption at rest protects data from bugs in the app. (3) Everything sensitive should be hashed, even data the app must show back to the member. (4) Pseudonymized data no longer counts as personal data.

Instructional Rationale: Choosing a method is an Evaluate task because each method trades what the app can still do against what a thief could recover. Showing the thief's view and the app's view for each choice makes the learner weigh both sides before committing.

Content:

The six storage methods, shown for every job:

Method What the app can do with it What a thief with the table gets
A. Plain text Read it, match it, show it The data itself
B. Plain SHA-256 hash Match it; can't show it For short inputs like phone numbers, the data, by hashing every possible value
C. Salted hash with one secret salt kept outside the database Match it; can't show it Nothing readable without the salt
D. Password hash (slow function, random salt per record) Check a typed value against it; can't match across records or show it Nothing readable; each guess is slow and works on one record only
E. Stored readable, with encryption at rest Read it, match it, show it The data, if they got in through the app or a database login; nothing if they only have the disk
F. Random pseudonymous ID in place of the person Count and group records; can't identify the person without the separate link table IDs with no meaning unless they also steal the link table

The five data jobs:

# Job shown to the learner Correct method Why (feedback)
1 A member's password, checked at sign-in D Passwords need a slow hash with a random salt per record, so each guess is expensive.
2 A banned phone number in the abuse ledger, checked at every sign-up C The app must match the same number every time, and a secret salt stops a thief from hashing every phone number.
3 A member's email address, used to send receipts E The app must read it to send mail, so it can't be hashed; encryption at rest and access checks protect it.
4 The line type and name-match result from a phone check, shown on the member's results page for 90 days E The member must see it, so it stays readable, and the retention period limits how long it's held.
5 Scans per member per day, used for the builder's usage chart F The chart needs to count by member, not know who the member is.

Provenance: The abuse ledger storing a salted hash is from the dating-safety app in research/seed-notes.md. The SHA-256 example values and the point about hashing every phone number are from the section "Hashing: Remembering Without Keeping." The 90-day period in job 4 is the illustrative retention period from the section "Keep It for a Set Time" and must be labeled "illustrative."

Rules: Each job has exactly one correct method, listed above. Method B on job 2 gets the extra feedback: "A plain hash of a phone number can be reversed by hashing every number. Add a secret salt." Method A on any job gets the extra feedback: "Plain text gives a thief everything." Method E on job 2 gets: "This works, but it keeps a readable list of people's numbers that the app never needs to read."

Learner Activity:

  1. The learner sees job 1 and the six methods.
  2. Choosing a method shows two short panels: what the app can do with that method, and what a thief with the table gets, both from the methods table. Changing the choice updates both panels. Nothing is scored yet.
  3. The learner presses Check. The pick is marked correct or incorrect with its Why text and any extra feedback from Rules.
  4. The learner moves to the next job. Jobs come in the fixed order 1 to 5.
  5. After job 5, a summary shows each job's correct method and the learner's pick side by side.

Feedback: Five jobs, fixed order, one attempt each; a checked job can't be re-answered. Correct: "Right. " followed by the Why text. Incorrect: "A better choice is [correct method]. " followed by the Why text and any extra feedback from Rules. The correct method is revealed on Check. A running count "Jobs correct: n of 5" is shown, with "Mastery reached" at 4 or more after job 5.

Starting State: Job 1 is shown with no method chosen. The prompt reads "How should the app store this, so it can do its job and a thief gets as little as possible?"

Chapter Anchors: SHA-256 of +15555550134 begins 462301934abe5e04, and of +15555550135 begins 73c7c7d3210ce3cb. There are about ten billion ten-digit phone numbers. The abuse ledger stores a salted hash, never the account. The illustrative retention period for check results is 90 days.

Tell your agent

"Find every place this app stores a password, a phone number, an email address or another identifier. For each, tell me how it's stored today: plain text, plain hash, salted hash, or handled by a sign-in provider. Flag any plain hash of a short value like a phone number, and any identifier we keep in readable form that the app never needs to read back."

Privacy Law Basics

This section is an overview, not legal advice. Privacy law depends on where your users live, what you collect and what you do with it, and it changes often. When your app holds sensitive data about people, a short session with a privacy lawyer is money well spent. What follows is enough to know which questions to bring.

Privacy law basics are the few ideas that run through most modern privacy laws. People have a right to know what is collected about them, to see it, to correct it and to have it deleted. Collection needs a stated purpose and a lawful reason. Data should be kept no longer than needed and protected while it's kept. And a breach must be reported. You have already met several of these in this chapter as engineering habits. Data minimization and retention periods aren't only good practice. In many places they're required.

A few laws come up most often for a small app with users in the United States or Europe.

  • The GDPR, the European Union's General Data Protection Regulation, has applied since May 2018. It covers the personal data of people in the EU, wherever the company is based. Fines can reach 4 percent of a company's yearly worldwide revenue or 20 million euros, whichever is higher.
  • The CCPA, the California Consumer Privacy Act, took effect in January 2020 and was later expanded by the California Privacy Rights Act. It gives California residents the right to know, delete and correct their data and to opt out of its sale or sharing. It applies to businesses above certain size or data thresholds.
  • State biometric laws cover data such as face geometry and voiceprints. Illinois's Biometric Information Privacy Act, passed in 2008, requires written consent before collecting a person's biometric identifiers. An app that runs face matching on photos of people who never signed up should ask a lawyer about laws like this one before launch.
  • Other state privacy laws have followed California's, and the list grows each year.

The rights in these laws turn into features. A member who asks to be deleted needs a way to ask and an app that can do it, across the database, the bucket and the vendors. A member who asks for a copy of their data needs an export.

Consent is a person's clear, informed agreement to a specific use of their data, given before the use begins. Under the GDPR, consent has to be freely given, specific and as easy to withdraw as to give. A box that comes pre-ticked doesn't count, and neither does consent buried in terms of service nobody reads.

Consent is only one of several lawful reasons to process data. Others include carrying out a contract the person asked for, and a "legitimate interest" weighed against the person's rights. Members can consent. Matches can't, because they never interact with the app. Whatever reason the app relies on for matches' data, its case is stronger when it collects little, keeps it briefly and never exposes it.

Privacy Policy

A privacy policy is the public document that tells people what personal data an app collects, why, who it's shared with, how long it's kept and how to exercise their rights. Most laws require one, and app stores and payment providers usually do too.

The common failure is a privacy policy that describes the app the builder meant to make rather than the one that runs. An agent can write a fluent policy in a minute, but it can't know that a log line stores phone numbers, or that a new vendor was added last Tuesday, unless someone tells it. A privacy policy that says "we delete photos after 30 days" when no purge job exists is worse than none, because it's a promise the code breaks every day.

The fix is to write the policy from what the code does, and to update it when the code changes. The data flow map in the next section is the thing to write it from.

Tell your agent

"Compare our privacy policy against the code. For every claim the policy makes about what we collect, who we share it with and how long we keep it, find the code that makes it true, or tell me that none exists. List every mismatch. Don't edit the policy; I'll take the list to a lawyer."

The Data Flow Map

A coat check's coats come in at one window and leave by the same window. An app's data takes many more paths, and most of them are invisible from the screen.

A data flow map is a diagram or table that shows every place personal data enters an app, where it's stored, which outside services it's sent to, and when it's deleted. It's the one picture that answers most privacy questions at once. Which vendors see a match's face? Where does a phone number end up? Does anything leave the app that the privacy policy doesn't mention? What has to happen when a member asks to be deleted?

Each arrow that leaves the app for an outside service is a one-way door in Chapter 1's sense. Once a vendor has a copy of a photo, its own retention rules decide what happens next, and your purge job can't reach it. Chapter 9 covers what to check before sending data to a vendor.

A Worked Map

Here are the main flows in the dating-safety app. Each row is one path that a piece of personal data takes.

# Data From To Kept for
1 Match's photos Member's browser Private bucket 30 days, then purged (illustrative)
2 Match's photos Private bucket Image-search vendor The vendor's own policy
3 Match's messages Member's browser, through the server AI model vendor, fenced as untrusted text The vendor's own policy
4 Match's phone number Server People-search vendor The vendor's own policy
5 Vendor's full record, including addresses People-search vendor The server, in memory only Dropped after the check; only the match result and line type are stored
6 Check results and trust score Server Database 90 days, then purged (illustrative)
7 Banned phone number Server Abuse ledger, as a salted hash Kept, because a hash can't be read
8 Member's card details Member's browser Stripe, directly Stripe's policy; the app never sees them
9 Request details, including member ID Server Logs 14 days (illustrative)

Rows 2, 3 and 4 are where a match's data leaves the app's control. Row 5 shows minimization at work: the full record passes through and only the needed answer is kept. Row 9 is the one most often missed. Logs quietly collect personal data, and Chapter 12 covers keeping secrets and personal data out of them.

The diagram below lets you explore a version of this map and find the flows that break a rule.

Diagram: Data Flow Map Explorer

Run the Data Flow Map Explorer MicroSim Fullscreen

Data Flow Map Explorer

Type: graph-model sim-id: data-flow-map-explorer
Library: vis-network
Status: Specified
Bloom Level: Analyze
Bloom Verb: examine
Learning Objective: The learner will examine a data flow map of the dating-safety app and identify the three flows that break a data rule from this chapter, naming the rule each one breaks.

Prerequisites: data flow map, data minimization, retention period, purge job, private bucket, signed URL, no-locate rule (named as a must-be-right part in Chapter 1 and defined later in this chapter), personal data (all defined in this chapter or Chapter 1 before this block).

Evidence of Mastery: The learner flags flows as "breaks a rule" and, for each flagged flow, picks the rule it breaks from a list of four. The answer is correct when exactly flows 10, 11 and 12 are flagged and each has its correct rule. Mastery is all three found with the correct rule and no more than one wrong flag.

Misconceptions: (1) Any flow to an outside service is a violation. (2) If data is stored in the app's own database, it is safe. (3) Logs don't hold personal data.

Instructional Rationale: A data flow map is useful only if the reader can scan it for trouble. Examining each flow against a short list of rules, and naming the rule, is an Analyze task: the learner breaks the system into paths and tests each one.

Content:

Nodes (each opens an infobox with its description when selected):

Node Description in infobox
Member's browser Where the member uploads photos, messages and a phone number about a match
Server The Express server that runs the checks
Private bucket File storage that only the app can open; files are shown through expiring signed links
Database Postgres tables for scans, results and accounts
Abuse ledger A table of salted hashes of banned phone numbers
Logs The server's request and error logs
Image-search vendor An outside service that finds where a photo appears on the web
AI model vendor An outside service that reads messages for scam patterns
People-search vendor An outside service that returns records about a phone number
Stripe The payment processor
Results page What the member sees

Flows (each opens an infobox with its data, retention and the correct judgment when selected):

# Flow Data Retention shown Breaks a rule? Rule Why (feedback)
1 Member's browser → Private bucket Match's photos 30 days, purged daily No none Private storage with a retention period and a purge job.
2 Private bucket → Image-search vendor Match's photos, location data stripped Vendor's policy, reviewed before first use No none Sending data out is allowed when it's needed and the vendor's terms were checked.
3 Member's browser → AI model vendor (through server) Match's messages Vendor's policy, reviewed before first use No none Needed for the message check.
4 Server → People-search vendor Match's phone number Vendor's policy, reviewed before first use No none The number is the minimum needed to run the check.
5 People-search vendor → Server Full record, held in memory Dropped after the check No none The full record passes through but isn't stored.
6 Server → Database Name-match result and line type 90 days, purged daily No none Only the answer is kept.
7 Server → Abuse ledger Salted hash of a banned number Kept No none A salted hash can't be read back.
8 Member's browser → Stripe Card details Stripe's policy No none The app never touches card details.
9 Private bucket → Results page Photos through signed links Links expire in 15 minutes No none Expiring signed links from a private bucket.
10 People-search vendor → Database Full record, including past addresses and relatives No retention period Yes Data minimization The app stores far more than the check needs, with no end date.
11 Server → Logs Signed photo links and match phone numbers Kept forever Yes Retention period Logs hold personal data and live links with no retention period.
12 Database → Results page Match's current street address Shown for 90 days Yes No-locate rule The app must never return an address, workplace or location.

Rule choices offered for each flagged flow: Data minimization; Retention period; No-locate rule; Private bucket and signed links.

Provenance: Flows 1 to 9 are from the section "A Worked Map" in this chapter, which draws on the dating-safety app in research/seed-notes.md (private photo storage with expiring links, text fenced as untrusted, abuse records stored as a salted hash). Flows 10 to 12 are illustrative faults built for this exercise and must be labeled "illustrative fault." Retention periods are illustrative.

Rules: A flow breaks a rule when any of these is true: it stores fields no feature needs (data minimization); it keeps personal data with no retention period (retention period); it returns an address, workplace or location to the results page (no-locate rule); it makes a stored file reachable without a private bucket and an expiring link (private bucket and signed links). A flagged flow is correct only if its rule is also correct. Each wrong flag on flows 1 to 9 counts as one wrong flag.

Learner Activity:

  1. The learner sees the map with every node and flow and no flags.
  2. Selecting a node or a flow opens its infobox with the description, data and retention, without the judgment.
  3. The learner flags any flow as "breaks a rule" and picks a rule for it. Flags can be added, changed or removed until Check.
  4. The learner presses Check. Every flow's infobox now includes its judgment and Why text, and flagged flows are marked correct or incorrect.
  5. The learner should notice that flows 2, 3 and 4 send data to vendors and are still allowed.

Feedback: Twelve flows, all shown at once, one attempt. Correct flag with correct rule: "Right. " followed by the Why text. Correct flag with wrong rule: "This flow does break a rule, but a different one. " followed by the Why text. Wrong flag: "This flow is allowed. " followed by the Why text. Missed flow: "You missed this one. " followed by the Why text. All judgments are revealed on Check. Shown after Check: "Problem flows found: n of 3" and "Wrong flags: n."

Starting State: The full map with no flags. The prompt reads "Three of these flows break a rule. Which ones, and which rule?"

Chapter Anchors: The worked map in the chapter has nine flows. Rows 2, 3 and 4 send a match's data to vendors. Illustrative retention periods: match photos 30 days, check results 90 days, logs 14 days. Signed links expire in 15 minutes.

Tell your agent

"Draw a data flow map of this app as a table in docs/data-flow-map.md. One row per path that personal data takes: what the data is, where it comes from, where it goes, and how long it's kept there. Include every outside service, the logs, and any file storage. Mark each row where data leaves our control. Then tell me which rows have no retention period."

Product Safety Rules

Everything so far in this chapter protects data from leaking. This last part protects people from the app itself, working exactly as built.

A product safety rule is a rule about what an app must never do to the people it holds data about, written precisely enough that code can enforce it and a test can check it. Product safety rules come from thinking about how the product could hurt someone, including how someone could misuse it on purpose. They are product decisions, and they are also engineering decisions. A rule that lives only in the builder's head or a planning document will be broken by the next feature an agent writes. The agent doesn't know the rule exists unless the code or the tests tell it.

A good product safety rule has three parts.

  1. A sentence anyone can read. "The app never shows an address."
  2. A place in the code that enforces it. A filter that every report passes through, or a data model that has no column for addresses at all.
  3. A test that fails if the rule breaks. Chapter 10 covers tests that guard rules like this one.

The dating-safety app has three product safety rules that were treated as must-be-right from the start. The first, no false all-clear, is about checks that fail to run. It belongs with outside services, and Chapter 9 covers it. This chapter covers the other two, plus the broader work of preventing abuse.

The No-Locate Rule

The no-locate rule says the app never returns a person's home address, workplace or current location, even when an outside service supplies one. It exists because a safety app that can find people can be used by the people others need to be safe from. Someone trying to find an ex-partner who moved away would find a tool that takes a phone number and returns an address very useful. The no-locate rule keeps the dating-safety app from becoming that tool.

The rule is enforced in two places, which is the point of making it an engineering decision.

  • The data model. There is no column for an address in the check results. The people-search adapter drops address fields as soon as the vendor's response arrives, before anything is stored. Data that never lands in the database can't be shown by a future feature.
  • The output. Every report passes through one function on its way to the member. That function removes anything shaped like a street address, and it fails the request loudly if a location field ever shows up. Its test feeds the people-search adapter a fake vendor response full of addresses, runs a scan, and checks that no address appears anywhere in the report or the database.

The test keeps the rule in force. Six months from now, someone will ask an agent to "add more detail to the people-search results." The agent will see the vendor returns addresses and helpfully add them. The test will fail, and the failing test will tell the agent why.

Partial locations still locate

Sawyer warning Watch out for partial locations. A city, a neighborhood or the name of an employer still tells a stranger where to look, and a filter that only matches street addresses lets them through. Put those cases in the no-locate test too.

The Verify-Before-Naming Rule

AI models are good at proposing who someone might be. Given a photo and a few messages, a model can suggest that the match is probably a particular person whose photos appear on a certain website. Sometimes that guess is right. Sometimes the model names a stranger who looks a little similar, or invents a person outright. Chapter 4 explains why models produce confident wrong answers.

The verify-before-naming rule says the app never shows a person's name as the likely identity of a match unless code has confirmed it against evidence. The evidence is a web page the search actually returned, showing the name and the photo together. The model proposes; the code verifies. If the code can't verify, the report says that a possible match was found and gives no name.

Here is how the two paths look.

Step Without the rule With the rule
The model looks at the image-search results Suggests the match is a named person Same suggestion
The model gives a source A web address Same web address
The app checks the source Doesn't check Confirms the address was among the pages the image search returned, loads that page, and checks that the name appears on it
The model invented the address, or the name isn't on the page The report names the person anyway The report says "Your match's photos also appear under another identity. We couldn't confirm a name."
What the member does next May confront, accuse or report a stranger Treats the match with caution without targeting anyone

Naming the wrong person can do lasting harm to someone who has nothing to do with the scam. A member who believes the report might post the name, contact that person, or report them. That is why this rule is a must-be-right part, and why it needs a test: feed the verifier an invented web address and a page that doesn't contain the name, and check that the report shows no name.

Abuse Prevention

Abuse prevention is the set of product and engineering measures that make an app hard to use to harm someone, by its own users or by people pretending to be users. The no-locate rule is one such measure. Others in the dating-safety app include:

  • The abuse ledger, which keeps banned people from signing up again, while storing only a salted hash of their number.
  • A daily scan cap, which limits how many scans one account can run, so the app can't be used to look up dozens of people in a night.
  • Minimization and short retention, so that even a misused account gets little out of the app and the data doesn't pile up.

Thinking through abuse means asking an uncomfortable question: if a bad person signed up for my app, what would they try to do with it? Chapter 16 turns that question into a habit called an abuse case, along with rate limits on the app's own endpoints.

The simulation below gives you a set of report lines to judge against the rules in this section.

Diagram: Would This Report Line Ship?

Run the Would This Report Line Ship? MicroSim Fullscreen

Would This Report Line Ship?

Type: microsim sim-id: report-line-safety-review
Library: p5.js
Status: Specified
Bloom Level: Evaluate
Bloom Verb: judge
Learning Objective: The learner will judge ten lines from dating-safety app reports against the no-locate and verify-before-naming rules, deciding which can ship and which rule each failing line breaks, with at least eight of ten correct.

Prerequisites: product safety rule, no-locate rule, verify-before-naming rule, evidence page, data minimization (all defined in the sections "Collect Less" and "Product Safety Rules").

Evidence of Mastery: For each of ten report lines, the learner chooses one of three verdicts: "Ships," "Breaks no-locate," or "Breaks verify-before-naming." A verdict is correct when it matches the answer column in Content. Mastery is 8 of 10 correct on the first attempt.

Misconceptions: (1) A city or neighborhood is vague enough to be safe. (2) A name is safe to show if the model is confident. (3) Information the member could find elsewhere is fine for the app to show. (4) Any line that mentions another identity breaks verify-before-naming.

Instructional Rationale: Judging is an Evaluate skill: the learner applies two stated rules to cases that sit near their edges, such as a workplace named indirectly or a name backed by a page the search never returned. Committing a verdict on each line before seeing the reason trains the check a builder must make when reviewing a new feature.

Content:

Every name below is fictional, and the sim must label all lines "illustrative."

# Report line shown to the learner Evidence status shown with the line Correct verdict Why (feedback)
1 "These photos appear on 4 other dating profiles under different names." Image search returned 4 profile pages Ships It warns the member without naming anyone or locating anyone.
2 "Your match's phone number is an internet phone line, not a mobile line." People-search result Ships Line type is a scam signal and reveals no location.
3 "Your match appears to live on Maple Street in Springfield." People-search result Breaks no-locate It returns an address.
4 "Your match works at the Springfield Regional Hospital." People-search result Breaks no-locate A workplace is a location where a person can be found.
5 "These photos belong to Dana Whitfield, a fitness instructor." Model suggestion; the source page was not among the image-search results Breaks verify-before-naming The model's source wasn't returned by the search, so the name is unverified.
6 "These photos also appear on a page under the name Dana Whitfield." Source page was among the image-search results, and the code confirmed the name and photo appear on it Ships The name was verified against a page the search actually returned.
7 "Your match's photos also appear under another identity. We couldn't confirm a name." Model suggestion could not be verified Ships This is the correct fallback when verification fails.
8 "The phone number was last used in the Riverside neighborhood." People-search result Breaks no-locate A neighborhood narrows where a person can be found.
9 "The model is 95% sure this is Dana Whitfield." Model suggestion; no page checked Breaks verify-before-naming Confidence isn't verification; no page was checked.
10 "The name your match gave doesn't match the name on the phone account." People-search result Ships It reports a mismatch without showing the other name or any location.

Provenance: The no-locate rule and the verify-before-naming rule are from the dating-safety app's product rules in research/seed-notes.md and the section "Product Safety Rules." Line 7's wording is from the worked table in "The Verify-Before-Naming Rule." All names, streets, workplaces and neighborhoods are fictional and illustrative.

Rules: A line breaks no-locate when it states or narrows a person's address, street, neighborhood, workplace or current location. A line breaks verify-before-naming when it shows a person's name as the match's identity and the evidence status does not say the code confirmed the name on a page the search returned. Every other line ships. If a line could break both rules, the expected verdict is no-locate; none of the ten lines does.

Learner Activity:

  1. The learner sees line 1 with its evidence status and the three verdict choices.
  2. The learner picks a verdict and presses Check. The verdict is marked correct or incorrect, with the Why text.
  3. The learner moves to the next line. Lines come in the fixed order 1 to 10.
  4. After line 10, a summary groups the lines by correct verdict, so the learner can compare line 5 with line 6 and line 3 with line 2.

Feedback: Ten lines, fixed order, one attempt each; a checked line can't be re-answered. Correct: "Right. " followed by the Why text. Incorrect: "The verdict is [correct verdict]. " followed by the Why text. If the learner marks line 6 as breaking verify-before-naming, add: "A verified name can ship. The rule is about checking, not about never naming." If the learner marks line 4 or line 8 as Ships, add: "Anything that tells a stranger where to find a person counts as locating." A running count "Lines correct: n of 10" is shown, with "Mastery reached" at 8 or more after line 10.

Starting State: Line 1 with its evidence status and no verdict chosen. The prompt reads "Would you let this line ship in a report?"

Chapter Anchors: The fallback wording is "Your match's photos also appear under another identity. We couldn't confirm a name." The chapter names three product safety rules in the dating-safety app, and this sim covers two of them; no false all-clear is in Chapter 9.

Tell your agent

"Write each of this app's product safety rules as one sentence in docs/product-safety-rules.md. For each rule, show me the code that enforces it and the test that would fail if it broke. If a rule has no test, write one: for no-locate, feed a fake vendor response full of addresses and check that none reaches the report or the database; for verify-before-naming, feed an invented source address and check that no name is shown. Run the tests and show me the results. If a test fails, show me your plan to fix the app before changing it."

Back to the Coat Check

The coat check attendant never thought of herself as running a privacy program. She gave out a ticket instead of asking for a name, checked the pocket before handing over a coat, let unclaimed coats go after thirty days, and never told anyone where an owner lived. An app can't carry those rules as common sense. The agent writing the next feature doesn't know that the match never signed up, or that an address in a report is dangerous, so the rules have to live in the data model and the tests. Chapter 9 follows the data out to the services it travels to, and covers the third product safety rule: never call a check that didn't run a pass.

Key Takeaways

  • A safety app holds sensitive data about people who never signed up. Ask what would happen to them if each item were posted publicly.
  • Store the answer a feature needs, not the whole vendor response (data minimization), and give each kind of data a retention period that a purge job enforces.
  • Keep files in a private bucket and show them through short-lived signed URLs. Encryption doesn't protect against a bug in the app.
  • A salted hash with a secret salt lets the app recognize a value without storing it, as the abuse ledger does.
  • Write the privacy policy from the data flow map, so it describes what the code does.
  • A product safety rule is a sentence, the code that enforces it, and a test that fails if it breaks.

Chapter 8 done

Sawyer celebrating You can now list the personal data your app holds, give each kind a retention period and a purge job, and store a banned number as a salted hash. You can also turn a product safety rule into a sentence, the code that enforces it, and a test. Chapter 9 follows the data out to the vendors it is sent to.

See Annotated References