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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@pompelmi/express-middleware

v0.17.0

Published

Express middleware to scan uploads with pompelmi (YARA).

Readme

@pompelmi/express-middleware

Guard your Express upload routes with pompelmi — a local-first, no-cloud file pre‑quarantine that checks uploads before they touch your app logic or storage.

Privacy-first: no outbound calls. Scans run in-process.


Install

npm i pompelmi express multer
# or: pnpm add pompelmi express multer
# or: yarn add pompelmi express multer

60‑second Quickstart (TypeScript)

import express from "express";
import multer from "multer";
import { createUploadGuard } from "@pompelmi/express-middleware";
import {
  CommonHeuristicsScanner,
  createZipBombGuard,
  composeScanners,
} from "pompelmi";

// Policy (tweak to your needs)
const policy = {
  includeExtensions: ["zip", "png", "jpg", "jpeg", "pdf", "txt"],
  allowedMimeTypes: [
    "application/zip",
    "image/png",
    "image/jpeg",
    "application/pdf",
    "text/plain",
  ],
  maxFileSizeBytes: 20 * 1024 * 1024, // 20MB
  failClosed: true, // block on scanner/parse errors
};

// Compose scanners (stop as soon as something becomes suspicious)
const scanner = composeScanners(
  [
    [
      "zipGuard",
      createZipBombGuard({
        maxEntries: 512,
        maxTotalUncompressedBytes: 100 * 1024 * 1024,
        maxCompressionRatio: 12,
      }),
    ],
    ["heuristics", CommonHeuristicsScanner],
  ],
  { stopOn: "suspicious" }
);

const app = express();
const upload = multer({
  storage: multer.memoryStorage(),
  limits: { fileSize: policy.maxFileSizeBytes },
});

// Protect your upload route(s)
app.post(
  "/upload",
  upload.any(),
  createUploadGuard({ ...policy, scanner }),
  (req, res) => {
    // The guard attaches the scan result to the request
    const scan = (req as any).pompelmi ?? null;
    res.json({ ok: true, scan });
  }
);

app.listen(3000, () => console.log("Listening on http://localhost:3000"));

Try it quickly

Run the server and in another terminal:

# Clean file
curl -F [email protected] http://localhost:3000/upload | jq

# EICAR test (if you have it) – this should be flagged as suspicious/malicious
# Replace with your own path; the repo often ships a sample under tests/samples/
# curl -F file=@tests/samples/eicar.zip http://localhost:3000/upload | jq

You’ll receive JSON containing a per‑file decision plus any notes from scanners.


API

createUploadGuard(options)

Returns an Express middleware (req, res, next) that:

  • Parses the files already loaded by multer (buffer/stream)
  • Runs the configured scanners
  • Blocks the request on policy violations (size/type/zip bomb/etc.)
  • Attaches the full scan result to req.pompelmi

Options (forwarded to core + a few middleware specifics):

  • allowedMimeTypes: string[]
  • includeExtensions: string[]
  • maxFileSizeBytes: number
  • failClosed: boolean — if true, unexpected errors result in a block
  • scanner: Scanner — from composeScanners([...])
  • mapErrorToStatus?: (reason) => number — customize HTTP codes

Core option details live in the main docs: https://pompelmi.github.io/pompelmi/#configuration

Error handling & status codes

By default the middleware maps common cases to HTTP errors:

  • 413 – file too large
  • 415 – unsupported/blocked MIME type or extension
  • 422 – suspicious content (heuristics/YARA/zip guard)

Override via mapErrorToStatus to fit your API contract.

Accessing the scan result

app.post("/upload", upload.single("file"), createUploadGuard({ ...policy, scanner }), (req, res) => {
  const scan = (req as any).pompelmi; // { files: [...], summary: {...} }
  // Log, metrics, auditing, etc.
  res.json({ ok: true, scan });
});

Patterns

Multiple fields

app.post("/avatar", upload.single("avatar"), createUploadGuard({ ...policy, scanner }), handler)
app.post("/docs", upload.array("docs", 8), createUploadGuard({ ...policy, scanner }), handler)

Deny‑list a hot type (e.g., block scripts entirely):

const policy = {
  ...base,
  allowedMimeTypes: base.allowedMimeTypes.filter((m) => !m.startsWith("text/javascript")),
};

Troubleshooting

  • PayloadTooLargeError from multer – increase limits.fileSize and maxFileSizeBytes consistently.
  • Everything gets blocked – set failClosed: false temporarily and inspect req.pompelmi in logs.
  • ZIPs always suspicious – relax maxEntries / maxCompressionRatio in createZipBombGuard.

Typings

This package ships TypeScript types. The middleware augments Request at runtime via req.pompelmi (typed as any in the example; feel free to define your own interface extension in your codebase).


See also

  • Core library: pompelmi
  • Koa middleware: @pompelmi/koa-middleware
  • Next.js handler (App Router): @pompelmi/next-upload

License

MIT