Skip to content

Getting started

Start with one upload route and one clear decision: inspect first, store later.

Pompelmi is most useful when you treat uploaded files as untrusted input and make a policy decision before persistence or downstream parsing.

If you want the wider architecture first, read Secure file uploads in Node.js: Beyond Extension and MIME Checks before picking a framework-specific path.

  • Want to inspect the verdict UX without sending a file anywhere? Open the browser preview.
  • Want a real route with a form and JSON response? Run the Express demo.
  • Want the broader example set first? Start with the examples index.
Terminal window
npm install pompelmi

That is enough to scan bytes locally. Framework adapters are optional.

import { readFileSync } from 'node:fs';
import { scanBytes, STRICT_PUBLIC_UPLOAD } from 'pompelmi';
const bytes = readFileSync('./package.json');
const report = await scanBytes(bytes, {
filename: 'package.json',
mimeType: 'application/json',
policy: STRICT_PUBLIC_UPLOAD,
failClosed: true,
});
console.log(report.verdict);
console.log(report.reasons);
VerdictMeaningTypical action
cleanNo blocking indicators from the configured checksContinue to storage or downstream processing
suspiciousSomething risky was detected, but not necessarily confirmed malwareQuarantine, manual review, or reject
maliciousHigh-confidence match or a policy condition you treat as maliciousReject and investigate

Built-in policy packs cover common starting points:

PolicyBest for
STRICT_PUBLIC_UPLOADPublic or semi-trusted upload endpoints
CONSERVATIVE_DEFAULTBalanced default for most server-side upload flows
DOCUMENTS_ONLYPDF and Office-oriented intake portals
IMAGES_ONLYAvatar, gallery, and image-only routes
ARCHIVESZIP-heavy endpoints when paired with archive guards

For archive handling, pair the policy with createZipBombGuard() and CommonHeuristicsScanner:

import { composeScanners, createZipBombGuard, CommonHeuristicsScanner } from 'pompelmi';
const scanner = composeScanners(
[
['zipGuard', createZipBombGuard()],
['heuristics', CommonHeuristicsScanner],
],
{ stopOn: 'suspicious' }
);

The most common safe sequence is:

  1. Receive the upload into memory or an isolated temp area.
  2. Scan bytes and archive structure.
  3. Reject malicious files immediately.
  4. Quarantine suspicious files if you need review instead of hard blocking.
  5. Persist only the files your application is ready to trust.