Sensitive data exposure: when your application hands over more than the screen needs
Sensitive data exposure does not need a break-in.
A signed-in caller makes a request they are allowed to make, and the response, the error, the export, a cached copy or a log line holds more about a person or the business than the task required. This guide covers each of those five places, what OWASP, MITRE, ASVS 5.0 and the HTTP caching standard say about them, and how to keep a field list per endpoint. It comes with a field-by-field table, a response-diff exercise and a lab you can run on your own computer.
In this guide
Field-level data-minimisation table, response-diff exercise and lab
Part 1 is a table for an invented customer record: twelve fields, six places each can travel, and for every cell whether the field is required, to be removed or to be shortened, with the reason and what backs it. Part 2 is the response-diff exercise, with the three tests that tell required, removable and redactable fields apart.
How to use itHide the instructions
Part 3 is an illustration, not a client system: an invented customer service on 127.0.0.1 in a careless and a careful version, a script that prints the differences, and a regression test that fails on the careless version and passes on the careful one, in six files that import only node: modules and install no packages. Every output was copied from one recorded run on Node.js 26.0.0.
sensitive-data-exposure.txt
Introduction7 lines
Part 1: The field-level data-minimisation table141 lines
Part 2: The response-diff exercise55 lines
Part 3: The lab (an illustration)972 lines
Whole template1,193 lines
FIELD-LEVEL DATA-MINIMISATION TABLE, RESPONSE-DIFF EXERCISE AND LAB
Use it on an application you own, or one you are authorised in writing to test, with test accounts and test records. Nothing here is for collecting data from a service that belongs to someone else.
Part 1 is the table. It works without the lab.
Part 2 is the response-diff exercise: how to compare a screen with its response and decide what each extra field is.
Part 3 is the lab: an illustration with invented data that runs the comparison on your own computer.
================================================================
PART 1: THE FIELD-LEVEL DATA-MINIMISATION TABLE
================================================================
THE RECORD
One stored customer record from the lab, with twelve fields. The person is invented and every value is a marked stand-in.
customerId cus_avery the public id, used in links and logs
internalId 1001 the database row number
fullName Avery Example
email avery.example@customer.example
phone PHONE-STAND-IN-0001
postalAddress 1 Stand-In Street Sampletown
dateOfBirth 1901-01-01
internalNote LAB-NOTE-0001 disputed an invoice so call before any refund written by staff, for staff
passwordHash HASH-STAND-IN-0001
staffOnlyFlag refund-review set by staff, read by staff
paymentReference PAYREF-STAND-IN-0001 the profile screen shows its last four characters
lastSessionId SESSION-STAND-IN-0001
THE SIX PLACES A FIELD CAN TRAVEL
Profile response The answer to the customer's own profile screen. The caller is the customer.
List or search The answer to the staff customer list. The caller is a staff member.
Error message Any error body sent to any caller.
CSV export The mailing list export, whose task is sending a newsletter. The caller is a staff member.
Cache entry A stored copy of a response: in the browser, in a shared cache such as a CDN, or in a cache the application fills itself.
Log line What the application writes down about the request.
THE THREE DECISIONS
REQUIRED The place cannot do its job without the field.
REMOVE The place works without the field. Take it out.
SHORTEN The place needs part of the field, or a stand-in for it. Send, store or log only that: the last four characters, a hash, a yes or no.
THE RULES BEHIND THE DECISIONS, AND THEIR SOURCES
Each decision in the table is this page's advice for this invented record. Where a rule from a standard backs it, the rule's letter follows in round brackets. Where a rule guides it without asking for it in those words, the cell says "page's advice, guided by" and the letter. Where only judgement backs it, the cell says "page's advice". Your own table will differ wherever your screens, tasks and legal duties differ.
(A) Return a subset. ASVS 5.0 requirement 15.3.1, Level 1: the application only returns the required subset of fields from a data object; its example is that it should not return an entire data object, as some individual fields should not be accessible to users. OWASP API3:2023: keep returned data structures to the bare minimum, according to the business and functional requirements for the endpoint. MITRE CWE-201, mitigations: any information that is not necessary to the functionality should be removed.
(B) Return the minimum of a sensitive value. ASVS 5.0 requirement 14.2.6, Level 3: the application only returns the minimum required sensitive data for the application's functionality; its example is returning only some of the digits of a credit card number and not the full number.
(C) Fields by permission. ASVS 5.0 requirement 8.2.3, Level 2: field-level access is restricted to consumers with explicit permissions to specific fields.
(D) Generic errors. ASVS 5.0 requirement 16.5.1, Level 2: a generic message is returned to the consumer when an unexpected or security-sensitive error occurs, ensuring no exposure of sensitive internal system data such as stack traces, queries, secret keys and tokens. MITRE CWE-209, mitigations: error messages only contain minimal details that are useful to the intended audience and no one else.
(E) Caches. A cache stores a whole response, so this column is decided per response, by the most sensitive field the response carries. RFC 9111 section 5.2.2.5: no-store means a cache must not store any part of either the immediate request or the response, and the directive applies to both private and shared caches. Section 5.2.2.7: the unqualified private directive means a shared cache must not store the response. ASVS 5.0 requirement 14.3.2, Level 2: sufficient anti-caching response header fields (that is, Cache-Control: no-store) so that sensitive data is not cached in browsers. Requirement 14.2.2, Level 2: sensitive data is prevented from being cached in server components, such as load balancers and application caches, or is securely purged after use.
(F) Logs. ASVS 5.0, V16 control objective: logs should not include sensitive personal data unless legally required. Requirement 16.2.1, Level 2: each log entry includes necessary metadata, such as when, where, who and what. Requirement 16.2.5, Level 2: when logging sensitive data, logging is enforced based on the data's protection level; its examples are that it may not be allowed to log certain data, such as credentials or payment details, and that other data, such as session tokens, may only be logged by being hashed or masked, either in full or partially. MITRE CWE-532, mitigations: consider seriously the sensitivity of the information written into log files. OWASP Logging Cheat Sheet, under Data to exclude, has two lists. The first is data that should usually not be recorded directly in the logs, but instead should be removed, masked, sanitised, hashed or encrypted; its entries include session identification values, access tokens, authentication passwords, bank account or payment card holder data, and sensitive personal data and some forms of personally identifiable information, with health, government identifiers and vulnerable people as its examples. The second is data that can sometimes also exist and that, while useful for subsequent investigation, may also need to be treated in some special manner before the event is recorded; its entries include non-sensitive personal data, with personal names, telephone numbers and email addresses as its examples. For seven fields of this record (fullName, email, phone, postalAddress, dateOfBirth, internalNote and staffOnlyFlag), the REMOVE in the Log line cell is this page's advice. (F) guides it and does not ask for it in those words, and each of those cells says "page's advice, guided by F".
THE TABLE, FIELD BY FIELD
1. customerId (the public id)
Profile response REMOVE. The route answers for whoever is signed in, so the screen needs no id. (A)
List or search REQUIRED. Each row links to its record by this id. (A: the screen uses it)
Error message REMOVE. The error carries its own reference, and the log line under that reference holds the id. (D)
CSV export REMOVE for a mailing list. REQUIRED when the task has to match rows back to records. (page's advice)
Cache entry Not sensitive by itself. Decided by the other fields in the same response. (E)
Log line REQUIRED. It is the "who" of the line. (F: 16.2.1)
2. internalId (the database row number)
Profile response REMOVE. No screen shows a row number. (A)
List or search REMOVE. The public id does the linking. (A)
Error message REMOVE. (D)
CSV export REMOVE. (A)
Cache entry Does not arise once the field is out of every response. (E)
Log line REMOVE where the public id is already logged. One identifier per person is enough. (page's advice)
3. fullName
Profile response REQUIRED. The screen shows it. (A)
List or search REQUIRED. The list shows it. (A)
Error message REMOVE. (D)
CSV export REQUIRED for the mailing list: the newsletter greets the customer by name. (A)
Cache entry Any response that carries it is about a person. Tell shared caches not to store that response, with private or no-store, and tell the browser's cache not to store it, with no-store, where your classification calls it sensitive. (E)
Log line REMOVE. Log the customerId. (page's advice, guided by F)
4. email
Profile response REQUIRED. The screen shows it. (A)
List or search REQUIRED. The list shows it. (A)
Error message REMOVE. In the lab, the careless error body carries it inside the failing query. (D)
CSV export REQUIRED for the mailing list. (A)
Cache entry As for fullName. (E)
Log line REMOVE. That includes the address of the request: in the lab, a staff search by email put this field into the careless log through the query string. (Page's advice, guided by F. ASVS 5.0 requirement 14.2.1, Level 1, asks that the URL and query string do not contain sensitive information, with an API key or session token as its examples.)
5. phone
Profile response REQUIRED. The screen shows it. (A)
List or search REMOVE. The list does not show it. SHORTEN to its last digits if staff use them to confirm a caller. (A, B)
Error message REMOVE. (D)
CSV export REMOVE. An email newsletter does not use it. (A)
Cache entry As for fullName. (E)
Log line REMOVE. Record that it changed, not what it changed to: the lab's careful log line says changed=phone,postalAddress. (page's advice, guided by F)
6. postalAddress
Profile response REQUIRED. The screen shows it. (A)
List or search REMOVE. The list does not show it. (A)
Error message REMOVE. (D)
CSV export REMOVE for an email newsletter. A postal mail-out is a different purpose with its own column list. (page's advice)
Cache entry As for fullName. (E)
Log line REMOVE. (page's advice, guided by F)
7. dateOfBirth
Profile response REMOVE. The screen does not show it. If a screen has to show that the customer is an adult, SHORTEN: send that yes or no, not the date. (A. B, applied by this page to a date)
List or search REMOVE. (A)
Error message REMOVE. (D)
CSV export REMOVE. (A)
Cache entry Does not arise once the field is out of every response. (E)
Log line REMOVE. (page's advice, guided by F)
8. internalNote
Profile response REMOVE. The caller is the customer, and the note is written by staff for staff. (A, C)
List or search REMOVE. It belongs on a staff record screen, one customer at a time, not in a list. (A)
Error message REMOVE. (D)
CSV export REMOVE. (A)
Cache entry A staff record screen's response would carry it: no-store on that response. (E)
Log line REMOVE. Log that a note was added and who added it. (page's advice, guided by F)
9. passwordHash
Profile response REMOVE. No screen has a use for it. (A)
List or search REMOVE. (A)
Error message REMOVE. (D)
CSV export REMOVE. (A)
Cache entry Does not arise once the field is out of every response. (E)
Log line REMOVE. (F: 16.2.5 gives credentials as an example of data that may not be allowed in logs. Treating a password hash as credential data is this page's advice.)
10. staffOnlyFlag
Profile response REMOVE. The customer has no permission to read it. (C)
List or search REMOVE while the list has no column for it. Staff may read it, so this is a question of need, not of permission: add it to the list's field list on the day the screen shows it. (A)
Error message REMOVE. (D)
CSV export REMOVE. (A)
Cache entry Decided with the response that carries it. (E)
Log line REMOVE from request lines. Log a change to the flag as its own event: who, when and which customer. (page's advice, guided by F: 16.2.1 gives when and who among its examples of necessary metadata)
11. paymentReference
Profile response SHORTEN. The screen shows the last four characters, so the server sends those and no more. The lab's careful version sends them as paymentReferenceEnding. (B)
List or search REMOVE. (A)
Error message REMOVE. (D)
CSV export REMOVE for a mailing list. A reconciliation export is a different purpose and may need it whole or shortened. (B)
Cache entry The shortened value is still about one person: tell shared caches not to store the response, with private or no-store. (E)
Log line REMOVE, or SHORTEN to the same last four characters if support has to match a payment. (F: 16.2.5 gives payment details as an example)
12. lastSessionId
Profile response REMOVE. Nothing the caller sees uses it. (A)
List or search REMOVE. (A)
Error message REMOVE. Tokens are on the list in 16.5.1. (D)
CSV export REMOVE. (A)
Cache entry Does not arise once the field is out of every response. (E)
Log line SHORTEN. If lines have to be tied to one session, log a hash or a masked form of the id, not the id. (F: 16.2.5 gives session tokens as an example)
HOW TO REUSE THE TABLE
1. List every field of one of your own records, including the ones no screen shows.
2. List the places it can travel. Start with these six and add your own: a PDF, a webhook, an email, a support tool.
3. Fill in each cell with a decision, a reason and what backs it.
4. Read down each column. The REQUIRED and SHORTEN cells of a column are that place's field list.
5. For any cell you cannot fill in, run the three tests in Part 2.
================================================================
PART 2: THE RESPONSE-DIFF EXERCISE
================================================================
The exercise compares what a screen displays with what its API response contains, field by field. The method and the three tests are this page's advice.
WHAT YOU NEED
- An application you own or are authorised in writing to test, a test account and test records.
- A browser with developer tools.
- A place to write the worksheet down.
THE METHOD
1. Pick one screen and sign in with the test account.
2. Write down every value the screen displays. Include values shown in part, such as the last four characters of a reference, and values it uses without displaying, such as an id inside a link.
3. Capture the response behind the screen. Open the developer tools, choose the network panel, reload the screen and find the request that returned the data. Save the response body, the status and the Cache-Control header.
4. List every field in the response, including fields inside nested objects and inside every item of a list.
5. Mark each response field: shown in full, shown in part, or not shown.
6. For every field that is not shown in full, run the three tests below.
7. Write down the decision: REQUIRED, REMOVABLE or REDACTABLE.
8. Do the same for the route's error (send it a request that fails), its export if it has one, and its log line.
THE THREE TESTS
Test 1. Remove it in a test build and see what breaks.
Take the field out of the response in a test build. Load every screen that calls the route and run the automated tests.
It finds: consumers that fail straight away.
It misses: a report that runs at the end of the month, and anything outside the test build.
Test 2. Search the client code for its name.
Search the web front end, the mobile app and any integration you hold the code for.
It finds: code that reads the field by name.
It misses: code that loops over every key or passes the whole object along, and consumers whose code you do not hold.
Test 3. Ask who reads it.
Ask the people who own the screen, the support team and anyone who receives the data: who reads this field, and do they need all of it?
It finds: readers outside the repository, and readers who need four characters and not forty.
It misses: a consumer nobody remembers, which is what tests 1 and 2 are for.
TELLING THE THREE DECISIONS APART
REQUIRED Test 1 breaks something the caller is meant to see, and test 3 names a reader who needs the whole value.
REMOVABLE Test 1 breaks nothing, test 2 finds no reference, and test 3 names nobody.
REDACTABLE Test 1 breaks something, but test 3 shows the reader needs only part of the value. The server computes that part and sends it in place of the field.
A reader in a different role (staff, when the caller is a customer) is not a reason to keep the field in this response. That reader's screen gets its own response.
THE WORKSHEET, ONE ROW PER RESPONSE FIELD
Field | Shown on screen: full, part or no | Test 1: what broke | Test 2: where the client code names it | Test 3: who reads it, and how much | Decision | Done
WORKED EXAMPLE: THE LAB'S PROFILE ROUTE, CARELESS VERSION
The lab has no browser and no client code, so tests 1 and 2 are answered from the screen's own list of fields in data.mjs: a field on the list would break the screen if it were removed, and a field off the list is referenced nowhere.
fullName shown in full REQUIRED
email shown in full REQUIRED
phone shown in full REQUIRED
postalAddress shown in full REQUIRED
paymentReference shown in part REDACTABLE: send the last four characters as paymentReferenceEnding
customerId not shown REMOVABLE
internalId not shown REMOVABLE
dateOfBirth not shown REMOVABLE
internalNote not shown REMOVABLE
passwordHash not shown REMOVABLE
staffOnlyFlag not shown REMOVABLE
lastSessionId not shown REMOVABLE
Step 1 of the lab prints the same sorting for all four routes that have a screen or a task.
================================================================
PART 3: THE LAB (AN ILLUSTRATION)
================================================================
WHAT IT IS
An invented customer service in two versions, careless and careful, a script that sends both the same five requests and prints the differences, and a regression test. It is an illustration with invented data. It shows the comparison, not how any real framework, database, cache or logging library behaves, and nothing in it is a client's code or a client's result.
THE PEOPLE AND THEIR DETAILS
Three invented customers: Avery Example, Blake Sample and Casey Invented. Every detail is a marked stand-in. Phone numbers, password hashes, payment references and session ids are labels that end in a counter, such as PHONE-STAND-IN-0001. Dates of birth are 1901-01-01, 1902-02-02 and 1903-03-03. Email addresses end in .example, a top-level domain that RFC 2606 reserves and recommends for use in documentation or as examples. The two session values are fixed labels, not secrets.
WHAT IT NEEDS
Node.js. Apart from each other, the six files import only node:assert/strict, node:crypto, node:fs, node:http, node:path, node:test and node:url, and call the global fetch() function. The lab installs no packages. It was written and run on Node.js 26.0.0 on macOS, the only version and the only system it was run on. The Node.js documentation lists the node:test module as stable since v20.0.0 and fetch() as no longer experimental from v21.0.0. Timestamps, reference ids, request ids, process ids, ports and test timings differ from run to run.
WHAT IT DOES NOT DO
Every server in the lab listens on 127.0.0.1, on a port the system picks. There is no database, no cache and no browser in it: the failing "query" is a label on an error, the cache check prints the header a cache would act on, and each screen is a list of the fields it would show. It writes log files into a lab-logs folder next to the scripts and changes nothing else. Both versions apply the same sign-in and role checks, so nothing in the lab is an access control flaw: every request is one its caller is allowed to make.
THE FIVE ROUTES, THE SAME IN BOTH VERSIONS
GET /api/profile customer the My profile screen
PATCH /api/profile customer the Edit contact details form
GET /api/profile/orders customer a lookup that fails in both versions, standing in for a fault nobody planned for
GET /api/customers staff the Staff customer list screen, with a search
GET /api/customers/export.csv staff the mailing list export
WHAT THE CARELESS VERSION DOES, AND WHAT THE CAREFUL VERSION DOES INSTEAD
Responses Returns the whole stored record. Builds each response that returns record data from an explicit field list.
Errors Sends the failing query and the stack trace. Sends a generic message and a reference, and logs the error's message under the reference.
Export Exports every column. Exports the columns listed for the stated purpose.
Caching Sends no Cache-Control header. Sends Cache-Control: no-store on every response.
Logging Logs the full address and the request body. Logs the route, the outcome and ids.
SETUP
Create an empty folder, save the six files below into it under the names shown, and open a terminal in that folder.
================================================================
FILE 1 OF 6: data.mjs
================================================================
// data.mjs: the invented customers, sessions and screens the lab uses.
// Illustration only. Every person here is invented, and every detail is a
// marked stand-in: phone numbers, password hashes, payment references and
// session ids are labels ending in a counter, dates of birth are in the
// years 1901 to 1903, and email addresses end in .example.
export const CUSTOMERS = [
{
customerId: 'cus_avery',
internalId: 1001,
fullName: 'Avery Example',
email: 'avery.example@customer.example',
phone: 'PHONE-STAND-IN-0001',
postalAddress: '1 Stand-In Street Sampletown',
dateOfBirth: '1901-01-01',
internalNote: 'LAB-NOTE-0001 disputed an invoice so call before any refund',
passwordHash: 'HASH-STAND-IN-0001',
staffOnlyFlag: 'refund-review',
paymentReference: 'PAYREF-STAND-IN-0001',
lastSessionId: 'SESSION-STAND-IN-0001',
},
{
customerId: 'cus_blake',
internalId: 1002,
fullName: 'Blake Sample',
email: 'blake.sample@customer.example',
phone: 'PHONE-STAND-IN-0002',
postalAddress: '2 Stand-In Street Sampletown',
dateOfBirth: '1902-02-02',
internalNote: 'LAB-NOTE-0002 prefers contact by email only',
passwordHash: 'HASH-STAND-IN-0002',
staffOnlyFlag: 'none',
paymentReference: 'PAYREF-STAND-IN-0002',
lastSessionId: 'SESSION-STAND-IN-0002',
},
{
customerId: 'cus_casey',
internalId: 1003,
fullName: 'Casey Invented',
email: 'casey.invented@customer.example',
phone: 'PHONE-STAND-IN-0003',
postalAddress: '3 Stand-In Street Sampletown',
dateOfBirth: '1903-03-03',
internalNote: 'LAB-NOTE-0003 account opened by a staff member in store',
passwordHash: 'HASH-STAND-IN-0003',
staffOnlyFlag: 'none',
paymentReference: 'PAYREF-STAND-IN-0003',
lastSessionId: 'SESSION-STAND-IN-0003',
},
]
// Two fixed sessions, sent in a cookie named lab_session. They are labels,
// not secrets: the lab is about what a signed-in caller is sent, so signing
// in is not part of it.
export const SESSIONS = {
'lab-session-customer-avery': { role: 'customer', actorId: 'cus_avery' },
'lab-session-staff-desk': { role: 'staff', actorId: 'staff_desk' },
}
// What each invented screen displays, or each task uses. The lab has no
// browser: a screen here is the list of fields it would show. A field under
// showsLastFourOf is shown only as its last four characters.
export const SCREENS = {
profile: {
name: 'My profile screen',
shows: ['fullName', 'email', 'phone', 'postalAddress'],
showsLastFourOf: ['paymentReference'],
},
contactDetails: {
name: 'Edit contact details form',
shows: ['phone', 'postalAddress'],
showsLastFourOf: [],
},
customerList: {
name: 'Staff customer list screen',
shows: ['customerId', 'fullName', 'email'],
showsLastFourOf: [],
},
mailingList: {
name: 'Mailing list export (task: send the newsletter)',
shows: ['fullName', 'email'],
showsLastFourOf: [],
},
}
// The new contact details the lab sends through the edit form.
export const NEW_CONTACT = {
phone: 'PHONE-STAND-IN-0099',
postalAddress: '99 Stand-In Street Sampletown',
}
// Nine fields whose values identify or describe a person. compare.mjs searches
// for these exact values in the log file each of its runs writes, and in the
// body of any response with status 500 or above.
const PERSONAL_FIELDS = [
'fullName',
'email',
'phone',
'postalAddress',
'dateOfBirth',
'internalNote',
'passwordHash',
'paymentReference',
'lastSessionId',
]
export function listPersonalValues() {
const values = []
for (const customer of CUSTOMERS) {
for (const field of PERSONAL_FIELDS) {
values.push({ label: customer.customerId + ' ' + field, value: customer[field] })
}
}
values.push({ label: 'cus_avery phone, as changed', value: NEW_CONTACT.phone })
values.push({ label: 'cus_avery postalAddress, as changed', value: NEW_CONTACT.postalAddress })
return values
}
================================================================
FILE 2 OF 6: server.mjs
================================================================
// server.mjs: one invented customer service in two versions, careless and
// careful. Both versions hold the same records, apply the same sign-in and
// role checks and serve the same five routes. They differ in what each
// response, error, export, cache header and log line contains, and the careful
// export refuses a purpose it has no column list for.
// Illustration only: it shows the comparison, not how any framework behaves.
import { createServer } from 'node:http'
import { randomUUID } from 'node:crypto'
import { appendFileSync } from 'node:fs'
import { CUSTOMERS, SESSIONS } from './data.mjs'
const NEWLINE = String.fromCharCode(10)
const ROUTES = {
'GET /api/profile': { role: 'customer', handler: 'getProfile' },
'PATCH /api/profile': { role: 'customer', handler: 'updateContact' },
'GET /api/profile/orders': { role: 'customer', handler: 'listOrders' },
'GET /api/customers': { role: 'staff', handler: 'searchCustomers' },
'GET /api/customers/export.csv': { role: 'staff', handler: 'exportCustomers' },
}
// The careful version's field lists: one explicit list per response that
// returns record data and one per export purpose. A stored field that is not
// on a list is not sent whole (getProfile adds the last four characters of the
// payment reference under its own name), so a field added to the record later
// stays out until someone adds it here on purpose.
const RESPONSE_FIELDS = {
profile: ['fullName', 'email', 'phone', 'postalAddress'],
contactDetails: ['phone', 'postalAddress'],
customerList: ['customerId', 'fullName', 'email'],
}
const EXPORT_COLUMNS = {
'mailing-list': ['fullName', 'email'],
}
// The only fields the edit form may change, in both versions.
const EDITABLE_FIELDS = ['phone', 'postalAddress']
function pick(record, fields) {
const picked = {}
for (const field of fields) picked[field] = record[field]
return picked
}
function json(status, body) {
return { status: status, type: 'application/json', text: JSON.stringify(body) }
}
function csvCell(value) {
return '"' + String(value).split('"').join('""') + '"'
}
function csv(columns, records) {
const lines = [columns.map(csvCell).join(',')]
for (const record of records) {
lines.push(columns.map((column) => csvCell(record[column])).join(','))
}
return { status: 200, type: 'text/csv', text: lines.join(NEWLINE) + NEWLINE }
}
// The lab has no orders table, so this lookup fails in both versions. It
// stands in for a fault nobody planned for. The query text is only a label:
// there is no database behind the lab.
function listOrders(customer) {
const error = new Error('relation "orders" does not exist')
error.query = 'SELECT orderId, placedOn FROM orders WHERE customerEmail = "' + customer.email + '"'
throw error
}
function findCustomers(customers, search) {
const wanted = String(search || '').toLowerCase()
return customers.filter((customer) => {
return (customer.fullName + ' ' + customer.email).toLowerCase().includes(wanted)
})
}
function applyContactChange(customer, body) {
const changed = []
for (const field of EDITABLE_FIELDS) {
if (typeof body[field] !== 'string') continue
customer[field] = body[field]
changed.push(field)
}
return changed
}
// CARELESS: each handler that returns record data sends whatever the stored
// record holds. listOrders returns none, because its lookup always fails.
const carelessHandlers = {
getProfile: (context) => json(200, context.customer),
updateContact: (context) => {
applyContactChange(context.customer, context.body)
return json(200, context.customer)
},
listOrders: (context) => json(200, listOrders(context.customer)),
searchCustomers: (context) => json(200, findCustomers(context.customers, context.search)),
exportCustomers: (context) => csv(Object.keys(context.customers[0]), context.customers),
}
// CARELESS: the failing query and the stack trace go to the caller.
function carelessFailure(error) {
const result = json(500, { error: error.message, query: error.query, stack: error.stack })
result.note = 'error=' + error.message + (error.query ? ' query=' + error.query : '')
return result
}
// CARELESS: the full address, the request body and any failing query are logged.
function carelessLogLine(entry) {
let line = entry.method + ' ' + entry.url + ' ' + entry.status
if (entry.bodyText) line = line + ' body=' + entry.bodyText
if (entry.note) line = line + ' ' + entry.note
return line
}
// CAREFUL: each handler that returns record data builds its response from an
// explicit field list. listOrders has no list, because its lookup always fails.
const carefulHandlers = {
getProfile: (context) => {
const body = pick(context.customer, RESPONSE_FIELDS.profile)
// The screen shows the last four characters, so only those are sent.
body.paymentReferenceEnding = context.customer.paymentReference.slice(-4)
return json(200, body)
},
updateContact: (context) => {
const changed = applyContactChange(context.customer, context.body)
const result = json(200, pick(context.customer, RESPONSE_FIELDS.contactDetails))
result.note = 'changed=' + changed.join(',')
return result
},
listOrders: (context) => json(200, listOrders(context.customer)),
searchCustomers: (context) => {
const found = findCustomers(context.customers, context.search)
const result = json(200, found.map((customer) => pick(customer, RESPONSE_FIELDS.customerList)))
result.note = 'results=' + found.length
return result
},
exportCustomers: (context) => {
const columns = EXPORT_COLUMNS[context.purpose]
if (!columns) return json(400, { error: 'Unknown export purpose' })
const result = csv(columns, context.customers)
result.note = 'purpose=' + context.purpose + ' rows=' + context.customers.length
return result
},
}
// CAREFUL: the caller gets a generic message and a reference. The error's
// message goes to the log under the same reference. In the lab's five requests
// that message comes from the stand-in lookup and names a table, not a person.
function carefulFailure(error) {
const reference = 'ERR-' + randomUUID().slice(0, 8)
const message = 'Something went wrong on our side. Quote the reference if you contact support.'
const result = json(500, { error: message, reference: reference })
result.note = 'ref=' + reference + ' error=' + error.message
return result
}
// CAREFUL: the log line says when, who, what and the outcome, by id. It
// records the route without its query string and does not read the request body.
function carefulLogLine(entry) {
let line = 'req=' + entry.requestId + ' ' + entry.method + ' ' + entry.route + ' ' + entry.status
line = line + ' actor=' + entry.actor
if (entry.note) line = line + ' ' + entry.note
return line
}
const VERSIONS = {
careless: {
handlers: carelessHandlers,
describeFailure: carelessFailure,
logLine: carelessLogLine,
headers: {},
},
careful: {
handlers: carefulHandlers,
describeFailure: carefulFailure,
logLine: carefulLogLine,
// Every response from these routes is about one person or a list of
// people, so the careful version sends no-store on all of them.
headers: { 'cache-control': 'no-store' },
},
}
function readCookie(request, name) {
const header = request.headers.cookie || ''
for (const part of header.split(';')) {
const pair = part.trim().split('=')
if (pair[0] === name) return pair[1]
}
return ''
}
// Reads the JSON body. A body that is not valid JSON gives a fixed error with
// no text from the parser, because the parser's message quotes part of the body
// and both versions write the error's message to the log.
function parseBody(bodyText) {
if (!bodyText) return {}
try {
return JSON.parse(bodyText)
} catch {
throw new Error('request body is not valid JSON')
}
}
// The same checks in both versions: a known route, a session, the right role.
function decide(version, customers, method, url, session, bodyText) {
const route = ROUTES[method + ' ' + url.pathname]
if (!route) return json(404, { error: 'Not found' })
if (!session) return json(401, { error: 'Sign in first' })
if (session.role !== route.role) return json(403, { error: 'Not allowed' })
try {
const context = {
customers: customers,
customer: customers.find((customer) => customer.customerId === session.actorId),
search: url.searchParams.get('search'),
purpose: url.searchParams.get('purpose'),
body: parseBody(bodyText),
}
return version.handlers[route.handler](context)
} catch (error) {
return version.describeFailure(error)
}
}
function answer(version, customers, request, bodyText) {
const url = new URL(request.url, 'http://lab.invalid')
const session = SESSIONS[readCookie(request, 'lab_session')]
const result = decide(version, customers, request.method, url, session, bodyText)
const entry = {
requestId: randomUUID().slice(0, 8),
method: request.method,
url: request.url,
route: url.pathname,
status: result.status,
actor: session ? session.actorId : 'nobody',
bodyText: bodyText,
note: result.note || '',
}
return { result: result, entry: entry }
}
// Starts one version on 127.0.0.1, on a port the system picks, with its own
// copy of the records and its own log file.
export function startServer(versionName, logFile) {
const version = VERSIONS[versionName]
const customers = CUSTOMERS.map((customer) => Object.assign({}, customer))
const server = createServer((request, response) => {
let bodyText = ''
request.on('data', (chunk) => { bodyText = bodyText + chunk })
request.on('end', () => {
const outcome = answer(version, customers, request, bodyText)
const line = new Date().toISOString() + ' ' + version.logLine(outcome.entry)
appendFileSync(logFile, line + NEWLINE)
const headers = Object.assign({ 'content-type': outcome.result.type }, version.headers)
response.writeHead(outcome.result.status, headers)
response.end(outcome.result.text)
})
})
return new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve(server)))
}
export function stopServer(server) {
server.closeAllConnections()
return new Promise((resolve) => server.close(resolve))
}
================================================================
FILE 3 OF 6: compare.mjs
================================================================
// compare.mjs: sends the same five requests to one version of the service
// and records what came back: the fields, the cache header, the error body
// and what the log file holds. run-diff.mjs prints the result and
// fields.test.mjs asserts on it.
import { mkdirSync, readFileSync, rmSync } from 'node:fs'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { NEW_CONTACT, SCREENS, listPersonalValues } from './data.mjs'
import { startServer, stopServer } from './server.mjs'
const LAB_DIR = fileURLToPath(new URL('.', import.meta.url))
export const LOG_DIR = join(LAB_DIR, 'lab-logs')
const NEWLINE = String.fromCharCode(10)
const CUSTOMER = 'lab_session=lab-session-customer-avery'
const STAFF = 'lab_session=lab-session-staff-desk'
// Each request is one the invented screens would make. The orders request
// has no screen: it is the one that fails.
export const REQUESTS = [
{ id: 'profile', screen: 'profile', method: 'GET', path: '/api/profile', cookie: CUSTOMER },
{ id: 'contact', screen: 'contactDetails', method: 'PATCH', path: '/api/profile', cookie: CUSTOMER, body: NEW_CONTACT },
{ id: 'orders', screen: '', method: 'GET', path: '/api/profile/orders', cookie: CUSTOMER },
{ id: 'search', screen: 'customerList', method: 'GET', path: '/api/customers?search=blake.sample@customer.example', cookie: STAFF },
{ id: 'export', screen: 'mailingList', method: 'GET', path: '/api/customers/export.csv?purpose=mailing-list', cookie: STAFF },
]
// The field names in a response: the keys of a JSON object, the keys used
// across a JSON list, or the header row of a CSV file.
function fieldsOf(type, text) {
if (type.startsWith('text/csv')) {
return text.split(NEWLINE)[0].split(',').map((cell) => cell.split('"').join(''))
}
const body = JSON.parse(text)
const records = Array.isArray(body) ? body : [body]
const names = []
for (const record of records) {
for (const name of Object.keys(record)) {
if (!names.includes(name)) names.push(name)
}
}
return names
}
function isShortenedForm(name, screen) {
return screen.showsLastFourOf.some((field) => name === field + 'Ending')
}
// Sorts what a response returned against what its screen shows:
// extras returned, and the screen never shows them
// sentInFull returned whole, though the screen shows only the last four characters
// missing shown by the screen, but not returned
export function compareWithScreen(returned, screen) {
const extras = []
const sentInFull = []
for (const name of returned) {
if (screen.shows.includes(name) || isShortenedForm(name, screen)) continue
if (screen.showsLastFourOf.includes(name)) sentInFull.push(name)
else extras.push(name)
}
const missing = screen.shows.filter((name) => !returned.includes(name))
for (const field of screen.showsLastFourOf) {
if (!returned.includes(field) && !returned.includes(field + 'Ending')) missing.push(field)
}
return { extras: extras, sentInFull: sentInFull, missing: missing }
}
// Which of the lab's invented personal values appear in a piece of text.
export function findPersonalValues(text) {
const found = []
for (const item of listPersonalValues()) {
const count = text.split(item.value).length - 1
if (count > 0) found.push({ label: item.label, count: count })
}
return found
}
function describeResponse(request, response, text) {
const observation = {
request: request,
status: response.status,
cacheControl: response.headers.get('cache-control') || '',
fields: fieldsOf(response.headers.get('content-type'), text),
}
if (request.screen) observation.comparison = compareWithScreen(observation.fields, SCREENS[request.screen])
if (response.status >= 500) {
observation.errorBody = JSON.parse(text)
observation.personalValues = findPersonalValues(text)
}
return observation
}
async function sendRequest(port, request) {
const options = { method: request.method, headers: { cookie: request.cookie } }
if (request.body) {
options.headers['content-type'] = 'application/json'
options.body = JSON.stringify(request.body)
}
const response = await fetch('http://127.0.0.1:' + port + request.path, options)
return describeResponse(request, response, await response.text())
}
function readLog(logFile) {
const text = readFileSync(logFile, 'utf8')
const lines = text.split(NEWLINE).filter((line) => line.length > 0)
return { lines: lines, found: findPersonalValues(text) }
}
// Starts one version, sends the five requests, stops it and reads its log.
export async function observeVersion(versionName) {
mkdirSync(LOG_DIR, { recursive: true })
const logFile = join(LOG_DIR, versionName + '.log')
rmSync(logFile, { force: true })
const server = await startServer(versionName, logFile)
const observations = []
for (const request of REQUESTS) {
observations.push(await sendRequest(server.address().port, request))
}
await stopServer(server)
return { version: versionName, observations: observations, log: readLog(logFile) }
}
================================================================
FILE 4 OF 6: run-diff.mjs
================================================================
// run-diff.mjs: runs the five requests against both versions and prints the
// response diff, the error bodies, the cache headers and the log scan.
// Usage: node run-diff.mjs
import { SCREENS } from './data.mjs'
import { REQUESTS, observeVersion } from './compare.mjs'
const NEWLINE = String.fromCharCode(10)
function list(names) {
return '(' + names.length + '): ' + (names.length ? names.join(', ') : 'none')
}
function requestLabel(request) {
return request.method + ' ' + request.path
}
function printScreenDiff(request, observations) {
const screen = SCREENS[request.screen]
console.log(requestLabel(request))
console.log(' for: ' + screen.name)
console.log(' shows in full ' + list(screen.shows))
console.log(' shows the last four characters of ' + list(screen.showsLastFourOf))
for (const observation of observations) {
const comparison = observation.comparison
console.log(' ' + observation.version + ', HTTP ' + observation.status)
console.log(' returned ' + list(observation.fields))
console.log(' extras ' + list(comparison.extras))
console.log(' sent in full but shown in part ' + list(comparison.sentInFull))
if (comparison.missing.length) console.log(' shown but not returned ' + list(comparison.missing))
}
console.log('')
}
function printErrorBody(observation) {
const body = observation.errorBody
console.log(' ' + observation.version + ', HTTP ' + observation.status)
console.log(' keys in the body ' + list(Object.keys(body)))
console.log(' error: ' + body.error)
if (body.query) console.log(' query: ' + body.query)
if (body.stack) {
const count = body.stack.split(NEWLINE).length
console.log(' stack: ' + count + ' lines, not printed here because they hold file paths')
}
if (body.reference) console.log(' reference: ' + body.reference)
const labels = observation.personalValues.map((item) => item.label)
console.log(' invented personal values in the body ' + list(labels))
}
function printCacheHeaders(versions) {
console.log('CACHE HEADERS: the Cache-Control header on each response')
console.log(' ' + 'request'.padEnd(58) + 'careless'.padEnd(12) + 'careful')
REQUESTS.forEach((request, index) => {
const cells = versions.map((version) => version.observations[index].cacheControl || 'not sent')
console.log(' ' + requestLabel(request).padEnd(58) + cells[0].padEnd(12) + cells[1])
})
console.log('')
}
function printLogScan(version) {
const log = version.log
console.log(' ' + version.version + '.log: ' + log.lines.length + ' lines, ' + log.found.length + ' invented personal value(s) found')
for (const item of log.found) console.log(' ' + item.label + ', ' + item.count + ' time(s)')
const sample = log.lines.find((line) => line.includes('PATCH'))
console.log(' the line for the edit form: ' + sample)
}
const versions = [await observeVersion('careless'), await observeVersion('careful')]
for (const version of versions) {
for (const observation of version.observations) observation.version = version.version
}
console.log('RESPONSE DIFF: what each version returns, against what the screen shows')
console.log('')
REQUESTS.forEach((request, index) => {
if (request.screen) printScreenDiff(request, versions.map((version) => version.observations[index]))
})
const failing = REQUESTS.findIndex((request) => request.id === 'orders')
console.log('ERROR BODY: ' + requestLabel(REQUESTS[failing]) + ', a lookup that fails in both versions')
for (const version of versions) printErrorBody(version.observations[failing])
console.log('')
printCacheHeaders(versions)
console.log('LOG SCAN: each log file, searched for the invented personal values')
for (const version of versions) printLogScan(version)
================================================================
FILE 5 OF 6: fields.test.mjs
================================================================
// fields.test.mjs: the regression test. It fails on the careless version and
// passes on the careful one.
// Usage: node fields.test.mjs careless, or node fields.test.mjs careful
// With no argument it tests the careful version, which is what
// node --test runs when it finds this file by its .test.mjs name.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { SCREENS } from './data.mjs'
import { observeVersion } from './compare.mjs'
const versionName = process.argv[2] === 'careless' ? 'careless' : 'careful'
const observed = await observeVersion(versionName)
const byId = {}
for (const observation of observed.observations) byId[observation.request.id] = observation
// One test per screen or task: the response holds what it shows and no more.
for (const id of ['profile', 'contact', 'search', 'export']) {
const observation = byId[id]
test(versionName + ': ' + SCREENS[observation.request.screen].name + ' gets only its own fields', () => {
const comparison = observation.comparison
assert.equal(comparison.extras.length, 0, 'extra fields returned: ' + comparison.extras.join(', '))
assert.equal(comparison.sentInFull.length, 0, 'sent in full but shown in part: ' + comparison.sentInFull.join(', '))
assert.equal(comparison.missing.length, 0, 'shown but not returned: ' + comparison.missing.join(', '))
})
}
test(versionName + ': an error gives the caller a reference and no internal detail', () => {
const body = byId.orders.errorBody
const keys = Object.keys(body).sort().join(', ')
assert.equal(keys, 'error, reference', 'keys in the error body: ' + keys)
const labels = byId.orders.personalValues.map((item) => item.label)
assert.equal(labels.length, 0, 'personal values in the error body: ' + labels.join(', '))
})
test(versionName + ': every response carries Cache-Control: no-store', () => {
const without = observed.observations.filter((observation) => observation.cacheControl !== 'no-store')
const labels = without.map((observation) => observation.request.method + ' ' + observation.request.path)
assert.equal(labels.length, 0, 'sent without no-store: ' + labels.join('; '))
})
test(versionName + ': the log file holds none of the invented personal values', () => {
const labels = observed.log.found.map((item) => item.label)
assert.equal(labels.length, 0, 'personal values in the log: ' + labels.join('; '))
})
================================================================
FILE 6 OF 6: serve.mjs
================================================================
// serve.mjs: starts one version by itself and keeps it running, so you can
// send it requests with your own HTTP client and read the responses.
// Usage: node serve.mjs careless, or node serve.mjs careful
import { mkdirSync } from 'node:fs'
import { join } from 'node:path'
import { LOG_DIR } from './compare.mjs'
import { startServer } from './server.mjs'
const versionName = process.argv[2] === 'careless' ? 'careless' : 'careful'
mkdirSync(LOG_DIR, { recursive: true })
const server = await startServer(versionName, join(LOG_DIR, versionName + '-serve.log'))
console.log(versionName + ' version listening on http://127.0.0.1:' + server.address().port + ', process id ' + process.pid)
console.log('customer cookie: lab_session=lab-session-customer-avery')
console.log('staff cookie: lab_session=lab-session-staff-desk')
console.log('stop it with Ctrl+C, or by its process id')
================================================================
STEP 1: run the response diff against both versions
================================================================
Command: node run-diff.mjs
RESPONSE DIFF: what each version returns, against what the screen shows
GET /api/profile
for: My profile screen
shows in full (4): fullName, email, phone, postalAddress
shows the last four characters of (1): paymentReference
careless, HTTP 200
returned (12): customerId, internalId, fullName, email, phone, postalAddress, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
extras (7): customerId, internalId, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, lastSessionId
sent in full but shown in part (1): paymentReference
careful, HTTP 200
returned (5): fullName, email, phone, postalAddress, paymentReferenceEnding
extras (0): none
sent in full but shown in part (0): none
PATCH /api/profile
for: Edit contact details form
shows in full (2): phone, postalAddress
shows the last four characters of (0): none
careless, HTTP 200
returned (12): customerId, internalId, fullName, email, phone, postalAddress, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
extras (10): customerId, internalId, fullName, email, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
sent in full but shown in part (0): none
careful, HTTP 200
returned (2): phone, postalAddress
extras (0): none
sent in full but shown in part (0): none
GET /api/customers?search=blake.sample@customer.example
for: Staff customer list screen
shows in full (3): customerId, fullName, email
shows the last four characters of (0): none
careless, HTTP 200
returned (12): customerId, internalId, fullName, email, phone, postalAddress, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
extras (9): internalId, phone, postalAddress, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
sent in full but shown in part (0): none
careful, HTTP 200
returned (3): customerId, fullName, email
extras (0): none
sent in full but shown in part (0): none
GET /api/customers/export.csv?purpose=mailing-list
for: Mailing list export (task: send the newsletter)
shows in full (2): fullName, email
shows the last four characters of (0): none
careless, HTTP 200
returned (12): customerId, internalId, fullName, email, phone, postalAddress, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
extras (10): customerId, internalId, phone, postalAddress, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
sent in full but shown in part (0): none
careful, HTTP 200
returned (2): fullName, email
extras (0): none
sent in full but shown in part (0): none
ERROR BODY: GET /api/profile/orders, a lookup that fails in both versions
careless, HTTP 500
keys in the body (3): error, query, stack
error: relation "orders" does not exist
query: SELECT orderId, placedOn FROM orders WHERE customerEmail = "avery.example@customer.example"
stack: 9 lines, not printed here because they hold file paths
invented personal values in the body (1): cus_avery email
careful, HTTP 500
keys in the body (2): error, reference
error: Something went wrong on our side. Quote the reference if you contact support.
reference: ERR-0fbdc481
invented personal values in the body (0): none
CACHE HEADERS: the Cache-Control header on each response
request careless careful
GET /api/profile not sent no-store
PATCH /api/profile not sent no-store
GET /api/profile/orders not sent no-store
GET /api/customers?search=blake.sample@customer.example not sent no-store
GET /api/customers/export.csv?purpose=mailing-list not sent no-store
LOG SCAN: each log file, searched for the invented personal values
careless.log: 5 lines, 4 invented personal value(s) found
cus_avery email, 1 time(s)
cus_blake email, 1 time(s)
cus_avery phone, as changed, 1 time(s)
cus_avery postalAddress, as changed, 1 time(s)
the line for the edit form: 2026-11-14T05:24:15.481Z PATCH /api/profile 200 body={"phone":"PHONE-STAND-IN-0099","postalAddress":"99 Stand-In Street Sampletown"}
careful.log: 5 lines, 0 invented personal value(s) found
the line for the edit form: 2026-11-14T05:24:15.488Z req=15d30b6c PATCH /api/profile 200 actor=cus_avery changed=phone,postalAddress
Reading it:
Profile The screen shows four fields and the last four characters of a fifth. The careless response carries twelve: seven the screen never shows, and the payment reference whole. The careful response carries the four fields and paymentReferenceEnding.
Edit form The form shows the two fields it edits. The careless version answers a change with the whole record, ten extra fields. The careful version answers with the two.
Search The list shows an id, a name and an email address. The careless version returns nine more fields for every match, the password hash and the date of birth among them.
Export The newsletter needs a name and an email address. The careless file has all twelve columns, ten more than the task uses.
Error The same lookup fails in both versions. The careless body holds the error text, the failing query, which contains the signed-in customer's email address, and the stack trace. The careful body holds a plain sentence and a reference, and the detail is in the careful log under that reference.
Cache The careless version sends no Cache-Control header on any of the five responses. The careful version sends no-store on all five.
Log The careless log holds four of the invented personal values: one email address from the failing query, one from the search in the address, and the new phone number and postal address from the edit form's body. The careful log holds none. Its line for the edit form says who changed which fields, not what they changed to.
================================================================
STEP 2: run the regression test against the careless version
================================================================
Command: node fields.test.mjs careless
✖ careless: My profile screen gets only its own fields (1.103333ms)
✖ careless: Edit contact details form gets only its own fields (0.087708ms)
✖ careless: Staff customer list screen gets only its own fields (0.068ms)
✖ careless: Mailing list export (task: send the newsletter) gets only its own fields (0.06ms)
✖ careless: an error gives the caller a reference and no internal detail (0.208042ms)
✖ careless: every response carries Cache-Control: no-store (0.083541ms)
✖ careless: the log file holds none of the invented personal values (0.0655ms)
ℹ tests 7
ℹ suites 0
ℹ pass 0
ℹ fail 7
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 4.348125
✖ failing tests:
test at fields.test.mjs:20:3
✖ careless: My profile screen gets only its own fields (1.103333ms)
AssertionError [ERR_ASSERTION]: extra fields returned: customerId, internalId, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, lastSessionId
7 !== 0
(stack trace and error details cut here, 13 lines: the first holds a local file path)
test at fields.test.mjs:20:3
✖ careless: Edit contact details form gets only its own fields (0.087708ms)
AssertionError [ERR_ASSERTION]: extra fields returned: customerId, internalId, fullName, email, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
10 !== 0
(stack trace and error details cut here, 15 lines: the first holds a local file path)
test at fields.test.mjs:20:3
✖ careless: Staff customer list screen gets only its own fields (0.068ms)
AssertionError [ERR_ASSERTION]: extra fields returned: internalId, phone, postalAddress, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
9 !== 0
(stack trace and error details cut here, 15 lines: the first holds a local file path)
test at fields.test.mjs:20:3
✖ careless: Mailing list export (task: send the newsletter) gets only its own fields (0.06ms)
AssertionError [ERR_ASSERTION]: extra fields returned: customerId, internalId, phone, postalAddress, dateOfBirth, internalNote, passwordHash, staffOnlyFlag, paymentReference, lastSessionId
10 !== 0
(stack trace and error details cut here, 15 lines: the first holds a local file path)
test at fields.test.mjs:28:1
✖ careless: an error gives the caller a reference and no internal detail (0.208042ms)
AssertionError [ERR_ASSERTION]: keys in the error body: error, query, stack
+ actual - expected
+ 'error, query, stack'
- 'error, reference'
^
(stack trace and error details cut here, 15 lines: the first holds a local file path)
test at fields.test.mjs:36:1
✖ careless: every response carries Cache-Control: no-store (0.083541ms)
AssertionError [ERR_ASSERTION]: sent without no-store: GET /api/profile; PATCH /api/profile; GET /api/profile/orders; GET /api/customers?search=blake.sample@customer.example; GET /api/customers/export.csv?purpose=mailing-list
5 !== 0
(stack trace and error details cut here, 15 lines: the first holds a local file path)
test at fields.test.mjs:42:1
✖ careless: the log file holds none of the invented personal values (0.0655ms)
AssertionError [ERR_ASSERTION]: personal values in the log: cus_avery email; cus_blake email; cus_avery phone, as changed; cus_avery postalAddress, as changed
4 !== 0
(stack trace and error details cut here, 15 lines: the first holds a local file path)
The process exits with code 1. A pipeline step that treats a non-zero exit code as a failure then fails. All seven tests fail, and each failure names what it found. Each test stops at its first failed check, which is why the profile failure lists the seven extra fields and not the payment reference as well. Seven stack traces were cut from this output, with the error details after each, because the first line of each holds a file path from the computer that ran the lab.
================================================================
STEP 3: run it against the careful version
================================================================
Command: node fields.test.mjs careful
✔ careful: My profile screen gets only its own fields (0.562875ms)
✔ careful: Edit contact details form gets only its own fields (0.056667ms)
✔ careful: Staff customer list screen gets only its own fields (0.040208ms)
✔ careful: Mailing list export (task: send the newsletter) gets only its own fields (0.049792ms)
✔ careful: an error gives the caller a reference and no internal detail (0.068875ms)
✔ careful: every response carries Cache-Control: no-store (0.050792ms)
✔ careful: the log file holds none of the invented personal values (0.045375ms)
ℹ tests 7
ℹ suites 0
ℹ pass 7
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 3.743209
The process exits with code 0. With no argument the file tests the careful version, which is what node --test runs when it finds the file by its .test.mjs name:
Command: node --test
✔ careful: My profile screen gets only its own fields (0.542959ms)
✔ careful: Edit contact details form gets only its own fields (0.055292ms)
✔ careful: Staff customer list screen gets only its own fields (0.037875ms)
✔ careful: Mailing list export (task: send the newsletter) gets only its own fields (0.042375ms)
✔ careful: an error gives the caller a reference and no internal detail (0.071375ms)
✔ careful: every response carries Cache-Control: no-store (0.057458ms)
✔ careful: the log file holds none of the invented personal values (0.042084ms)
ℹ tests 7
ℹ suites 0
ℹ pass 7
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 148.253125
This run also exits with code 0.
================================================================
STEP 4: look at a response yourself
================================================================
Command: node serve.mjs careless
careless version listening on http://127.0.0.1:55224, process id 45167
customer cookie: lab_session=lab-session-customer-avery
staff cookie: lab_session=lab-session-staff-desk
stop it with Ctrl+C, or by its process id
The server keeps running until you stop it. From a second terminal, use your own HTTP client to request /api/profile at the address the script printed, sending the customer cookie, and compare the fields in the answer with the profile screen's list in data.mjs. Then stop the server and do the same with node serve.mjs careful. In the recorded run the server was stopped by the process id it printed.
================================================================
STEP 5: point the comparison at your own application
================================================================
1. Copy compare.mjs and fields.test.mjs into your project's tests.
2. Replace startServer and stopServer with your application running against a test database seeded with invented records, and replace the two cookies with however your tests sign in each test account.
3. Rewrite REQUESTS for your own routes, and SCREENS in data.mjs with what each of your screens and tasks really uses. Part 2 is how you find that out.
4. Replace listPersonalValues with the invented values in your own seed data, so the log scan searches for the right strings, and point readLog at your test log.
5. Run it in the pipeline that deploys your application, as a check that has to pass before a change merges.
6. When a screen gains a field, change the screen's list and the response's field list in the same change. The test fails until both agree.What sensitive data exposure means when nobody broke in
Sensitive data exposure is an application giving out information about a person or the business that the recipient did not need and should not have.
This guide is about the version with no break-in at all. The caller signed in properly and asked for something they were allowed to ask for, and the application answered with more than the task required: a profile response that includes a password hash, an error that quotes a database query, an export with every column, a private page left in a shared cache, a log that keeps customers' phone numbers. Nothing was bypassed. The application handed it over.
MITRE's catalogue of software weaknesses names the general case CWE-200, Exposure of Sensitive Information to an Unauthorized Actor: the product exposes sensitive information to an actor that is not explicitly authorised to have access to that information. The kinds of sensitive information the entry lists include private, personal information such as personal messages, financial data, health records, geographic location or contact details; business secrets and intellectual property; and the product's own code or internal state.
It describes three ways an exposure can occur, and the first is the subject of this guide: the code explicitly inserts sensitive information into resources or messages that are intentionally made accessible to unauthorised actors, but should not contain the information.
In those terms, a caller can be authorised to make a request and still be an unauthorised actor for some of what comes back.
A narrower entry fits an over-full response closely. CWE-201, Insertion of Sensitive Information Into Sent Data, is code that transmits data to another actor when a portion of the data includes sensitive information that should not be accessible to that actor.
Its mitigations include specifying which data should be regarded as sensitive, considering which types of users should have access to which types of data, and removing any information that is not necessary to the functionality.
You will also see the problem called information disclosure, or a data exposure vulnerability. CWE-200 lists Information Disclosure as an alternate term and marks it as discouraged, saying the term is frequently used in vulnerability advisories to describe a consequence or technical impact, for any vulnerability that has a loss of confidentiality.
Its mapping notes add that CWE-200 is commonly misused to represent the loss of confidentiality in a vulnerability, that from the CWE perspective loss of confidentiality is a technical impact and not a root cause error, and that as of CWE 4.20 over 400 CWE entries can lead to one.
The distinction is useful outside CWE too. When a report says "information disclosure", ask which mistake produced it, because the fix belongs to the mistake.
What happened to the OWASP category of the same name
Sensitive Data Exposure used to be a category in the OWASP Top 10. The 2017 edition lists it as A3:2017. In the 2021 edition the second category is A02:2021 Cryptographic Failures, and its page says the category was previously known as Sensitive Data Exposure, which it calls more of a broad symptom rather than a root cause, with the focus now on failures related to cryptography, or the lack of it, which often lead to exposure of sensitive data.
The 2025 edition keeps the newer name. Its introduction says A04:2025 Cryptographic Failures falls two spots, from second to fourth, and that the category often leads to sensitive data exposure or system compromise.
The same introduction gives "Sensitive Data Exposure" as an example of a symptom type of CWE, in contrast to root cause types such as "Cryptographic Failure", and says OWASP decided to focus on the root cause whenever possible.
So the phrase did not stop meaning something when the category was renamed. OWASP moved its list towards causes, and exposure is what more than one of those causes produces. This guide stays with a cause that has nothing to do with cryptography: data the application sent, stored or wrote down because nobody decided it should not.
Excessive data exposure, the API name for it
OWASP's API Security Top 10 had a category with a similar name, API3:2019 Excessive Data Exposure. The release notes for the 2023 edition say the project combined Excessive Data Exposure and Mass Assignment, focusing on their common root cause, object property level authorisation validation failures.
Both now sit under API3:2023 Broken Object Property Level Authorization. Its page says an API endpoint is vulnerable if it exposes properties of an object that are considered sensitive and should not be read by the user, which it notes was previously named Excessive Data Exposure, or if it allows a user to change, add or delete the value of a sensitive object property the user should not be able to access, previously named Mass Assignment.
Allowed to see the record is not the same as needing every field
Access control answers one question: may this caller reach this record?
It is a yes or no about the whole record. Data minimisation asks a second question once the answer is yes: which parts of the record does this screen, for this caller, need? A customer may certainly see their own account.
Their browser still has no need for the note a staff member wrote about them, the flag that sends their refunds to a supervisor, or the row number the database uses.
ASVS 5.0 treats the second question as a requirement of its own. Requirement 15.3.1, at Level 1, asks that the application only returns the required subset of fields from a data object, and gives as an example that it should not return an entire data object, as some individual fields should not be accessible to users.
Requirement 14.2.6, at Level 3, asks that the application only returns the minimum required sensitive data for its functionality; its example is returning only some of the digits of a credit card number and not the full number.
Where fields differ by role, requirement 8.2.3, at Level 2, asks that field-level access is restricted to consumers with explicit permissions to specific fields.
OWASP's API3:2023 has a matching item in its prevention list: keep returned data structures to the bare minimum, according to the business and functional requirements for the endpoint.
Staff screens show the difference clearly. A support agent may be entitled to open any customer's record, so nobody questions what the customer list sends. In the lab, the staff list screen shows an id, a name and an email address for each match, and the careless search route returns nine more fields for every customer it finds, the password hash and the date of birth included.
A list, a search or an autocomplete route multiplies whatever one record leaks by the number of rows it returns.
Three answers are possible for each field, and the table on this page works through them for an invented customer record. The field is required: the screen shows it or the task uses it. The field is removable: nothing the caller sees depends on it.
Or the field can be shortened or redacted: the screen needs part of it, such as the last four characters of a payment reference, and the server can send that part alone.
What error messages give away
An error message is a response too, written at the moment the application has least control over what it says.
MITRE's CWE-209, Generation of Error Message Containing Sensitive Information, describes a product that generates an error message including sensitive information about its environment, users or associated data. The entry gives two examples of what can follow. An attempt to exploit a path traversal weakness might yield the full pathname of the installed application.
A SQL injection attempt might not initially succeed, but an error message could reveal the malformed query, which would expose query logic and possibly even passwords or other sensitive information used within the query.
The OWASP Web Security Testing Guide v4.2 test for improper error handling, WSTG-ERRH-01, counts stack traces among the forms errors take, and says improper error handling can let attackers understand the APIs being used internally and gather the versions and types of the applications in use.
The OWASP Top 10:2025 added a category that takes in improper error handling, A10 Mishandling of Exceptional Conditions. One of that page's example scenarios begins with the words sensitive data exposure: improper handling or database errors that reveal the full system error to the user.
The attacker, it says, continues to force errors in order to use the sensitive system information to create a better SQL injection attack.
ASVS 5.0 requirement 16.5.1, at Level 2, says what the caller should get instead: a generic message is returned to the consumer when an unexpected or security-sensitive error occurs, ensuring no exposure of sensitive internal system data such as stack traces, queries, secret keys and tokens. CWE-209's mitigations say error messages should contain only minimal details that are useful to the intended audience and no one else, and that if errors must be captured in some detail they should be recorded in log messages, with thought given to what could occur if the log messages can be viewed by attackers.
The detail still has to go somewhere, or nobody can fix the fault. The pattern the lab's careful version uses is a generic message with a reference: the caller sees a short code, the log holds the detail under the same code, and support can connect the two without the customer ever seeing a query.
In the lab, one lookup fails in both versions. The careless version answers with the error text, the failing query, which contains the signed-in customer's email address, and a stack trace. The careful version answers with one plain sentence and a reference that begins with ERR-.
Personal data reaches error messages by ordinary routes: a query that failed with a customer's email address in its WHERE clause, a validation message that repeats what was typed, an upstream service's reply passed along unread. An error that quotes its input can also end up in places the response never would, such as a screenshot sent to support or an error tracker run by another company.
What an export should contain
An export is a response that leaves the application for good.
A CSV file is saved to a laptop, attached to an email, opened in a spreadsheet and uploaded to a mailing tool, and none of those copies can be recalled or corrected afterwards. The column list of an export deserves more attention than the field list of a screen for that reason. "Export everything" is the quickest version to build, and it looks like a feature.
The rule is the one a response follows, applied to a task in place of a screen. An export exists for a job: send the newsletter, reconcile the month's payments, give the accountant the invoice totals. Each job needs a few columns.
ASVS 5.0's data protection chapter names bulk extraction, alongside modification and excessive usage, as a further consideration for data protection, and its requirement 14.2.6, at Level 3, asks for only the minimum required sensitive data to be returned for the application's functionality.
In the lab, the mailing list export exists to send a newsletter, which needs a name and an email address. The careless version exports all twelve columns for every customer, so the file also holds each customer's phone number, postal address, date of birth, password hash, staff note and session id.
The careful version keeps a column list per purpose, exports two columns, and answers a purpose it has no list for with an error instead of a file.
- Name the purpose. An export route that takes a purpose and looks up that purpose's column list cannot gain a column by accident.
- Shorten inside the export as well. A reconciliation file may need the last four characters of a payment reference and not the reference.
- Treat every generated file as a response. A PDF statement, a spreadsheet, a report emailed on a schedule and a webhook payload sent to another system each have a field list, whether or not anyone wrote it down.
- Log the export as an event: who ran it, for which purpose and how many rows. The lab's careful version logs those three things, along with the time, a request identifier, the method, the route and the status, and none of the rows.
Where a personal response can end up stored, and which directive addresses which
A response does not always stop existing once the browser has shown it.
HTTP allows copies to be kept and reused, and RFC 9111, HTTP Caching, sorts the places that keep them into two kinds. A shared cache stores responses for reuse by more than one user, and the RFC says shared caches are usually, but not always, deployed as part of an intermediary.
A private cache is dedicated to a single user, and the RFC says private caches are often deployed as a component of a user agent. RFC 9110 section 3.5 says the most familiar form of user agent is the general-purpose web browser, though it adds that this is only a small percentage of implementations. The user agent this guide has in mind is a visitor's browser.
A content delivery network that keeps one copy of a response to serve many visitors is a shared cache in that sense. RFC 9110 lists content delivery networks that use gateway caching among the cache architectures deployed across the web. The OWASP Top 10:2025 page for A04 says to disable caching for responses that contain sensitive data, and that this includes caching in your CDN, web server and any application caching, with Redis as its example. The 2017 and 2021 pages carry the same instruction in a shorter form.
The default is the part worth knowing. RFC 9111 says that although caching is an entirely optional feature of HTTP, it can be assumed that reusing a cached response is desirable and that such reuse is the default behaviour when no requirement or local configuration prevents it.
Section 3 says a cache must not store a response unless a list of conditions holds. The conditions include that the no-store directive is not present; that, for a shared cache, the private directive is either not present or allows a shared cache to store a modified response; and that the response contains at least one item from a further list, which includes a status code defined as heuristically cacheable.
RFC 9110 says a 200 response is heuristically cacheable unless the method definition or explicit cache controls indicate otherwise.
One of section 3's conditions concerns authenticated requests. A shared cache must not store the response to a request that carried an Authorization header field unless a response directive is present that explicitly allows shared caching. The list has no matching condition for a request that carried a session cookie, and section 7.3 notes that a Set-Cookie response header field does not inhibit caching.
On this page's reading, then, a 200 response to a GET request authenticated by a cookie, sent with no Cache-Control header, passes each of the conditions quoted here.
Whether a particular cache stores it depends on that product and how it is configured, and that part is this page's point, not the RFC's. Section 3 does note that in normal operation some caches will not store a response that has neither a cache validator nor an explicit expiration time, though they are not prohibited from doing so.
The careful course is to state what you want on every personal response and not lean on a default.
Three Cache-Control response directives sit close together in name, and each answers a different question.
- no-store. Section 5.2.2.5 of RFC 9111 says the directive indicates that a cache must not store any part of either the immediate request or the response, and that it applies to both private and shared caches. It is the directive that addresses the browser's cache and a shared cache together. ASVS 5.0 requirement 14.3.2, at Level 2, asks for sufficient anti-caching HTTP response header fields, which it gives as Cache-Control: no-store, so that sensitive data is not cached in browsers.
- private. Section 5.2.2.7 says the unqualified directive indicates that a shared cache must not store the response, and that a private cache may store it, subject to the constraints defined in section 3. It tells a CDN or proxy cache that follows the standard not to keep a personal response, and leaves the visitor's own browser free to keep it. The RFC adds a note that this usage of the word only controls where the response can be stored, and cannot ensure the privacy of the message content.
- no-cache. Despite its name, its definition is about reuse, not storage. Section 5.2.2.4 says the unqualified directive indicates that the response must not be used to satisfy any other request without forwarding it for validation and receiving a successful response. MITRE's CWE-525, on browser caches that hold sensitive information, gives "no-cache" in the Cache-Control header as its example of a restrictive caching policy for forms and web pages that potentially contain sensitive information. If the aim is that no copy is kept, no-store is the directive whose definition says so.
- Caches your own code fills. An HTTP directive is addressed to HTTP caches. A key-value store holding rendered responses or query results follows your code, not the header. ASVS 5.0 requirement 14.2.2, at Level 2, asks that the application prevents sensitive data from being cached in server components, such as load balancers and application caches, or ensures that the data is securely purged after use. MITRE's CWE-524 describes the weakness as code using a cache that contains sensitive information when the cache can be read by an actor outside the intended control sphere.
RFC 9111 section 5.2.2.5 says no-store is not a reliable or sufficient mechanism for ensuring privacy: in particular, malicious or compromised caches might not recognise or obey the directive, and communications networks might be vulnerable to eavesdropping. Section 6 adds that web browsers often have history mechanisms, such as Back buttons, that can redisplay a representation retrieved earlier in a session, and that the caching requirements do not necessarily apply to how applications use data after it is retrieved from an HTTP cache, although a history mechanism might honour cache directives such as no-store.
The lab has no cache in it. It prints the header a cache would act on: the careless version sends no Cache-Control header on any of its five responses, the profile and the export included, and the careful version sends no-store on all five.
What belongs in a log line and what does not
A log is a copy too, and it is read by a different set of people from the ones who see the screen.
MITRE's CWE-532, Insertion of Sensitive Information into Log File, describes a product that writes sensitive information to a log file, and says logging sensitive user data, full path names or system information often provides attackers with an additional, less-protected path to acquiring the information.
ASVS 5.0's logging chapter states the principle in its control objective: logs should not include sensitive personal data unless legally required, and any logged data must be protected as a high-value asset. Its general logging section says it is critical to log only what is necessary.
Requirement 16.2.1, at Level 2, asks that each log entry includes the necessary metadata, such as when, where, who and what, to allow a detailed investigation of the timeline. Requirement 16.2.5, also Level 2, asks that when sensitive data is logged, the application enforces logging based on the data's protection level.
It gives two examples: it may not be allowed to log certain data, such as credentials or payment details, and other data, such as session tokens, may only be logged by being hashed or masked, either in full or partially.
Requirement 16.3.2, a Level 2 requirement that failed authorisation attempts are logged, adds for Level 3 the logging of all authorisation decisions, including when sensitive data is accessed, without logging the sensitive data itself.
OWASP's Logging Cheat Sheet supplies a working list. It says certain data should usually not be recorded directly in the logs, but removed, masked, sanitised, hashed or encrypted instead. That list includes session identification values, access tokens, authentication passwords, database connection strings, bank account or payment card holder data, and sensitive personal data and some forms of personally identifiable information, for which its examples are health, government identifiers and vulnerable people.
A second list covers data that is useful for later investigation but may need to be treated in some special manner before the event is recorded.
It includes file paths, internal network names and addresses, and non-sensitive personal data such as personal names, telephone numbers and email addresses.
What belongs in the line is the event and the identifiers that let you look the rest up: when it happened, which route, the outcome, an id for the request and an id for the person. Among the cheat sheet's examples of a user identity are a user database table primary key value and a username.
A customer id in a log answers "who was this?" for anyone who can also read the customer table, and says little to someone who has only the log.
Personal details get into logs through a small number of habits, and the lab's careless version has three of them.
- Request bodies. A line that prints the whole body of every request keeps a copy of every form a customer submits. In the lab, the careless log holds the new phone number and postal address a customer typed into the edit form.
- Addresses. A search term or an email address in a query string is part of the URL, and a log line that records the URL records it too. ASVS 5.0 requirement 14.2.1, at Level 1, asks that sensitive data is only sent to the server in the HTTP message body or header fields, and that the URL and query string do not contain sensitive information, with an API key or session token as its examples. In the lab, a staff search by email address puts that customer's address into the careless log. The careful version logs the route without its query string. That covers the application's own log and nothing else: anything in front of the application that records URLs would still record the search text.
- Error detail. The careless version logs the failing query, and the query contains the customer's email address for the same reason the error body did.
- Debug settings left on. CWE-532's mitigations include removing debug log files before deploying the application into production, and adjusting configurations appropriately when software is transitioned from a debug state to production.
Logs travel further than the server
A log line may be stored more than once. It can be forwarded to a hosted log service, copied into an error tracker, pasted into a support ticket and kept in a backup, and each of those is another store with its own set of readers.
ASVS 5.0 requirement 14.1.2, at Level 2, asks that every protection level for sensitive data has a documented set of protection requirements, and its list of what those must cover includes how the data is to be logged and access controls around sensitive data in logs.
Deciding what a line may hold is easier before it is written than after it has been copied to four places.
Keep a field list per endpoint, so new fields do not leak by default
An over-full response can be correct on the day it is written.
The record had six harmless fields and the route returned the record. Then someone added a column for a staff note, another for a risk flag and another for the last session, and every route that returned "the record" began returning those as well, without a line of the route changing. The leak arrived by default.
The durable fix turns the default around. Each response is built from an explicit list of fields, and a field that is not on the list is not sent. A new column then stays out of every response until someone adds it to a list on purpose, and that edit is a line in a code review, where "who needs this?" can be asked.
Libraries offer two styles of control. An allowlist names what to send: Prisma's ORM v7 documentation says to use select when you only need a few scalar fields, and shows a nested select that keeps relation payloads focused.
A denylist names what to hold back. The same Prisma page points to a separate page on excluding fields for cases where you mostly want the default result but need to exclude a few fields, and Mongoose's SchemaType documentation describes a select setting for a path: true if the path should always be included in the results, false if it should be excluded by default, with the setting able to be overridden at the query level.
The two styles fail in opposite directions. A denylist suits a field that should not go out in any response, such as a password hash. Used alone it leaves the default as "send", so the next column added is exposed until someone remembers to exclude it. That is this page's reasoning, not a statement from either library's documentation.
Where the list lives matters less than there being one place for it. For new projects, the Next.js data security guide recommends a dedicated Data Access Layer: an internal library that controls how and when data is fetched and what gets passed to the render context. It says the layer should run only on the server, perform authorisation checks and return safe, minimal Data Transfer Objects.
OWASP's API3:2023 suggests a schema-based response validation mechanism as an extra layer of security, one that defines and enforces the data returned by all API methods. The lab's careful version is the smallest form of the idea: two small objects hold the field lists, one list for each response and one for each export purpose, and each handler that returns record data builds its answer by picking from the stored record through its list.
A field list is easier to write once the fields have been sorted. ASVS 5.0 requirement 14.1.1, at Level 2, asks that all sensitive data created and processed by the application has been identified and classified into protection levels. The OWASP Top 10 has kept the same first step through three editions: the prevention lists for A3:2017, A02:2021 and A04:2025 each begin with classifying the data an application processes, stores or transmits and identifying which data is sensitive according to privacy laws, regulatory requirements or business needs.
Then make the list enforce itself. A test that calls each route with a test account and compares the fields returned against the list fails as soon as a response grows, whoever caused it. The lab's regression test is that idea in seven checks: four routes whose responses must match what their screen or task uses, one error that must carry a reference and no internal detail, the cache header on every response, and a log file that must hold none of the invented personal values.
The Node.js test runner documentation says that if any tests fail, the process exit code is set to 1. A pipeline step that treats a non-zero exit code as a failure stops with it.
The response-diff exercise: compare the screen with the response
You do not need the code to find out what your application over-returns.
You need a test account and a browser. The exercise is to write down what a screen shows, capture what the server sent to draw it, and account for the difference field by field. Use it on an application you own, or one you are authorised in writing to test, with test accounts and test records.
The full method, the worksheet and a worked example are in the asset on this page; this is the short form.
- List what the screen displays, including values shown in part, such as the last four characters of a reference, and values it uses without showing, such as an id inside a link.
- Capture the response behind the screen. In your browser's developer tools, open the network panel, reload the screen and find the request that returned the data. Save the body, the status and the Cache-Control header.
- List every field in the response, including fields inside nested objects and inside each item of a list.
- Mark each response field as shown in full, shown in part or not shown.
- For every field that is not shown in full, run three tests. Remove it from the response in a test build and see what breaks. Search the client code for its name. Ask who reads it, and whether that reader needs the whole value.
- Record a decision for the field: required, removable, or redactable, meaning the server sends a shortened or masked form.
- Repeat for the same route's error, its export if it has one, and its log line.
How the three tests tell required, removable and redactable apart
The three tests fail in different ways, which is why the exercise uses all of them. Removing a field finds the consumers that break straight away and misses the report that runs at the end of the month.
Searching for the field's name finds code that reads it by name and misses code that loops over every key or passes the whole object along. Asking who reads it finds the mobile app, the partner integration and the spreadsheet macro that live outside the repository, and it is the one test that can tell you a reader needs four characters and not forty.
A field is required when removing it breaks something the caller is meant to see and a named reader needs the whole value. It is removable when nothing breaks, nothing references it and nobody can say who reads it. It is redactable when something does break but the reader needs only a part.
The server then computes that part and sends it in place of the field, as the lab's careful version does with the ending of the payment reference.
The lab: one customer service in a careless and a careful version
The lab is an illustration with invented data.
It shows the comparison this page describes, not how any real framework, database, cache or logging library behaves. It is six files that import only node:assert/strict, node:crypto, node:fs, node:http, node:path, node:test and node:url and call the global fetch() function, and it installs no packages.
The service listens on 127.0.0.1 and asks for port 0. The Node.js documentation says that when the port is omitted or is 0, the operating system will assign an arbitrary unused port.
It holds three invented customers, and every detail is a marked stand-in. Phone numbers, password hashes, payment references and session ids are labels that end in a counter, dates of birth fall in 1901 to 1903, and email addresses end in .example, a top-level domain that RFC 2606 reserves and recommends for use in documentation or as examples.
Both versions apply the same sign-in and role checks to the same five routes, so every request in the lab is one its caller is allowed to make. The versions differ only in what they send, what they tell caches and what they log.
Against the careless version, the diff script finds 7, 10, 9 and 10 extra fields in the four responses that have a screen or a task. It finds an error body with the failing query, a stack trace and one customer's email address, no Cache-Control header on any of the five responses, and four invented personal values in the log.
Against the careful version it finds no extra fields, an error body with a generic message and a reference, no-store on all five responses and no personal values in the log.
The regression test fails all seven checks on the careless version and passes all seven on the careful one.
The lab was written and run on Node.js 26.0.0 on macOS, the only version and system it was run on, and every output in the asset comes from that run. Timestamps, reference ids, request ids, process ids, ports and test timings will differ on your computer.
If a response has already been sending too much
Finding an over-full response on a build that matches production means real people's details have been going out for as long as that route has existed.
Work through these in order, and check each step for what it removes before you take it.
- Record what you found before changing anything: the request, the full response, the build and the date. Take a copy of the access logs for the route as well, because a deployment or a retention window can remove them.
- Fix the response on the server, then add the route to a regression test so the field cannot return unnoticed.
- Tell whoever handles privacy for your business, and read what any cyber insurance policy says about telling the insurer before you engage anyone from outside the business.
- If the data reached people who should not have it, an incident response specialist comes next. Clever Ops does not provide incident response or monitoring.
- Work out who received the data, from the logs: which accounts called the route, and since when. A response sent only to the signed-in customer about themselves reached that customer. A staff list, an export or a copy in a shared cache may have reached more people.
- Deal with the stored copies. If a shared cache or CDN could have stored the response, note what was cached and then clear the copies for that route once the fix is live, because the purge removes that evidence as well. Exports already downloaded cannot be recalled; list who ran them and when.
- Treat logs that hold personal details as personal data. Stop writing more, and narrow who can read the files: CWE-532's mitigations include protecting log files against unauthorised read and write. Take advice before deleting or rewriting old log files, because the same files may be the only record of who was affected.
- The OAIC explains that under the Notifiable Data Breaches scheme, an organisation or agency covered by the Privacy Act 1988 must notify affected individuals and the OAIC when a data breach is likely to result in serious harm to a person whose personal information is involved. Australian Privacy Principle 11.1 says that if an APP entity holds personal information, the entity must take such steps as are reasonable in the circumstances to protect the information from misuse, interference and loss, and from unauthorised access, modification or disclosure. Whether either applies to what you found is a question for your privacy adviser, not for this page.
What this guide leaves to other guides
This guide starts from a caller who is allowed to make the request and asks what came back.
The questions around it have guides of their own in this library:
- Secrets exposure: API keys, tokens and passwords that leak into source, repository history, client bundles and logs, and the order in which to revoke, rotate and clean up.
- Security logging and monitoring: which events to record, how to alert on them and how to protect the logs themselves.
- Security misconfiguration: settings that expose detail, such as a debug mode, a directory listing or a default error page left on in production.
- Mass assignment: the mirror image of this guide, fields a client sends that it should not be able to set.
- Broken access control and IDOR: whether the caller may reach the record at all, another customer's included.
- API security: the API as a whole, from the list of endpoints that exist to authentication, limits and old versions left running.
- Web cache deception: a cache tricked into storing a private response under an address that looks like a static file, which ASVS 5.0 requirement 14.2.5 addresses at Level 3.
- LLM data leakage: what an AI feature reveals from prompts, retrieved documents and conversation history.
Where an outside security test fits
The exercise on this page covers the screens you think to check.
A Clever Ops web application and API penetration test is run from test accounts in every role the scope names, and one of its questions about fields is the one this guide asks: do responses carry properties the screen never shows, such as another person's email address, an internal flag or a password hash?
OWASP files that under API3:2023. The website security check includes error pages and debug output among its checks (WSTG-ERRH-01), where a good result is a plain error page with stack traces and debug detail kept in server logs.
Evidence in the report has session tokens, passwords, keys and personal details redacted, and each finding comes with its business impact, a fix and the criteria the retest will use.
A report records what was tested and what was found. It is evidence for your decisions, not a certificate, and it is not monitoring: a field added to a response the week after the test is outside what it can speak to.
If Clever Ops built or hosts your application, the work is a security review rather than an independent test, and the report says who built it and who hosts it.
Frequently asked questions
It is an application giving out personal or business information to someone who did not need it. MITRE catalogues the general weakness as CWE-200, Exposure of Sensitive Information to an Unauthorized Actor. This guide covers the form with no break-in: a signed-in caller makes an allowed request, and the response, error, export, cached copy or log holds more than the task required.
Not under that name. It was A3 in the 2017 edition. The 2021 edition's A02 Cryptographic Failures page says the category was previously known as Sensitive Data Exposure, which it calls more of a broad symptom rather than a root cause, and the 2025 edition lists Cryptographic Failures as A04. The 2025 introduction gives "Sensitive Data Exposure" as an example of a symptom type of CWE.
It is an API response that returns properties of an object the caller should not read. It was API3 in the 2019 OWASP API Security Top 10. The 2023 edition combined it with Mass Assignment as API3:2023 Broken Object Property Level Authorization, whose prevention advice includes keeping returned data structures to the bare minimum the endpoint's business and functional requirements call for.
Yes. Hiding a field in the interface happens after the response has arrived, and a browser's developer tools show the full body of every response. In the lab on this page, the profile screen shows four fields and part of a fifth, while the careless version's response carries all twelve fields of the stored record.
They address different stores. RFC 9111 says the unqualified private directive means a shared cache must not store the response, while a private cache, the kind it says is often part of a user agent, may store it, subject to the constraints defined in its section 3, Storing Responses in Caches. no-store means a cache, private or shared, must not store any part of the request or response. ASVS 5.0 requirement 14.3.2 gives Cache-Control: no-store as the header for keeping sensitive data out of browser caches.
As little as an investigation needs. ASVS 5.0's logging chapter says logs should not include sensitive personal data unless legally required. Its requirement 16.2.5 gives credentials and payment details as examples of data it may not be allowed to log, and session tokens as an example of data that may only be logged hashed or masked. Log an id for the person and for the request, and look the details up when you need them.
Run the response-diff exercise on this page with a test account. List what the screen shows, capture the response in your browser's developer tools, and account for every extra field with three tests: remove it in a test build, search the client code for its name, and ask who reads it. Then keep an explicit field list per endpoint and a test that fails when a response grows.
Scope the right test for your application
Tell us what you have built, who uses it and when it needs to launch. You will get a plain-English recommendation: a website audit, a web application test or a referral to a specialist.