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/koa-middleware

v0.17.0

Published

Koa middleware to scan uploads with pompelmi (YARA), MIME sniffing and ZIP anti-bomb.

Readme

@pompelmi/koa-middleware

Guard your Koa upload routes with pompelmi — a local‑first, no‑cloud pre‑quarantine that checks files before they reach your app logic or storage.

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


Install

npm i pompelmi koa @koa/router @koa/multer
# or: pnpm add pompelmi koa @koa/router @koa/multer
# or: yarn add pompelmi koa @koa/router @koa/multer

60‑second Quickstart (TypeScript)

import Koa from "koa";
import Router from "@koa/router";
import multer from "@koa/multer";
import { createKoaUploadGuard } from "@pompelmi/koa-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 = new Koa();
const router = new Router();
const upload = multer({
  storage: multer.memoryStorage(),
  limits: { fileSize: policy.maxFileSizeBytes },
});

router.post(
  "/upload",
  upload.any(),
  createKoaUploadGuard({ ...policy, scanner }),
  (ctx) => {
    const scan = (ctx as any).pompelmi ?? null;
    ctx.body = { ok: true, scan };
  }
);

app.use(router.routes()).use(router.allowedMethods());
app.listen(3003, () => console.log("http://localhost:3003"));

Try it quickly

Run the server and in another terminal:

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

# EICAR test (if present in your repo)
# curl -F file=@tests/samples/eicar.zip http://localhost:3003/upload | jq

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


API (brief)

createKoaUploadGuard(options)

Returns a Koa middleware that:

  • Reads files from @koa/multer buffers/streams
  • Runs the configured scanners
  • Blocks on policy violations (size/type/zip bomb/etc.)
  • Attaches the full scan result to ctx.pompelmi

Options (forwarded to core + a few Koa 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 used in your handler

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

Common statuses to return

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

Troubleshooting

  • Everything gets blocked – set failClosed: false temporarily and inspect ctx.pompelmi in logs.
  • LIMIT_FILE_SIZE from multer – increase both limits.fileSize and maxFileSizeBytes.
  • ZIPs always suspicious – relax Zip Guard (maxEntries / maxCompressionRatio).

See also

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

License

MIT