Slide 21 of 28
Part 4 · PreventionSlide 21
Slide 21 · Mitigation 3
MIT 03
Use DTOs — never expose the database model directly.

A Data Transfer Object (DTO) is a separate class or schema that defines exactly what an API endpoint accepts or returns. It is completely decoupled from the database model.

Create distinct DTOs for each direction and each operation:

UserCreateRequest — fields allowed when creating a user (name, email, password)

UserUpdateRequest — fields allowed when updating a user (name, bio, avatar)

UserPublicResponse — fields returned to other users (name, bio, avatar only)

UserPrivateResponse — fields returned to the user themselves (name, bio, email, settings)

The database model (which contains passwordHash, isAdmin, resetToken) is never directly serialized into any API response.

Think of the database model as a filing cabinet with everything in it. A DTO is a photocopy of only the pages you're allowed to share. You never hand someone the whole cabinet — you hand them the photocopy.

💼 Business takeaway

Ask for a list of fields in your user and account objects that users should never be able to modify directly — then ask your team to confirm those fields are blocked at the API level, not just hidden in the UI.

← Back MIT 04: Server-side only properties →