📦 Excessive Data Exposure: Find the API Fields Your UI Never Shows
A profile card shows a display name, an avatar and a city. The JSON that fed the card also carries an email, a phone number and a password hash. Nobody decided to publish those. The endpoint serialized the whole object,
A profile card shows a display name, an avatar and a city. The JSON that fed the card also carries an email, a phone number and a password hash. Nobody decided to publish those. The endpoint serialized the whole object, and the frontend picked the three fields it needed.
That is excessive data exposure. It needs no payload and no bypass: you read a response that was sent to you. It's also easy to over-report, because most extra fields are harmless. This article covers both halves: how to find the fields the UI never shows, and how to tell a harmless extra from a real finding and prove it.
Only test applications you own or are authorized to test. Every example below uses stand-in data and a mock API on 127.0.0.1.
What it is
OWASP listed it as API3 in the 2019 API Security Top 10, under the name Excessive Data Exposure. The 2019 text puts the root cause in one line: "APIs rely on clients to perform the data filtering." The server sends everything, and the client is trusted to hide most of it.
In the 2023 edition it became half of API3:2023 Broken Object Property Level Authorization. An endpoint is vulnerable if it exposes object properties that are sensitive and that the user should not be able to read. The other half is the write side, mass assignment, which I covered in an earlier article. The two are the same mistake in opposite directions: the API checks access to the object and never asks about the individual properties.
OWASP maps the read side to CWE-213, Exposure of Sensitive Information Due to Incompatible Policies.
Where it shows up
OWASP notes that REST APIs tend to return all of an object's properties. So look anywhere an object is serialized for someone who isn't its owner:
- Other users' objects. Public profiles, comment authors, team member lists, marketplace sellers.
-
Nested objects. OWASP's 2019 scenario is a comments endpoint that embeds the author through a generic
toJSON()on theUsermodel, personal data included. -
Responses to writes. In the 2023 scenario, a dating app's
reportUserGraphQL mutation lets the reporter ask for the reported user's full name and recent location in the response. - Lists the UI filters. Another 2019 scenario: the app shows a guard only the cameras for their buildings, while the API returns every camera on the site.
- GraphQL. The client picks the fields, so the question becomes which fields the schema lets this user select.
- Debug and export endpoints. They were built to return everything.
Find it: diff the response against the UI
The method is a comparison. Write down what the UI shows on one screen. Capture the response behind it. Everything in the response that isn't on your list is a lead.
Doing this by eye works for one endpoint. For twenty, I'd rather have a script. Here is a small stand-in API to practice on. In vulnerable mode it returns the whole user record. In fixed mode it returns four named properties.
# mock_api.py - a stand-in API for local practice. Never expose it.
import json, os
from http.server import BaseHTTPRequestHandler, HTTPServer
MODE = os.environ.get("MODE", "vulnerable")
USERS = {
"101": {"id": "101", "displayName": "Account A", "avatar": "/img/a.png",
"email": "[email protected]", "phone": "+00 5550 0101",
"role": "user", "passwordHash": "stand-in-hash-a",
"address": {"city": "Testville", "street": "1 Example Road"}},
"102": {"id": "102", "displayName": "Account B", "avatar": "/img/b.png",
"email": "[email protected]", "phone": "+00 5550 0102",
"role": "user", "passwordHash": "stand-in-hash-b",
"address": {"city": "Mockton", "street": "2 Example Road"}},
}
TOKENS = {"token-a": "101", "token-b": "102"}
def public_profile(user):
"""The fix: name every property this endpoint returns."""
return {
"id": user["id"],
"displayName": user["displayName"],
"avatar": user["avatar"],
"address": {"city": user["address"]["city"]},
}
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
token = self.headers.get("Authorization", "").removeprefix("Bearer ")
if token not in TOKENS:
return self.send_json(401, {"error": "unauthorized"})
parts = self.path.strip("/").split("/")
if len(parts) == 3 and parts[:2] == ["api", "users"] and parts[2] in USERS:
user = USERS[parts[2]]
body = user if MODE == "vulnerable" else public_profile(user)
return self.send_json(200, body)
self.send_json(404, {"error": "not found"})
def send_json(self, status, body):
data = json.dumps(body).encode()
self.send_response(status)
self.send_header("Content-Type", "application/json")
self.send_header("Content-Length", str(len(data)))
self.end_headers()
self.wfile.write(data)
def log_message(self, *args):
pass
if __name__ == "__main__":
HTTPServer(("127.0.0.1", 8000), Handler).serve_forever()
The checker flattens the JSON into paths such as address.street, removes the ones the UI shows, and prints the rest. It takes two more inputs that matter later: a name pattern that hints at sensitivity, and a list of values you planted yourself.
# extra_fields.py - list the response fields the UI never shows.
# usage: python extra_fields.py URL TOKEN shown.txt [planted-value ...]
import json, re, sys, urllib.request
SENSITIVE = re.compile(
r"pass|hash|token|secret|key|email|phone|role|admin|street|birth|internal", re.I
)
def paths(node, prefix=""):
"""Yield (path, value) for every leaf: address.city, items[].price, ..."""
if isinstance(node, dict):
for key, value in node.items():
yield from paths(value, f"{prefix}.{key}" if prefix else key)
elif isinstance(node, list):
for item in node:
yield from paths(item, prefix + "[]")
else:
yield prefix, node
def main():
url, token, shown_file, *planted = sys.argv[1:]
with open(shown_file) as fh:
shown = {line.strip() for line in fh if line.strip()}
req = urllib.request.Request(url, headers={"Authorization": f"Bearer {token}"})
with urllib.request.urlopen(req) as resp:
body = json.load(resp)
leads = proofs = 0
for path, value in paths(body):
if path in shown:
continue
leads += 1
notes = []
if SENSITIVE.search(path):
notes.append("name looks sensitive")
if str(value) in planted:
proofs += 1
notes.append("PLANTED VALUE from the other account")
print(f"extra {path:<16} {', '.join(notes)}")
print(f"\n{leads} field(s) the UI never shows, {proofs} proven with a planted value")
if __name__ == "__main__":
main()
shown.txt is the list from the screen, one path per line:
id
displayName
avatar
address.city
An extra field is a lead, not a finding
A field name proves nothing. role may be public by design. email on your own /me response is your own data. A report that says "the response contains a field called token" gets closed, and it should be.
The 2019 OWASP entry explains why scanners struggle here: telling legitimate data from sensitive data takes an understanding of the application. A tool can show you the difference. Whether it matters is your call, and it comes down to three questions:
- Is the value sensitive? Contact details, location, credentials or hashes, tokens, internal flags and pricing usually are.
- Should this viewer be able to read it? Check as the right user. The owner reading their own email is fine. A stranger reading it is not.
-
Is it real? A field that is always
nullor a placeholder is a code smell, not an exposure.
Prove it with a planted value
The clean proof uses two accounts that you control.
- In account B, set private fields to values only you know: a unique email alias, a phone number, a street.
- As account A, load a screen that shows B, and capture the response.
- Check that the UI, as A, does not show those values. That's your control.
- Search A's response for B's planted values.
If a value you planted in B's private settings comes back in A's session, there is nothing left to argue about. You know the value is real, you know whose it is, and you know A was never shown it.
Against the mock in vulnerable mode, with A's token and B's ID:
$ python extra_fields.py http://127.0.0.1:8000/api/users/102 token-a shown.txt \
"[email protected]" "+00 5550 0102" "2 Example Road"
extra email name looks sensitive, PLANTED VALUE from the other account
extra phone name looks sensitive, PLANTED VALUE from the other account
extra role name looks sensitive
extra passwordHash name looks sensitive
extra address.street name looks sensitive, PLANTED VALUE from the other account
5 field(s) the UI never shows, 3 proven with a planted value
Five leads, three of them proven. role and passwordHash are still leads. A password hash returned to another user is serious enough to report on its own, with the value masked. role needs an argument for why it's sensitive in this app.
Then stop. One pair of your own accounts proves the endpoint. Don't walk the ID space to collect real users' data, and don't try to crack a hash you received. In the report, give the request, the response with values masked, the list of exposed properties and the planted-value steps so the triager can repeat them.
Fix it: name every property you return
OWASP's prevention list for API3:2023 is short, and four items apply here:
- Make sure the user is allowed to see each property you expose.
- Avoid generic methods such as
to_json()andto_string(). Cherry-pick the properties instead. - Keep returned data to the minimum the endpoint needs.
- Add schema-based response validation as an extra layer.
public_profile() in the mock is the cherry-pick. The property that matters is the default: when someone adds a column to the user table next year, it stays out of the response until a person adds it on purpose.
Most frameworks have this built in. In FastAPI, a response model does the filtering. The docs say FastAPI will filter out all the data that isn't declared in the output model, and their own example is a UserOut model that leaves out the password:
from typing import Any
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class PublicProfile(BaseModel):
id: str
displayName: str
avatar: str
@app.get("/api/users/{user_id}", response_model=PublicProfile)
async def read_profile(user_id: str) -> Any:
return load_user(user_id) # the full record goes in, three fields come out
The same docs recommend separate model classes over response_model_include and response_model_exclude. One reason they give: with those parameters, the generated schema still describes the complete model.
In Django REST Framework, the trap is fields = '__all__' on a ModelSerializer. The docs strongly recommend listing every field, so that a model change is less likely to expose data by accident:
class PublicProfileSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ["id", "display_name", "avatar"]
I wrote both snippets from the framework docs and did not run them. load_user and User stand in for your own code. The mock, the checker and the test below were run locally on Python 3.14, and the outputs shown are from those runs.
Two more rules:
-
Different viewers, different shapes. The owner's view and the public view are two serializers. One serializer with
ifstatements inside is where fields slip through. - Filter on the server. Hiding a field in the frontend, or in a mobile app, changes nothing about the response.
Prove the fix: put the contract in a test
A fix like this is easy to undo by accident. Pin the response shape in a test that fails when a new field appears, and keep the planted values in it.
# test_profile_contract.py - the response contract, as a test.
import json, unittest, urllib.request
from extra_fields import paths
BASE = "http://127.0.0.1:8000"
ALLOWED = {"id", "displayName", "avatar", "address.city"}
PRIVATE_TO_B = ["[email protected]", "+00 5550 0102", "2 Example Road"]
def get(path, token):
req = urllib.request.Request(BASE + path, headers={"Authorization": f"Bearer {token}"})
with urllib.request.urlopen(req) as resp:
return resp.read().decode()
class ProfileContract(unittest.TestCase):
def test_control_public_fields_still_work(self):
body = json.loads(get("/api/users/102", "token-a"))
self.assertEqual(body["displayName"], "Account B")
def test_no_field_outside_the_contract(self):
body = json.loads(get("/api/users/102", "token-a"))
extra = {path for path, _ in paths(body)} - ALLOWED
self.assertEqual(extra, set())
def test_planted_private_values_never_appear(self):
raw = get("/api/users/102", "token-a")
for value in PRIVATE_TO_B:
self.assertNotIn(value, raw)
if __name__ == "__main__":
unittest.main()
The control test matters. Without it, an endpoint that returns nothing would pass. In vulnerable mode the suite fails twice (tracebacks trimmed):
FAIL: test_no_field_outside_the_contract
FAIL: test_planted_private_values_never_appear
Ran 3 tests in 0.054s
FAILED (failures=2)
With MODE=fixed, the checker reports 0 field(s) the UI never shows and the suite passes:
Ran 3 tests in 0.053s
OK
The third test searches the raw body for the planted values, so it also catches the same data coming back under a new field name.
Try it yourself
Legal places to practice:
-
The mock above. Start it in
vulnerablemode, run the checker, then setMODE=fixedand run both again. - OWASP crAPI. Its challenge list has an Excessive Data Exposure section: Challenge 4 asks for an endpoint that leaks sensitive information of other users, and Challenge 5 for one that leaks an internal property of a video.
-
VAmPI. Its README lists "Excessive Data Exposure through debug endpoint". Run it with
docker run -p 5000:5000 erev0s/vampi:latest. - PortSwigger Web Security Academy. The lab User ID controlled by request parameter with password disclosure has an account page that carries the user's current password in a masked input.
On each one, write the "shown" list before you look at the response. The habit of making that list is the skill.
Conclusion
Excessive data exposure is a property-level authorization bug: the object is yours to see, and some of its fields are not. Finding it is a diff between the screen and the response. An extra field is a lead. A value you planted in one account and read from another is the proof. The fix is an explicit list of properties for each viewer, and a test that holds the response to that list.
Further reading
- OWASP API3:2023 Broken Object Property Level Authorization
- OWASP API3:2019 Excessive Data Exposure
- CWE-213: Exposure of Sensitive Information Due to Incompatible Policies
- FastAPI: Response Model - Return Type
- Django REST Framework: Serializers (ModelSerializer, specifying which fields to include)
- PortSwigger: API testing (comparing returned objects with accepted fields)
- OWASP crAPI challenges
I'm Krishna, a pentester and the founder of Xalgorix, an open-source AI pentester that only reports vulnerabilities it has actually exploited.
🔐 If this was useful, follow me for more hands-on web & API security write-ups.
🔗 Connect with me on LinkedIn: https://www.linkedin.com/in/xalgord/
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.