VIRUCHITH
Colour theme
Email Resume (opens in a new tab)

Defending Your Own Website with Non-Recursive Zip Bombs: A Developer's Field Notes

Exploring how non-recursive zip bombs and honeypot endpoints can counter malicious scanners probing for .env, API keys, and .git metadata in web server logs.

Published
Reading time
8 min read
Category
Cyber Security
  • zip bomb
  • honeypot
  • cyber security
  • web security
  • hacking
  • pentesting
Defending Your Own Website with Non-Recursive Zip Bombs: A Developer's Field Notes

It Started With the Logs

I run my small Astro blog hosted on Cloudflare. It is mostly static, cheap to run, and seemingly not worth attacking. Then I started reading the edge logs.

The file logs-2026-11-01T14_15_36.375Z.json showed otherwise. In less than five hours, scanners from multiple countries probed paths targeting credentials, admin panels, and leaked API keys:

  • /.well-known/security.txt: reconnaissance probing.
  • /.vscode/sftp.json and /sftp-config.json: SFTP credentials left in editor configurations.
  • /wp-content/debug.log, /wp-config.php.bak, /wp-login.php: WordPress exploit paths.
  • /.env, /.env.production, /.env.local, /.env.bak, /.env.openai, /.env.anthropic: environment files and LLM provider keys.
  • /.git/config, /.git/index, /.git/logs/HEAD: source code and secrets in Git metadata.
  • /.aws/credentials, /.aws/credentials.bak: cloud credential hunting.
  • /backup.sql, /database.sql, /secrets.json, /auth.json, /settings.json: database dumps and configuration files.
  • /vendor/phpunit, /phpinfo.php, /server-status, /actuator/env: framework status and debug endpoints.

None of these paths exist on the site, so they returned 404s. However, logging and serving constant probes still consumes bandwidth and storage.

Seeing these relentless probes led me down a rabbit hole of active defense strategies, which is how I discovered using non-recursive zip bombs as an HTTP tarpit.


What Is a Zip Bomb?

A zip bomb is an archive that is tiny on disk but expands to an enormous size when decompressed. The classic example, 42.zip, is 42 KB and expands to 4.5 PB if recursively unpacked across six layers. This works because DEFLATE, the standard compression algorithm in ZIP archives, compresses long sequences of identical bytes efficiently. A 10 GB stream of zeroes can shrink to a few megabytes.

Traditional zip bombs rely on nested archives: a zip file contains another zip file, which contains another, multiplying expansion across layers. However, most modern decompression tools do not recurse automatically, and those that do typically enforce depth or size limits. A standard unzip command that extracts only the outer archive avoids expansion entirely.

Non-recursive zip bombs eliminate this limitation by expanding in a single pass.


Non-Recursive Zip Bombs: The Overlap Trick

David Fifield’s 2019 paper A better zip bomb (USENIX WOOT 2019) introduced a construction that surpasses DEFLATE’s normal 1,032:1 compression ceiling without recursion. Instead of nesting archives, a non-recursive zip bomb overlaps files inside the container: a single compressed “kernel” of data is referenced by many local file headers. Each header points to the same compressed bytes, so the archive appears to contain many large files while the compressed payload remains tiny.

Output size grows quadratically with input size. A 10 MB non-recursive zip bomb expands to 281 TB, and a 46 MB Zip64 variant reaches 4.5 PB in a single round of decompression. The construction uses only DEFLATE and works with zip parsers that read the central directory before extracting files.

flowchart LR
    subgraph Archive["Non-recursive zip bomb (few hundred bytes to a few MB)"]
        CD["Central directory"]
        H1["Local header 1<br/>points to kernel"]
        H2["Local header 2<br/>points to same kernel"]
        H3["Local header N<br/>points to same kernel"]
        K["Compressed kernel<br/>(highly compressible data)"]
    end
    H1 --> K
    H2 --> K
    H3 --> K
    CD --> H1
    CD --> H2
    CD --> H3
    Archive -->|"single decompression"| OUT["Massive output<br/>(GB to PB)"]

Figure 1: Overlapping local file headers referencing a single compressed kernel, expanding into a large output in one decompression pass.

Because expansion occurs in one pass without recursion, any scanner that reads the central directory and unpacks each entry sequentially allocates memory or disk space for the entire aggregate output.


Why This Is Useful as a Defensive Honeypot

In web defense, zip bombs act as tarpits: they do not filter traffic or block volumetric attacks, but they impose resource penalties on automated scanners.

Christian Haschek’s 2017 write-up popularized serving GZIP bombs to vulnerability scanners. He compressed a 10 GB zero-filled file into a 10 MB payload and served it with Content-Encoding: gzip. Because browsers and HTTP clients automatically decompress GZIP, scanners attempting to inspect the body inflated the zeroes. In testing, major browsers and headless clients hung, exhausted available memory, or crashed.

A non-recursive ZIP bomb operates on the archive layer instead. When a scanner requests /backup.zip, /secrets.zip, or /.env.zip and receives a small zip bomb, it attempts extraction. Without strict extraction limits, the scanner exhausts its own memory or disk space rather than host resources.

This shifts the resource overhead of reconnaissance from the origin server back to the scanning client.


Endpoints Worth Trapping

Traps must target paths requested solely by automated scanners to avoid disrupting legitimate users or search engine crawlers.

Common reconnaissance paths from the logs include:

CategoryExample paths from my logsWhy scanners probe them
Environment files/.env, /.env.production, /.env.local, /.env.bak, /.env.old, /.env.openai, /.env.anthropicLeaked database passwords, API keys, LLM provider keys
Git metadata/.git/config, /.git/index, /.git/logs/HEAD, /.git-credentialsSource code, commit history, embedded credentials
Cloud credentials/.aws/credentials, /.aws/credentials.bak, /.boto, /aws-exports.jsAWS access keys, S3 bucket names, IAM misconfigurations
WordPress/wp-config.php, /wp-config.php.bak, /wp-login.php, /xmlrpc.php, /wp-content/debug.logAdmin takeover, database credentials, RCE
PHP / framework/phpinfo.php, /config.php, /settings.php, /vendor/composer/installed.json, /actuator/env, /server-statusDebug info, dependency versions, Spring Boot actuator leaks
Backups & dumps/backup.sql, /database.sql, /secrets.json, /auth.json, /credentialsFull database dumps, secret stores
Editor / CI configs/.vscode/sftp.json, /sftp-config.json, /.gitlab-ci.yml, /.cursor/mcp.jsonSFTP passwords, CI secrets, MCP server tokens

Two rules apply:

  1. Never trap paths legitimate users or crawlers request. /robots.txt, /sitemap.xml, /favicon.ico, and genuine article URLs must always return normal responses.
  2. Leave security.txt untouched. Security researchers routinely check /.well-known/security.txt; returning a tarpit on this path interferes with responsible vulnerability disclosure.

The safest targets are non-existent, semantically private paths: .env, .git, .aws, database backups, and local editor configurations.


Static Sites vs Dynamic Sites

Deployment depends on whether the hosting environment provides a runtime.

Static Sites (Astro, VitePress, Hugo, Jekyll, plain HTML)

Static sites lack an application server, leaving two integration points:

1. Build-time honeypot generation. Tools like @itznotabug/vitepot emit decoy files during build. While VitePot focuses on fake content rather than zip bombs, it can pair with a custom build step that places pre-generated zip bombs at trap locations.

2. Edge middleware. If you host on Cloudflare Pages, Netlify Edge Functions, Vercel Edge Middleware, or Deno Deploy, you can intercept requests at the edge and return a zip bomb for specific paths. This approach keeps build outputs clean. An edge worker checks request.url and returns a Response with Content-Type: application/zip.

flowchart TD
    A[Scanner request] --> B{Path matches<br/>trap list?}
    B -->|No| C[Normal static asset<br/>or 404]
    B -->|Yes| D[Edge worker / middleware]
    D --> E[Return non-recursive<br/>zip bomb response]
    E --> F[Scanner decompresses<br/>and exhausts resources]

Figure 2: Edge middleware intercepting trap paths before requests reach origin storage.

For Astro sites, this can run as a Cloudflare Worker or Netlify Edge Function. On hosts without edge logic (such as GitHub Pages), build-time generation is the remaining option.

Dynamic Sites (Node, PHP, Python, Java, Ruby)

Dynamic environments intercept requests directly in middleware. The mleczakm/zip-bomb-honeypot package for Symfony implements this by trapping requests for .env, wp-admin, PHP shells, SQL dumps, and .aws/credentials using overlapping local headers.

The same pattern works in Express:

// Express middleware example (conceptual)
import { createZipBomb } from './zip-bomb-generator';

const TRAP_PATHS = [
  /^\/\.env/,
  /^\/\.git\//,
  /^\/\.aws\//,
  /^\/wp-config\.php/,
  /^\/wp-login\.php/,
  /^\/backup\.sql/,
  /^\/secrets\.json/,
];

app.use((req, res, next) => {
  if (TRAP_PATHS.some((re) => re.test(req.path))) {
    const bomb = createZipBomb(); // pre-generated, few hundred bytes
    res.set('Content-Type', 'application/zip');
    res.set('Content-Disposition', 'attachment; filename="backup.zip"');
    return res.status(200).send(bomb);
  }
  next();
});

Pre-generating the bomb once at startup avoids repeated compression overhead. Serving a cached static payload consumes minimal bandwidth while deflecting probe traffic.

sequenceDiagram
    participant S as Scanner
    participant M as Middleware
    participant A as Application
    S->>M: GET /.env
    M->>M: Path matches trap list
    M-->>S: 200 OK + zip bomb (300 bytes)
    S->>S: Attempts extraction
    S->>S: Allocates GB / TB
    Note over S: Scanner stalls or crashes
    S-->>M: (No further requests)

Figure 3: Dynamic middleware short-circuiting scanner requests before application routing.


Implementation Notes and Caveats

Generate payloads offline. Produce the zip bomb once and serve identical bytes for matching requests. The 42 KB zbsm.zip sample from bamsoftware expands to 5.5 GB, which is sufficient for a tarpit while remaining small enough to cache in memory.

Set expected headers. Use Content-Type: application/zip and descriptive filenames (backup.zip, secrets.zip, .env.zip). For browser-based tools that decode compression headers automatically, serving a GZIP bomb with Content-Encoding: gzip may trigger decompression faster.

Operational limits. A zip bomb does not disable an attacker’s host permanently. It exhausts temporary memory or disk space on unconstrained clients, but hardened tools often enforce decompression limits. Its function is to slow scanning down, not disable infrastructure. The video What Happens When You Open a Zip Bomb illustrates the practical effects: memory spikes, hangs, and crashes in some environments.

Legal considerations. Serving compressed payloads is a form of active defense. While protecting your own server is standard practice, attempting to cause harm to external systems can carry legal risks. A non-recursive zip bomb functions as a tarpit because it consumes only the resources the client chooses to allocate, but organizations operating in regulated environments should review their defense policies before deployment.

Crawler allowlists. Search engines respect robots.txt and do not request .env or .git/config. However, maintaining an allowlist for verified search crawler user agents provides an extra safeguard against misconfiguration.


Designing a Defensive Architecture

For static sites running on modern edge platforms like Cloudflare, a practical implementation strategy combines build-time traps with edge routing:

  1. Build-time decoys: A build script outputs fake files (such as sftp-config.json or .env.example) containing decoy credentials to stall basic scanners without requiring dynamic logic.
  2. Edge middleware tarpits: A Cloudflare Worker or edge function intercepts requests matching high-value trap patterns (/.env, /.git, /.aws, /wp-config.php, /backup.sql) and returns a pre-generated, 300-byte non-recursive zip bomb with a Content-Type: application/zip header before traffic reaches the origin.
  3. Telemetry and logging: Trapped requests record the source IP, user agent, and queried path to track ongoing reconnaissance patterns.

While an HTTP tarpit does not stop scanning immediately because automated bots crawl continuously, the resource trade-off changes: the edge server returns a lightweight cached response, leaving the scanner to handle the decompression burden.


References


Conclusion

Automated scanning remains a constant baseline across public web infrastructure. Non-recursive zip bombs provide a lightweight mechanism to shift the resource cost back onto scanners probing for private credentials and exposed configurations. Restricting traps strictly to non-existent, sensitive paths limits risk to legitimate visitors while imposing costs on unconstrained bots.

See also

#see-also
IMAGE Zoom View
100%
Pinch to zoom · Drag to pan · Double-tap to toggle