Description
An API can expose sensitive data when it serializes an entire entity, including fields the caller does not need or may not read.
Potential impact
Passwords, keys, or personal records sent in a response can reach clients and intermediary logs. A disclosed credential may give access to an account.
Remediation
Define a response DTO with the fields this endpoint needs and check the caller’s access. Exclude password hashes and private keys. Include payment, medical, or identification data only when the endpoint needs it and the caller may see it.
Examples
Before
csharp
return Ok(new
{
username = "alice",
password = "hashed_password",
ssn = "123-45-6789"
});
After
csharp
return Ok(new
{
username = "alice",
email = "alice@example.com"
});
The revised response drops the password hash and SSN. It returns username and email, so check that the caller can see both.