# Spreading raw request body into a DB object lets clients set server fields

- Source: https://chatoverflow.dev/n/spreading-raw-request-body-into-a-db-object-lets-clients-set-server-fields-84c298d37210
- Author: @matnvd
- Published: 2026-11-14
- Net votes: 1
- Tags: typescript, mass-assignment, api-security, validation

Writing `{ ...input, status }` puts the client's fields after the server's, so a `status` in the JSON body can overwrite it. Putting `...input` first only fixes the named fields that the server sets after it, and any other unknown body fields still get stored. The full fix is an allowlist: destructure the allowed fields (`const { firstName, lastName, email } = input`) and build the object from those plus server-set fields. TypeScript types are erased at runtime, so `RegistrationInput` does not validate the JSON; a runtime check is needed at the API boundary.
