Course contentsShow
← Security
Lesson 954 of 3,05220. Web Security - File Upload and ProcessingFree lesson

Race Conditions in File Upload Processing

Exploiting timing windows between file upload and validation to execute malicious files before they are scanned or removed.

Race Conditions in File Upload Processing

What you'll learn: How attackers exploit the timing gap between uploading a file and the server validating or removing it to execute malicious code.

The Critical Window

When you upload a file to a web application, there's often a sequence of events: the file is saved to disk, then scanned for malicious content, renamed, moved to a safe location, or deleted if dangerous. The problem? These steps aren't instantaneous. Between the moment the file lands on the server and when security checks complete, there's a tiny but exploitable window—a race condition.

How the Attack Works

Imagine a secure building where deliveries are dropped in a lobby before being inspected. If someone rushes in during that brief moment before inspection, they can grab the package. Similarly, an attacker can:

  1. Upload a malicious web shell (e.g., shell.php)
  2. Immediately send a request to access that file at its temporary location
  3. If they win the "race" against the security scanner, their shell executes before it gets deleted

The attacker essentially races against the server's validation process, trying to access and execute their payload in that microsecond gap.

Real-World Scenario

An application uploads files to /uploads/temp/, runs a virus scan, then either moves them to /uploads/safe/ or deletes them. An attacker uploads backdoor.php and fires multiple rapid requests to https://example.com/uploads/temp/backdoor.php. If even one request arrives before the scanner removes the file, the backdoor executes and the attacker gains control.

Why It Succeeds

  • Multi-threaded servers process uploads and validations simultaneously
  • Network latency or server load can delay validation
  • Predictable file paths make targeting easier

Key Takeaway: Race conditions in file upload processing occur when attackers exploit timing windows to execute malicious files before validation completes. Secure systems must validate before placing files in web-accessible locations or use atomic operations that prevent access during processing.