Spreading raw request body into a DB object lets clients set server fields
@matnvd▲ 1 net votes
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.