Excessive Data Exposure (Go)
ID |
excessive_data_exposure_go |
Severity |
high |
Remediation Complexity |
medium |
Remediation Risk |
high |
Remediation Effort |
medium |
Family |
API3:2023 - Broken Object Property Level Authorization |
CWE |
CWE-213, CWE-200 |
Resource |
data_exposure |
Language |
net/http, Gin, Echo, Chi, Fiber |
Description
Walks each endpoint’s response model and classifies every field into one of three confidence tiers, based on whether the field is sensitivity-tagged (PII / PCI / PHI / credentials by the sensitivity classifier) and whether the same field name appears in the request:
-
HIGH — sensitive AND not referenced in the request. The caller never asked for the field; returning it is over-fetch.
-
MEDIUM — sensitive AND referenced in the request. Possibly a legitimate field-by-field update — surfaced for review.
-
LOW — not sensitivity-tagged AND not referenced in the request. Mild signal of over-fetching.
Only the HIGH tier fires by default. The detector is per-language because the framework idioms differ — JSON-annotation models in Java / C#, dataclass / Pydantic models in Python, plain-object / class-transformer in JS/TS, struct tags in Go, Eloquent / Symfony serializer groups in PHP.
Rationale
Excessive Data Exposure is the read side of OWASP API3:2023 — the API returns more than the client needs, because the implementation returned a persistence model directly and the persistence model has more fields than the contract. The risk is twofold:
-
Direct data leak — the extra fields contain credentials (
passwordHash,apiToken), PII (email,phone,ssn), or PCI (cardLastFour,accountNumber). Anyone reading the response sees them. -
Object-property authorization bypass — even if the endpoint is authorised to return the object, individual fields on that object should be scoped. A "GET my profile" endpoint authorised for the user should not expose the user’s
isAdminflag,lastLoginIp, orinternalNotes. API3 separates these from API1 (object-level) for exactly this reason.
The pattern is endemic in single-page-app backends, where the same User / Order / Patient entity is reused across all read endpoints, with the client deciding which fields to show. The "client filters out the bad fields" defence does not work — anyone can read the network response.
A susceptible Gin / GORM handler might look like this:
type User struct {
ID int64
Username string
Email string // PII
PasswordHash string // CREDENTIAL
SSN string // PII
IsAdmin bool // PRIVILEGE
}
func GetUser(c *gin.Context) {
var u User
db.First(&u, c.Param("id"))
c.JSON(http.StatusOK, u)
}
encoding/json marshals every exported field — including PasswordHash, SSN, and IsAdmin.
Remediation
The fix is to return a dedicated response model per operation, narrow to the fields the operation actually needs to expose. Specific per-language patterns are in the language pages.
Beyond per-route DTOs:
-
If the sensitivity tag is wrong for your project — for example, an email-newsletter app whose
User.emailfield is intentionally public — exclude the field via per-project sensitivity overrides rather than suppressing the finding. -
Pair this detector with
pii_leak_in_response(focuses on PII / PCI / PHI specifically, with stricter severity). -
Server-side response filtering is the only effective control. Anything that depends on the client hiding fields is not a remediation.
Here is a revised handler with a dedicated response struct:
type PublicUser struct {
ID int64 `json:"id"`
Username string `json:"username"`
}
func GetUser(c *gin.Context) {
var u User
if err := db.Select("id", "username").First(&u, c.Param("id")).Error; err != nil {
c.AbortWithStatus(http.StatusNotFound)
return
}
c.JSON(http.StatusOK, PublicUser{ID: u.ID, Username: u.Username})
}
PublicUser declares the wire shape; the database Select("id", "username") mirrors that shape on the query side so the sensitive columns never leave the database. Adding a sensitive field to User no longer leaks it.
A lighter alternative — json:"-" on every sensitive field of User — works but is fragile: every new sensitive field has to be annotated, and a future ORM-generated model resets the tags.
Configuration
The detector accepts:
-
minConfidence— the minimum confidence tier that fires. Defaulthigh. Set tomediumto include "sensitive AND referenced in request" findings. Set tolowonly for benchmark / audit runs (very noisy).
The set of sensitivity tags (PII / PCI / PHI / credentials) is configured globally on the sensitivity classifier, not per-detector.
References
-
OWASP API Security Top 10 (2023) - API3:2023 - Broken Object Property Level Authorization.
-
CWE-213 : Exposure of Sensitive Information Due to Incompatible Policies.
-
CWE-200 : Exposure of Sensitive Information to an Unauthorized Actor.
-
OWASP Cheat Sheets Series: REST Security Cheat Sheet — section on minimum information disclosure.
-
Go standard library —
encoding/jsonMarshal semantics : how struct tags drive the wire shape. -
GORM —
SelectandOmit: project columns at query time.