Return Only Authorized Response Properties
Build permission-aware response projections and check search, detail, export, and nested serialization for sensitive field exposure.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
A permitted record can contain forbidden properties
Reading a record and reading every property of that record are different permissions. An employee directory may legitimately let staff find colleagues by name while forbidding salary, tax identifiers, and performance notes. Returning the persistence model directly can cross that boundary even when login and search permissions work.
In TeamAtlas, any active employee can read colleagues' names, work email addresses, and departments. Payroll data is stored on the same model for an administrative workflow. The frontend renders only the public fields, but the network response contains everything the server serialized.
type Employee struct {
ID string `json:"id"`
Name string `json:"name"`
WorkEmail string `json:"work_email"`
Department string `json:"department"`
SalaryCents int64 `json:"salary_cents"`
TaxIdentifier string `json:"tax_identifier"`
PerformanceNotes string `json:"performance_notes"`
}
Go's JSON encoder normally serializes exported fields, subject to tags and other encoding behavior. A JSON tag names a field; it does not authorize its disclosure. omitempty omits empty values under its rules, not sensitive nonempty values. A frontend hiding a salary column leaves the response available to the caller.