Test that your API doesn't return more than it should
The profile page shows a name and an avatar. The API behind it returns the whole user row: email, phone, passwordHash, resetToken, isInternalTester, stripeCustomerId. The UI hides them, but anyone who opens the network tab sees everything. This is the "read" half of broken object property level authorization in the OWASP API Top 10.
A denylist on every response
Add this to the collection's test script. It walks the whole JSON response and lists every key that looks like it shouldn't leave the server:
const forbidden = /pass(word)?_?hash|^password$|secret|^salt$|reset_?token|api_?key|private_?key|^ssn$|card_?number|cvv/i;
function findForbidden(value, path, found) {
if (Array.isArray(value)) value.forEach((item, i) => findForbidden(item, `${path}[${i}]`, found));
else if (value && typeof value === 'object') {
for (const [key, child] of Object.entries(value)) {
if (forbidden.test(key)) found.push(`${path}.${key}`);
findForbidden(child, `${path}.${key}`, found);
}
}
return found;
}
let body;
try { body = pm.response.json(); } catch (e) { body = null; }
if (body) {
pm.test('no secret-looking fields in the response', () => {
pm.expect(findForbidden(body, '$', []).slice(0, 10)).to.be.empty;
});
}When it fails, the message lists up to ten paths, such as $.data[0].passwordHash, so you know exactly where to look.
Tune the pattern to your API. accessToken in a login response is expected; exclude that request by name with if (pm.info.requestName !== 'Log in').
An allowlist for sensitive endpoints
A denylist catches known names. For the few endpoints that matter most (profile, user search, public pages), say exactly which fields are allowed:
// Tests on "Get public profile"
const allowed = ['id', 'displayName', 'avatarUrl', 'bio', 'createdAt'];
const extra = Object.keys(pm.response.json()).filter((key) => !allowed.includes(key));
pm.test('the public profile has only public fields', () => {
pm.expect(extra).to.be.empty;
});Now a developer adding email to the model doesn't quietly publish everyone's email. They have to change this test, which makes it a decision.
Other users' data in lists
List and search endpoints are where exposure scales: one request, a thousand users. As an ordinary user, search for other users and check what comes back:
// Tests on "Search users (as member)"
const me = pm.environment.get('userId');
const others = pm.response.json().items.filter((user) => user.id !== me);
const leaking = others.filter((user) => 'email' in user || 'phone' in user);
pm.test('other users\' emails and phones are not returned', () => {
pm.expect(leaking.map((user) => user.id)).to.be.empty;
});Errors and debug fields
Exposure also happens in error responses ("query": "SELECT * FROM users WHERE…") and in debug fields left on in staging (_debug, trace, sql). Add them to the denylist, and see test your API's error responses.
Headers too
X-Powered-By, Server: nginx/1.18.0 and internal hostnames in headers tell an attacker what to try. Check them with security header assertions.