npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-middleware-honeypot

v2.0.1

Published

A middleware that creates a honeypot system to detect and track potential malicious requests while providing fake responses to common attack vectors. It is designed to be used as a development tool to test and analyze the security of your application or h

Readme

Express Honeypot Middleware

Express middleware that acts as a honeypot: it logs suspicious traffic and serves ultra-realistic decoy responses for common probing routes (328 endpoints × 2 variants).

Features

  • On-the-fly generation — no mockup files on disk, each request gets a fresh timestamp/request_id
  • 328 endpoints with realistic tailored content (credentials, configs, API responses, login pages, phishing landings, etc.)
  • 2 variants: default (succinct but credible) and complete (rich, detailed)
  • Generator scriptbun run scripts/generate-mockups.ts to write files for debugging
  • Traffic logging — JSON-lines format, on-demand bot extraction via /newBotsRoute
  • PHP spoofing — proxies *.php requests to localhost for real responses
  • Composable APIcreateHoneypot() returns { mocks, phpSpoofer, notFoundHandler, register, ... }
  • Backward-compatcreateHoneypot(app, options) auto-registers

Installation

npm install express-middleware-honeypot

Basic Usage

With register() (auto-registers all routes)

const express = require("express");
const { createHoneypot } = require("express-middleware-honeypot");

const app = express();

const instance = createHoneypot({
    knownPaths: ["/", "/login", "/support"],
    knownPatterns: [/^\/blogs\/[^/]+$/],
    knownApiPaths: ["/api/cart", "/api/cart/list"],
    knownApiPatterns: [/^\/api\/cart\/[^/]+$/],
    logTraffic: true,
    is404Handler: true,
    isCompleteResponses: false,
});

instance.register(app);

app.listen(3000, () => {
    console.log("Server running on port 3000");
});

With app.use() (single catch-all middleware)

const { createHoneypot } = require("express-middleware-honeypot");

const app = express();

// Your real routes first
app.get("/", (req, res) => res.send("Home"));

// Then the honeypot catch-all
const instance = createHoneypot({ /* options */ });
app.use(instance.middleware);
app.use(instance.phpSpoofer);

Individual mocks with app.all()

const instance = createHoneypot({ /* options */ });

// Register only specific endpoints
app.all('/admin', instance.mocks['/admin']);
app.all('/.env', instance.mocks['/.env']);
app.all('/wp-admin', instance.mocks['/wp-admin']);

instance.mocks is a Record<string, Middleware> keyed by endpoint path — pick the ones you want.

Custom headers

Middleware that sets realistic response headers — spoofs Server, X-Powered-By (dynamically chosen based on file extension), security headers:

app.use(instance.headersMiddleware);
app.use(instance.middleware);
  • .phpX-Powered-By: PHP/8.1.12
  • .jspX-Powered-By: JSP/3.0
  • .aspx/.ashx/.asmxX-Powered-By: ASP.NET
  • .do/.actionX-Powered-By: Servlet/3.0
  • other paths → no X-Powered-By header

PHP Spoofer

instance.phpSpoofer intercepts *.php requests and proxies them to your local dev server, returning real PHP-processed output instead of a static mock:

app.use(instance.phpSpoofer);

How it works:

  1. Catches requests with .php in the path (e.g. /wp-admin/setup-config.php)
  2. Strips the .php suffix and proxies to http://localhost:<port>/<base>
  3. If your local PHP server (Valet, Laravel, etc.) responds, the HTML is returned
  4. If the host is not localhost, it returns a hard 404 (prevents SSRF)
  5. No local PHP server? Falls through to your 404 handler

This lets you run a real WordPress/PHP app on localhost and have the honeypot serve real rendered pages to bots. For production or when no local PHP server is available, skip the phpSpoofer and the static .php mockups are used instead.

Shorthand (auto-registers)

createHoneypot(app, { knownPaths: [], ... });

Runtime Options

| Option | Type | Default | Description | |---|---|---|---| | knownPaths | string[] | [] | Paths handled by the real app (excluded from mockups) | | knownPatterns | RegExp[] | [] | Regex patterns for real app paths | | knownApiPaths | string[] | [] | API paths handled by the real app | | knownApiPatterns | RegExp[] | [] | Regex patterns for real API paths | | logTraffic | boolean | false | Log all traffic to traffic.txt | | is404Handler | boolean | false | Register a fallback 404 handler | | isCompleteResponses | boolean | false | Use the "complete" (rich detail) variant | | additionalEndpoints | string[] | ["/not_covered_endpoint_test"] | Extra endpoints to serve beyond the built-in 328 | | enrichResponses | boolean | true | Wrap JSON responses with timestamp/version fields |

Mockups

Mock content is generated on-the-fly by src/services/mockupGenerator.ts — no filesystem I/O at runtime. Each response receives a fresh timestamp and request_id, making every reply look like it came from a live server.

The generator covers 328 endpoints across two variants:

  • Default — succinct but believable ({ code: 0, message: "ok", data: {...} })
  • Complete — rich responses with timestamps, request IDs, meta, version headers, etc.

To write mockups to disk for debugging:

bun run scripts/generate-mockups.ts --dry-run   # preview only
bun run scripts/generate-mockups.ts --list-uncategorized  # show catchall endpoints

Content types served

| Type | Example endpoints | |---|---| | Credential leaks | .env, secrets.json, aws/credentials, etc/shadow | | SSH keys | .ssh/id_rsa, .ssh/id_ed25519 | | Database configs | config/database, wp-config.php, docker-compose.yml | | Admin panels | /admin, /wp-admin, /manage/account/login | | API responses | /api/version, /api/config, .do, .ashx | | Banking phishing | /lander/sber*, /index_sber.php, Russian bank landings | | C2 heartbeats | Random 6+ char paths (/262LBNFp, /Kd67Fq1x) | | Stock/crypto | /stock/mzhishu, /kline/1m/1, /m/allticker/1 | | Gambling/gaming | /proxy/games, /Ctrls/GetSysCoin, /room/getRoomBangFans | | Config files | config.json, config.yml, sitemap.xml, ads.txt | | Landing pages | /about, /contact, /products, /blog |

Analysis Endpoints

| Route | Description | |---|---| | GET /newBotsRoute | Returns unhandled unknown routes found in traffic logs | | GET /notCoveredAdditionalEndpoints | Returns additional endpoints not in the built-in 328 |

HoneypotInstance API

interface HoneypotInstance {
  mocks: Record<string, Middleware>;       // Individual mock handlers
  middleware: Middleware;                  // Single catch-all (use with app.use())
  headersMiddleware: Middleware;           // Sets realistic response headers
  phpSpoofer: Middleware;                  // PHP spoofing middleware
  notFoundHandler: Middleware;             // 404 fallback handler
  register(app: RouteApp): void;           // Register all handlers on an Express app
  getUnhandledRoutes(): Promise<string[]>; // Get unhandled bot routes
  getNotCoveredEndpoints(): string[];      // Get additional uncovered endpoints
}

Development

bun install
bun test          # 36+ tests
bun run build     # TypeScript → dist/

Security Note

This package is a honeypot/deception tool. Do not expose sensitive real data through your app while running it.

License

MIT