Input Validation on Client-Side or Server-Side? (2024)

The question of whether input validation should be performed on the client side or server side is one that has been debated time and time again. There are pros and cons to both approaches, and ultimately the decision of which one to use depends on the specific situation. As web applications are developed, the input received from the client is often stored or reflected back to the user. Then, as security implications were discovered, it was understood that the input needed to be validated. Developers were then advised to restrict or sanitize the user's input.

While some developers only validate on the client-side (e.g., JavaScript), some validate on only the server-side, while others validate on both. Below, each type will be broken down to understand its importance.

Input Validation on Client-Side

Client-side validation is visible to the user. It involves having validation on input forms through JavaScript. For example, if the input is submitted for a phone number or email, a JavaScript validator would provide an error if anything is submitted that does not conform to a phone number or email. For example, below we will see how client-side restrictions could be easily changed.

The following form will only submit if the phrase “success” is submitted.

Input Validation on Client-Side or Server-Side? (1)

Figure 1: Client-side Input Validation, Stage 1

However, a token error is presented when “success” is submitted.

Input Validation on Client-Side or Server-Side? (2)

Figure 2: Client-side Input Validation, Stage 2

This means that the request is submitting a token in addition to the phrase. In order to see what is being done, we can take a look at the request using an interception proxy (such as Burp Proxy).

Input Validation on Client-Side or Server-Side? (3)

Figure 3: Client-side Input Validation, Stage 3

Now that we have confirmed our suspicions, we need to understand what is being used to generate the token. Given the JavaScript is provided to us to populate the page, we can easily view the code.

function rot13(inp) {return inp.replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});}function generate_token() {var phrase = document.getElementById("phrase").value;document.getElementById("token").value = md5(rot13(phrase));}generate_token();

The code above will take the phrase from the input box, run it through a simple substitution cipher (rot13) and then md5 it. We can confirm this by taking the phrase “ChangeMe” and running it through a rot13 substitution which would present us with “PunatrZr”. The hash of “PunatrZr” is 8b479aefbd90795395b3e7089ae0dc09, which matches the token in the request above.

If the phrase “success” is to be successfully submitted, we will need to do the same steps as we did for “ChangeMe”.

  • The rot13 of “success” becomes “fhpprff”

  • The md5 of “fhpprff” is 38581812b435834ebf84ebcc2c6424d6

The next step would be to intercept the request before it is sent to the server and modify the token to be that of 38581812b435834ebf84ebcc2c6424d6.

Input Validation on Client-Side or Server-Side? (4)

Figure 4: Client-side Input Validation, Stage 4

Once submitted, we’ll receive confirmation that it succeeded.

Input Validation on Client-Side or Server-Side? (5)

Figure 5: Client-side Input Validation, Stage 5 – Bypassed

JavaScript has to be accessible by the browser (and therefore the user) to ensure the web application functions as it should. As seen above, any restrictions can be quickly reverse engineered or even bypassed entirely.

Input Validation on Server-Side

Server-side input validation will take whatever is sent by the client and conduct additional checks. Using server-side validation indicates that any input sent by the user (or client) cannot be trusted.

In order to show how effective this is, the following form is vulnerable to Cross-Site Scripting.

Input Validation on Client-Side or Server-Side? (6)

Figure 6: Server-side Input Validation, Stage 1

If a JavaScript payload is submitted, the alert box will appear.

Input Validation on Client-Side or Server-Side? (7)

Figure 7: Server-side Input Validation, Stage 2

This implies that the request was sent to the server and reflected back to the client without any validation. In these examples, we have access to the underlying source code to validate our claim.

  • echo ‘<pre>Hello ‘ . $_GET[ ‘name’ ] . ‘</pre’;

There are many approaches that can be taken to validate from the server-side, and one can simply be to remove JavaScript tags when the name is sent back to the client.

The same payload was sent but now the alert box was not populated.

Input Validation on Client-Side or Server-Side? (8)

Figure 8: Server-side Input Validation, Stage 3 – Fail

Taking a look at the source, we notice that any presence of a script tag within the name variable will be replaced.

  • $name = str_replace( ‘<script>’, ”, $_GET[ ‘name’ ] );

These simple replacements can be by-passed using other Cross-Site Scripting payloads. The recommended solution is to use the PHP htmlspecialchars() function that will encode user input to completely prevent Cross-Site Scripting.

  • $name = htmlspecialchars( $_GET[ ‘name’ ] );

Which Input Validation Should You Use?

In general, it is best to perform input validation on both the client side and server side. Client-side input validation can help reduce server load and can prevent malicious users from submitting invalid data. However, client-side input validation is not a substitute for server-side input validation. Server-side input validation is essential to ensure that only valid data is processed by the application.

While running a dynamic application security test, tools used will bypass the client-side restrictions to attempt injection attacks (e.g., Cross-Site Scripting, SQL injection). Each piece of input must be validated on both ends to ensure injection attacks are mitigated.

Doing input validation on both the client side and server side has a number of benefits:

  • It helps reduce server load since invalid data is never submitted in the first place.

  • It helps prevent malicious users from submitting invalid data.

  • It can help improve application performance since the application doesn't have to waste time processing invalid data.

Ultimately, the decision of whether to perform input validation on the client side or server side depends on the specific situation.

Input Validation on Client-Side or Server-Side? (2024)
Top Articles
3 Ways to Buy Ethereum With Debit Card in 2024 | CoinJournal
DHHS Grant Program (2024) | Financial Support Requirements
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Energy Healing Conference Utah
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Pearson Correlation Coefficient
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Movies - EPIC Theatres
Cvs Sport Physicals
Mercedes W204 Belt Diagram
Mia Malkova Bio, Net Worth, Age & More - Magzica
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Nfsd Web Portal
Selly Medaline
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 5830

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.