DEV Community

FakeStandard
FakeStandard

Posted on

Often Misused File Upload ( 11503 ) Check the File Extension During Upload

After performing a source code vulnerability scan on the website, the report indicated the issue "Often Misused: File Upload (11503)." To fix this vulnerability, the frontend must validate the file extension.

<input name="file" type="file" accept=".jpg" />
Enter fullscreen mode Exit fullscreen mode

Additionally, the backend must also validate the file extension. The report pointed out that the scanning tool bypassed the frontend checks and directly uploaded a .exe file to the server.
This issue is not a big deal and is easy to fix by checking the file extension on the backend, and rejecting any non-compliant files.

string extension = Path.GetExtension(file.FileName);

if (!(extension == ".jpg"))
{
    throw new Exception("Uploading a file with a disallowed extension.");
}
Enter fullscreen mode Exit fullscreen mode

With that, the vulnerability is considered fixed. Job done☑️


Thanks for reading the article

If you like it, please don't hesitate to click heart button ❤️
or follow my GitHub I'd appreciate it.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay