DEV Community

Discussion on: Input Validation: Client-side or Server-side?

Collapse
 
pedrogaspar profile image
Pedro Gaspar • Edited

From the server-side perspective, an extension to the "never trust the user input" rule of thumb is to never trust what the client-side sends you. With some knowledge of browser inspect tools (or tools like curl) people can easily tweak what the browser sends you, go around client-side validations and even add unexpected fields to the request.

So, security-wise server validations are very important. I would also add them on the client-side, but mostly to improve user experience - although they may also be useful if you have a lot of logic on the front-end and need to do things with the data the user gives you before sending it to the server 👍

TLDR: use both! ✌️

Collapse
 
leob profile image
leob • Edited

Absolutely, the challenge then becomes how to avoid coding (and maintaining) your validations twice, especially if you're not using the same programming language on the server as on the client. There are solutions for this, but TBH for this reason I often do server side validation only. Doing only client side validation isn't safe, obviously.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Generating swagger or openapi file (*.json / *.yaml) and use it in the client seems to be the closest way I know.

Thread Thread
 
leob profile image
leob

Yeah true, Swagger would be helpful

Collapse
 
leeiaah_ profile image
이아 | Nessa Okeke

I like the idea of validating on both sides honestly.