---
title: "4. Clientside validation file upload vulnerabilities"
date: 2024-11-13
draft: false
---


Many apps rely on JS frontend to validate format before upload
Since this is happening clientside we can easily bypass it - interacting directly with the server. 
- frontend code can also be moified through browser dev tools 

Any code running front-end is under our control 
Webserver may be responsible for sending that frontend code, rendering/execution frontend happens in our browser. 

In our example we will use burp to modify the request 
![](/img/Pasted image 20241113175622.png)

becomes
![](/img/Pasted image 20241113175658.png)

this assumes the backend lacks proper validation 

---
Second method to bypass clientside validation is through manipulating frontend code 

Browser tools -> select profile image (where we trigger file selector for the upload form)
![](/img/Pasted image 20241113175818.png)
line18 we see:
```bash
<input type="file" name="uploadFile" id="uploadFile" onchange="checkFile(this)" accept=".jpg,.jpeg,.png">
```

We can modify this. The more interesting part is `onchange="checkFile(this)"` which appears to run js

To get the details of this function we go into console and type the functions name to get its details 
`checkFile` 

```bash
    if (extension !== 'jpg' && extension !== 'jpeg' && extension !== 'png') {
        $('#error_message').text("Only images are allowed!");
        File.form.reset();
        $("#submit").attr("disabled", true);
```

we see it checks only whether file ext is an image; if not print error and disable upload button. we can add PHP as one of the allowed extensions or modify the function to remove the ext check 

or just remove it entirely. go into inspector, click profile image again, doubleclick the function name, and delete it. 

```bash
 The modification we made to the source code is temporary and will not persist through page refreshes, as we are only changing it on the client-side. However, our only need is to bypass the client-side validation, so it should be enough for this purpose.
```

