Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is client-side validation not enough?

I saw here that:

As you probably already know, relying on client-side validation alone is a very bad idea. Always perform appropriate server-side validation as well.

Could you explain why server-side validation is a must?

like image 725
Misha Moroshko Avatar asked Aug 14 '10 13:08

Misha Moroshko


People also ask

Why is client-side validation not sufficient?

JavaScript powered validation can be turned off in the user's browser, fail due to a scripting error, or be maliciously circumvented without much effort. Also, the whole process of form submission can be faked. Therefore, there is never a guarantee that what arrives server side, is clean and safe data.

Why is client-side validation less trustworthy than server side validation?

Mostly the Client Side Validation depends on the JavaScript Language, so if users turn JavaScript off, it can easily bypass and submit dangerous input to the server . So the Client Side Validation can not protect your application from malicious attacks on your server resources and databases.

Why can't you rely solely on client-side validation when creating forms that post to dynamic web pages or CGI scripts?

Because the browser is running on the user's machine, it can be fully controlled by the user. Therefore, any client-side validation code can be controlled and bypassed by an attacker. Use JavaScript only to enhance your pages.

What are the dangers of client-side form field validation?

If you do validation only in client-side, someone may disable javascript (or change the js code, with firebug, for example). So, all validations made in js would be useless and user can insert invalid data in your system.


4 Answers

Client-side validation - I assume you are talking about web pages here - relies on JavaScript.

JavaScript powered validation can be turned off in the user's browser, fail due to a scripting error, or be maliciously circumvented without much effort.

Also, the whole process of form submission can be faked.

Therefore, there is never a guarantee that what arrives server side, is clean and safe data.

like image 136
Pekka Avatar answered Oct 17 '22 23:10

Pekka


There is a simple rule in writing server application: Never trust the user data.

You need to always assume that a malicious user accesses your server in a way you didn't intend (e.g. in this case via a manual query via curl instead of the intended web page). For example, if your web page tries to filter out SQL commands an attacker already has a good hint that it might be a good attack vector to pass input with SQL commands.

like image 42
DarkDust Avatar answered Oct 18 '22 00:10

DarkDust


anyone who knows basic javascript can get around client side.

client side is just used to improve the user experience (no need to reload page to validate)

like image 13
Paul Creasey Avatar answered Oct 18 '22 00:10

Paul Creasey


The client you're talking to may not be the client you think you're talking to, so it may be ignoring whatever validation you're asking it to do.

In the web context, it's not only possible that a user could have javascript disabled in their browser, but there's also the possibility that you may not be talking to a browser at all - you could be getting a form submission from a bot which is POSTing to your submission URL without ever having seen the form at all.

In the broader context, you could be dealing with a hacked client which is sending data that the real client never would (e.g., aim-bots for FPS games) or possibly even a completely custom client created by someone who reverse-engineered your wire protocol which knows nothing about any validation you're expecting it to perform.

like image 7
Dave Sherohman Avatar answered Oct 18 '22 01:10

Dave Sherohman