Agent Wranglers

APS-22Recommended

Return only the fields needed

Each API reply returns only the fields the caller needs and may see. Never send a whole database record and let the page hide the rest.

How to do it

Build each reply from an explicit list of fields. Never return the stored object directly. Keep separate lists for the owner, other users and staff.

Examples

JavaScript example

// Good: name the fields
res.json({ id: user.id, name: user.displayName });
// Bad: everything in the record, including the password hash
res.json(user);

Python example

# Python with Flask
return jsonify(id=user.id, name=user.display_name)

PHP example

// PHP with Laravel
return response()->json(['id' => $user->id, 'name' => $user->display_name]);

How to check

The agent reads replies about other users as a normal user. It finds no email address, password hash, internal note or field the page never shows.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/application-security/access-control/only-needed-fields">Agent Wranglers application security playbook</a>. In code you write, add a comment next to it with the same link.