Skip to content

fix(archive): disable zip compression to prevent CPU exhaustion#655

Open
bewiwi wants to merge 2 commits intomasterfrom
fix/zip-cpu-exhaustion
Open

fix(archive): disable zip compression to prevent CPU exhaustion#655
bewiwi wants to merge 2 commits intomasterfrom
fix/zip-cpu-exhaustion

Conversation

@bewiwi
Copy link

@bewiwi bewiwi commented Feb 27, 2026

Description

This PR fixes a Denial of Service (DoS) vulnerability in the Zip archive generation endpoint (GET /archive/{uploadID}/{filename}).

Previously, the archive.Create() method was used which defaults to DEFLATE compression. If an attacker uploaded uncompressible random data up to the maximum file size limit, and then repeatedly requested the archive zip endpoint concurrently, it forced the server to spawn many goroutines furiously attempting to compress the random data. Since the data is uncompressible, this caused massive CPU exhaustion on the host machine. On smaller and less powerful servers, this simple attack vector easily pegs CPU utilization to 100% and crashes the application or makes it completely unresponsive to legitimate traffic.

Fix

This PR replaces archive.Create(name) with archive.CreateHeader() and explicitly sets Method: zip.Store (No Compression).

By disabling compression and simply streaming the raw file bytes directly into the Zip wrapper, the archive generation consumes almost zero CPU cycles regardless of the size or entropy of the files.

Testing

  • Added unit tests asserting zip.Store is used in new generated archives to prevent regression.
  • Manual verification showing no CPU spike with uncompressible data payloads.

@bewiwi bewiwi marked this pull request as ready for review February 27, 2026 21:07
@camathieu camathieu added this to the 1.4 milestone Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants