Client-Side Validation

🚫 Front-End Only: Bypassing JavaScript-based file validation that occurs entirely in the browser

Overview

Many web applications only rely on front-end JavaScript code to validate the selected file format before it is uploaded and would not upload it if the file is not in the required format (e.g., not an image).

However, as the file format validation is happening on the client-side, we can easily bypass it by directly interacting with the server, skipping the front-end validations altogether. We may also modify the front-end code through our browser's dev tools to disable any validation in place.


Client-Side Validation

⚠️ Security Flaw: Any code that runs on the client-side is under our control

The exercise shows a basic Profile Image functionality, frequently seen in web applications that utilize user profile features, like social media web applications.

Identifying Client-Side Validation

Common Indicators:

  • File dialog limited to specific formats (e.g., images only)

  • Error messages appear without page refresh

  • No HTTP requests sent during validation

  • Upload button gets disabled based on file type

Example Scenario:

  1. File Selection Dialog - Limited to .jpg, .jpeg, .png formats

  2. Invalid File Selection - "Only images are allowed!" error message

  3. Upload Button Disabled - No server interaction occurs

  4. No Network Activity - Validation happens entirely in browser

Why Client-Side Validation is Vulnerable

Key Vulnerability Points:

  • Complete Control - All code executes within our browser

  • Source Code Access - We can view and modify all JavaScript

  • Server Trust - Backend may trust that frontend validated properly

  • Direct Server Access - We can bypass frontend entirely


Bypass Method 1: Back-end Request Modification

πŸ”§ Direct Server Communication: Bypass frontend by modifying HTTP requests

Burp Suite Interception Method

Step 1: Capture Normal Upload Request

Step 2: Modify Request for PHP Upload

Step 3: Analyze Response

Key Modification Points

Critical Fields to Modify:

  1. filename="HTB.png" β†’ filename="shell.php"

  2. [IMAGE CONTENT] β†’ [PHP WEB SHELL CODE]

Optional Modifications:

  • Content-Type: Can be left as image/png or changed to application/x-php

  • File Extension: Try different PHP extensions (.phtml, .php5, etc.)

Complete Bypass Workflow

Step 1: Setup Interception

Step 2: Trigger Upload

Step 3: Modify Request

Step 4: Verify Upload


Bypass Method 2: Disabling Front-end Validation

πŸ› οΈ Browser DevTools: Modify JavaScript validation directly in the browser

Browser Inspector Method

Step 1: Access Page Inspector

Step 2: Analyze HTML File Input

Key Elements:

  • accept=".jpg,.jpeg,.png" - File dialog filter

  • onchange="checkFile(this)" - JavaScript validation function

Step 3: Examine JavaScript Function

Example checkFile Function:

Removing Validation Function

Method 1: Remove onchange Attribute

Method 2: Remove accept Attribute

Method 3: Remove Both Attributes

Browser-Specific Instructions

Firefox Method:

  1. Right-click on file input β†’ "Inspect Element"

  2. Double-click on attribute name to edit

  3. Delete unwanted attributes

  4. Press Enter to save changes

Chrome Method:

  1. Right-click on file input β†’ "Inspect"

  2. Double-click on attribute to edit

  3. Delete content and press Enter

  4. Changes apply immediately

Edge Method:

  1. Press F12 to open DevTools

  2. Use element selector to find file input

  3. Edit attributes in HTML panel

  4. Changes are applied automatically

Testing Modified Upload

Step 1: Upload PHP File

Step 2: Verify Upload Success

Step 3: Find Uploaded File Location


HTB Academy Lab Solutions

Lab 1: Basic Client-Side Bypass

Target: HTB{...}

Method 1 - Burp Suite Interception:

Method 2 - Browser DevTools:

Expected Workflow

1. Reconnaissance:

2. Bypass Execution:

3. Command Execution:


Advanced Client-Side Bypass Techniques

JavaScript Function Overriding

Method: Redefine Validation Function

Event Listener Removal

Method: Remove Event Handlers

Local Storage Manipulation

Method: Modify Client-Side Variables

Form Validation Override

Method: Disable HTML5 Validation


Detection and Mitigation

Proper Server-Side Validation

Essential Backend Checks:

Defense-in-Depth Strategy

Multiple Validation Layers:

  1. Client-side validation - User experience only

  2. Server-side extension check - File extension validation

  3. MIME type verification - Content-Type header check

  4. Magic byte analysis - Actual file content inspection

  5. File size limits - Prevent DoS attacks

  6. Filename sanitization - Remove dangerous characters

  7. Isolated storage - Non-executable upload directory

This comprehensive guide demonstrates why client-side validation alone is insufficient and provides practical methods to bypass such controls for successful penetration testing.

Last updated