Skip to content

Security: conversora/conversora-file-uploading

Security

SECURITY.md

πŸ›‘οΈ Defensive Security & Threat Model: Secure Next Upload

Security Researcher: axosolaman Research: Axo Security CWE-434 Mitigated Bug Bounty Hardened

Authored by Security Researcher axosolaman (Axo Security)
A technical deep-dive into file upload vulnerability mechanics, bug bounty economics, CWE mitigation mappings, defensive cloud storage engineering, and curated learning references.


πŸ“‘ Table of Contents

  1. The Real-World Threat Landscape & Bug Bounty Economics
  2. Master CWE Vulnerability Mitigation Matrix
  3. The Hidden Dangers of Server-Side EXIF Stripping
  4. 5-Layer Defense-in-Depth Pipeline Architecture
  5. End-to-End Sequence Diagram
  6. Attacker Exploit Scenarios & How Secure Next Upload Neutralizes Them
  7. Vulnerability Learning Resources & Research References
  8. Reporting a Vulnerability
  9. Author & Security Researcher Bio

1. The Real-World Threat Landscape & Bug Bounty Economics

File upload endpoints are historically the single most lucrative attack surface across bug bounty platforms like HackerOne, Bugcrowd, and Intigriti. Naive implementations (e.g. standard multer, basic presigned URLs without byte inspection, or file-extension-only checks) regularly lead to catastrophic breaches.

πŸ“Š Public Bug Bounty Data & Industry Stats

  • CWE-434 (Unrestricted Upload of Dangerous Type): Over 2,220+ unique disclosed reports on HackerOne. It remains among the most actively reported critical bug classes.
  • Chained Vulnerabilities: Path Traversal (CWE-22), Improper Input Validation (CWE-20), and Stored XSS (CWE-79) via uploads account for thousands more findings.
  • Typical Bug Bounty Payout Ranges:
    • Basic MIME Spoof / Extension Bypass: $500 – $3,000
    • Upload βž” Stored XSS or EXIF Data Leak: $1,000 – $5,000
    • Upload βž” Path Traversal / Arbitrary File Write: $3,000 – $15,000
    • Upload βž” Remote Code Execution (RCE): $3,000 – $30,000+ (Critical CVSS 9.0–10.0)

2. Master CWE Vulnerability Mitigation Matrix

CWE ID Vulnerability Name How Secure Next Upload Neutralizes It Severity / Impact Bounty Payout Range
CWE-434 Unrestricted Upload of File with Dangerous Type Strict MIME whitelist + max size limits + 16-byte binary magic byte inspection (PNG, JPEG, PDF, WEBP, AVIF, ZIP, etc.) + post-upload HeadObject verification + single-use cryptographic intent tokens. Critical β†’ High (Malware Hosting / Polyglot Bypass) $3,000 – $30,000+
CWE-646 Reliance on File Name or Extension of Externally-Supplied File Server generates an unpredictable random 7-character object key (e.g. avatars/xK9_m2Q.webp). Never trusts client filenames or double extensions (.php.jpg). Binary magic bytes dictate authenticity. High (Webshell / Polyglot Bypass) $2,000 – $10,000
CWE-20 Improper Input Validation 5-layer defense-in-depth pipeline: Client-side validation β†’ Cryptographic presigned URL constraints β†’ Storage metadata verification β†’ S3 Byte-Range binary inspection β†’ Atomic database commit. High (Injection / Tampering) $1,000 – $5,000
CWE-22 / CWE-73 Path Traversal / External Control of File Path Strict isolated storage folders, randomized server-generated object keys, zero user-controlled file paths, and atomic replacement garbage collection. High β†’ Critical (Arbitrary File Overwrite / Config Tampering) $3,000 – $15,000
CWE-200 / CWE-359 / CWE-212 Exposure of Sensitive Information (EXIF / GPS Leakage) Client-side Web Worker automatically strips all EXIF metadata and GPS coordinates in memory before the upload token is even requested. Medium β†’ High (User Doxxing / Privacy Lawsuits / GDPR) $1,000 – $5,000
CWE-400 Uncontrolled Resource Consumption (DoS) Strict per-entity file size limits + distributed token-bucket rate limiting + Zero Server Bandwidth (Direct-to-S3/R2 PUT). Web servers never buffer file blobs in RAM. Medium β†’ High (Server Crash / Wallet Draining) $500 – $3,000
CWE-862 / CWE-306 Missing Authentication / Missing Authorization Per-entity requiresAuth enforcement, intent records cryptographically bound to authenticated user sessions, and single-use confirmation state machines. High (Unauthorized File Replacement) $1,500 – $6,000
CWE-79 Stored XSS via File Upload SVGs and HTML payloads are sanitized and rejected unless explicitly permitted in isolated sandboxed entity configurations. Medium β†’ High (Session Hijacking / Account Takeover) $1,000 – $5,000

3. The Hidden Dangers of Server-Side EXIF Stripping

Many backend engineers attempt to sanitize image metadata on the server using CLI utilities like ExifTool, ImageMagick, or native C-bindings. From an offensive security perspective, server-side EXIF processing introduces severe critical attack vectors:

⚠️ Vulnerabilities Created by Server-Side EXIF Processing

Risk Type Description & Real-World Exploits Severity
Command Injection / RCE Backend servers invoke binaries (ExifTool, ImageMagick, ffmpeg) on untrusted files. Crafted metadata payloads, filename pipes, or parser format bugs execute arbitrary OS commands.
β€’ CVE-2021-22204 (ExifTool DjVu parser) βž” Led directly to CVE-2021-22205 (GitLab unauthenticated pre-auth RCE).
β€’ Multiple ExifTool command injections via DateTimeOriginal and parameter pipe injection.
Critical (CVSS 9.8–10.0)
Parser & Memory Corruption C/C++ image parsing libraries have a decades-long history of buffer overflows, integer underflows, and out-of-bounds memory writes when unpacking corrupted EXIF chunks.
β€’ Real-world vulnerabilities in libexif, ImageMagick, OpenImageIO, and FFmpeg metadata decoders.
High β†’ Critical
SSRF / Arbitrary File Read Legacy image processors parse indirect metadata delegates (e.g. SVG internal XML entities or MSL scripts), forcing the backend server to make internal network requests or dump local /etc/passwd files.
β€’ Classic ImageTragick (CVE-2016-3714) and modern policy-bypass variants.
High
Denial of Service (DoS) Malformed EXIF headers (such as circular tags or decompression bombs) trigger infinite loops, 100% CPU thread starvation, or multi-gigabyte memory allocations (CWE-770, CWE-400). Medium β†’ High
Privacy Leak During Transit When EXIF stripping is done on the server, the raw unstripped file (containing high-precision GPS coordinates, user home location, device IDs) is transmitted across the wire and written to temporary server disks or logs before being processed. Medium β†’ High (GDPR Breach)
Incomplete Stripping / Polyglot Survival Basic server-side strip commands often strip only standard EXIF IFDs while preserving comments, IPTC, XMP, or embedded PHAR/PHP polyglot blocks inside auxiliary segments. Medium β†’ High

πŸ† Why Client-Side Web Worker Stripping Wins

Architectural Dimension Client-Side Web Worker (Secure Next Upload) Traditional Server-Side Processing
Server Attack Surface Zero β€” Server never executes metadata parsing binaries Massive β€” Server must execute complex C/Perl binaries
RCE Vulnerability Risk None β€” Browser sandbox isolates processing High (History of ExifTool / ImageMagick CVEs)
User GPS & Privacy 100% Protected β€” Stripped before leaving browser Exposed β€” Transits wire & lands in server temp storage
Server CPU & Memory Load Zero Overhead β€” Client device performs resizing High β€” Heavy server CPU spikes and RAM consumption
Bypass Resilience Bypassing client still triggers server-side magic byte locks Attacker only needs to craft 1 weaponized metadata exploit

4. 5-Layer Defense-in-Depth Pipeline Architecture

[ User File ] 
      β”‚
      β–Ό  Layer 1: Pre-flight Client Validation & Web Worker Processing
   β€’ Resizes image, strips EXIF (GPS/camera metadata), compresses file in Web Worker
   β€’ Checks MIME whitelist and size limits before network transmission
      β”‚
      β–Ό  Layer 2: Cryptographic Presigned PUT URL Token Issuance
   β€’ Token-bucket rate limiting check (Redis / In-memory)
   β€’ Issues 60s short-lived Presigned PUT URL locked strictly to Content-Type & Length
   β€’ Generates unpredictable random 7-char cache-busting key (folder/aB3_x9Z.ext)
   β€’ Creates database upload intent record with status: "pending"
      β”‚
      β–Ό  [ Direct Browser-to-Cloud PUT β€” 0 Server Bandwidth Consumed ]
      β”‚
      β–Ό  Layer 3: Post-Upload Storage HeadObject Verification
   β€’ Server queries S3 HeadObject metadata to confirm actual byte length & Content-Type
   β€’ Verifies uploaded size matches intent within strict tolerance (fileSizeTolerance: 0.10)
      β”‚
      β–Ό  Layer 4: 16-Byte Magic Byte Binary Signature Inspection
   β€’ Fetches only first 16 bytes via S3 byte-range request (Range: bytes=0-15)
   β€’ Validates raw mathematical signatures (PNG: 89 50 4E 47, PDF: 25 50 44 46, JPEG: FF D8 FF, etc.)
   β€’ INSTANT PURGE: If spoofed or malicious, instantly deletes object from S3 and marks intent failed
      β”‚
      β–Ό  Layer 5: Single-Use State Machine & Atomic Replacement
   β€’ Updates intent to "completed" with audit logging
   β€’ If swapMode == "atomic_replace", safely deletes old avatar/document from storage
   β€’ Emits finalized secure public CDN URL

5. End-to-End Sequence Diagram

sequenceDiagram
    autonumber
    participant C as Client (React / Browser)
    participant A as API Server (/api/upload/*)
    participant D as Database (PostgreSQL)
    participant S as Cloud Storage (R2 / S3)
    participant R as Rate Limiter (Redis / In-Memory)

    Note over C: 1. User selects file(s)
    opt Image Entity (compressClientSide: true)
        C->>C: Compress image & Strip EXIF/GPS metadata in Web Worker
    end
    
    Note over C, A: Phase 1: Upload Intent Request
    C->>A: POST /api/upload/request { entityType, fileName, fileSize, mimeType }
    A->>R: Check Token Bucket Rate Limit
    R-->>A: Rate limit OK
    A->>A: Validate entity in UploadRegistry & enforce size/MIME constraints
    A->>D: Insert upload_intents (status: 'pending')
    A->>A: Generate random 7-char objectKey (avatars/aB3_x9Z.webp)
    A->>S: Generate Presigned PUT URL (Locked Content-Type & Length)
    A-->>C: Return presignedUrl, uploadIntentId, objectKey
    
    Note over C, S: Phase 2: Direct Upload (0 Server Bandwidth)
    C->>S: PUT request directly to S3 URL with file binary
    S-->>C: 200 OK (Validated at cloud edge)
    
    Note over C, D: Phase 3: 5-Layer Verification & Atomic Commit
    C->>A: POST /api/upload/confirm { uploadIntentId, previousFileUrl }
    A->>D: Query upload_intent by ID (verify status == 'pending')
    A->>S: HeadObject(objectKey)
    A->>A: Verify size & mime match intent within tolerance
    opt If magicByteCheck enabled
        A->>S: GetObject(objectKey, Range: bytes=0-15)
        A->>A: Deep inspect 16-byte raw Magic Bytes against MIME signature
    end
    alt Validation Failed (Tampered / Spoofed Payload)
        A->>S: DeleteObject(objectKey)
        A->>D: Update intent (status: 'failed')
        A-->>C: 422 Unprocessable Entity (Malicious Payload Rejected)
    else Verification Successful
        opt If swapMode == 'atomic_replace' & previousFileUrl provided
            A->>S: DeleteObject(extractKey(previousFileUrl))
        end
        A->>D: Update upload_intents.status = 'completed'
        A->>D: Insert audit_logs
        A-->>C: 200 OK { fileUrl, objectKey, metadata }
    end
Loading

6. Attacker Exploit Scenarios & How Secure Next Upload Neutralizes Them

Scenario A: The Polyglot Webshell Bypass

  • Attacker Strategy: Attacker renames shell.php to shell.php.png or injects PHP code into image comments, expecting the backend or web server to execute it.
  • Secure Next Upload Defense:
    1. The server generates an unpredictable random key (avatars/9xK_m2Z.png), destroying user file paths and extensions.
    2. The raw first 16 bytes are validated against 0x89 0x50 0x4E 0x47 binary signature.
    3. Files are stored on isolated Cloudflare R2 / AWS S3 storage buckets with no PHP execution engine.

Scenario B: The Extension & MIME Spoof

  • Attacker Strategy: Attacker intercepts HTTP request and declares Content-Type: image/jpeg while sending an .exe or .sh script.
  • Secure Next Upload Defense:
    1. The server performs an S3 byte-range read (Range: bytes=0-15) on the uploaded object.
    2. Binary signatures for JPEG (FF D8 FF) fail verification.
    3. The server immediately issues DeleteObject to storage, updates intent status to failed, and logs the security incident.

Scenario C: Intent Replay & Race Conditions

  • Attacker Strategy: Attacker attempts to reuse a valid uploadIntentId to confirm multiple uploads or swap another user's file.
  • Secure Next Upload Defense:
    1. Intent records are strictly bound to the authenticated userId.
    2. The status transition is atomic: only intents with status == 'pending' can be confirmed.
    3. Once confirmed, status transitions to 'completed'. Subsequent requests return 409 Conflict.

7. πŸ“š Vulnerability Learning Resources & Research References

A curated collection of industry-standard security research, interactive labs, and exploit walkthroughs mapped to each vulnerability class:

1. Unrestricted File Upload (CWE-434) – Core Vulnerability

2. Magic Bytes, Content-Type Spoofing & Polyglots

3. Reliance on Filename/Extension (CWE-646) & Path Traversal (CWE-22)

4. Server-Side EXIF & Metadata Processing Risks (RCE via Parsers)

5. EXIF & Geolocation Privacy Leakage (CWE-200 / CWE-212 / CWE-359)

6. General Web Application Security Testing Guides


8. Reporting a Vulnerability

Security is our top priority. If you discover a security vulnerability or potential bypass in @axosolaman/secure-next-upload, please report it responsibly:

  • Email: security@axosecurity.com (or reach out directly on GitHub to @axosolaman)
  • Please include proof-of-concept steps, affected component versions, and exploit impact.
  • We will acknowledge receipt within 24 hours and provide a coordinated remediation.

9. Author & Security Researcher Bio

Secure Next Upload is architected and maintained by axosolaman (Axo Security).

  • Lead Security Researcher: axosolaman
  • GitHub: @axosolaman
  • Organization: Axo Security (@axosecurity)
  • Specialization: Web Application Security, Bug Bounty Vulnerability Research, Zero-Trust Cloud Architectures, and Defensive AppSec Engineering.

There aren't any published security advisories