Course contentsShow
← System Design
Lesson 1592 of 1,91939. Real-World System: Image and Video HostingFree lesson

Upload Validation and Virus Scanning

Validate file types, size limits, and scan for malware before accepting uploads to prevent abuse.

Upload Validation and Virus Scanning

What you'll learn: How to protect your image and video hosting platform by validating uploads and scanning for malicious content before accepting files.

Why Validation and Scanning Matter

In an image/video hosting system, users can upload potentially harmful content—either accidentally or maliciously. Without proper checks, your platform could distribute malware, consume resources with junk files, or violate security policies. Validation and scanning act as gatekeepers before files reach your storage layer.

Think of this as airport security: you check boarding passes (file type), weigh luggage (size limits), and scan bags (virus detection) before allowing anything onboard.

Validation Checks

File Type Validation: Verify the file extension and MIME type match expected formats (JPEG, PNG, MP4, etc.). Don't trust the extension alone—attackers can rename malware.exe to photo.jpg. Inspect the file header (magic bytes) to confirm actual content type.

Size Limits: Enforce maximum file sizes to prevent storage abuse and resource exhaustion. Set per-file and per-user quotas. Reject uploads exceeding thresholds early in the pipeline to save bandwidth.

Format Integrity: Parse file headers to ensure the file isn't corrupted or malformed. Invalid files can crash processing pipelines or exploit parser vulnerabilities.

Virus Scanning

Integrate antivirus scanning before storing uploads. Use services like ClamAV (open-source) or cloud-based solutions (AWS GuardDuty, Google Cloud Security Scanner). Scan asynchronously to avoid blocking the upload response—mark files as "pending scan" and quarantine until cleared.

For large files already using multipart uploads, scan chunks incrementally or perform scanning after assembly but before making the file publicly accessible.

Architecture Placement

Run validation immediately after upload receipt, before object storage. Virus scanning can happen asynchronously in a queue-based workflow, allowing quick upload acknowledgment while security checks complete in the background.

Key Takeaway: Upload validation (type, size, integrity) and virus scanning form critical defenses against abuse, ensuring only safe, legitimate content enters your storage and CDN infrastructure.