Skip to content

Pompelmi Commands

Comprehensive Pompelmi file upload security scanning commands for Node.js application protection.

Installation

CommandDescription
npm install pompelmiInstall Pompelmi via npm
yarn add pompelmiInstall Pompelmi via Yarn
pnpm add pompelmiInstall Pompelmi via pnpm
bun add pompelmiInstall Pompelmi via Bun

Basic Setup (Express)

const express = require('express');
const { createScanner } = require('pompelmi');

const app = express();
const scanner = createScanner({
  maxFileSize: '10mb',
  allowedExtensions: ['.pdf', '.png', '.jpg', '.docx'],
});

app.post('/upload', scanner.middleware(), (req, res) => {
  res.json({ files: req.files });
});

Framework Adapters

FrameworkDescription
pompelmi/expressExpress.js middleware adapter
pompelmi/koaKoa middleware adapter
pompelmi/nextNext.js API route adapter
pompelmi/nitroNuxt/Nitro adapter
pompelmi/fastifyFastify plugin adapter

Scanner Configuration

OptionDescription
maxFileSize: '10mb'Maximum allowed file size
allowedExtensions: ['.pdf', '.png']Whitelist of allowed file extensions
blockedExtensions: ['.exe', '.bat']Blacklist of blocked extensions
allowedMimeTypes: ['image/png']Whitelist of allowed MIME types
scanTimeout: 30000Scan timeout in milliseconds
tempDir: '/tmp/pompelmi'Temporary directory for scanning
preserveOriginalName: trueKeep original filename

YARA Integration

OptionDescription
yara: { enabled: true }Enable YARA rule scanning
yara: { rules: './rules/' }Path to custom YARA rules directory
yara: { builtinRules: true }Use built-in malware detection rules
yara: { timeout: 10000 }YARA scan timeout
Custom YARA rules fileWrite .yar files for custom detection

Archive Protection

OptionDescription
archive: { enabled: true }Enable archive inspection
archive: { maxDepth: 3 }Maximum recursion depth for nested archives
archive: { maxFiles: 100 }Maximum files inside archive
archive: { maxRatio: 100 }Max compression ratio (zip bomb protection)
archive: { maxSize: '100mb' }Max total extracted size
archive: { formats: ['zip', 'tar', 'gz'] }Supported archive formats

Security Policies

PolicyDescription
policy: 'strict'Block anything suspicious (recommended)
policy: 'moderate'Block known malware, warn on suspicious
policy: 'permissive'Only block confirmed malware
Custom policy functionDefine your own accept/reject logic

MIME Type Validation

CheckDescription
Extension validationCheck file extension against allowlist
Magic byte detectionVerify file type by content bytes
MIME type verificationServer-side MIME type checking
Double extension detectionCatch file.pdf.exe tricks
Null byte detectionBlock null byte injection in filenames
Content-Type mismatchDetect extension/content mismatches

Event Hooks

EventDescription
scanner.on('scan:start', fn)Fired when scan begins
scanner.on('scan:complete', fn)Fired when scan finishes
scanner.on('scan:reject', fn)Fired when file is rejected
scanner.on('scan:accept', fn)Fired when file passes all checks
scanner.on('scan:error', fn)Fired on scanning error
scanner.on('yara:match', fn)Fired when YARA rule matches

Scan Results

PropertyDescription
result.safeBoolean: file passed all checks
result.threatsArray of detected threats
result.mimeTypeDetected MIME type
result.extensionFile extension
result.sizeFile size in bytes
result.hashSHA-256 hash of file
result.scanTimeTime taken to scan (ms)
result.yaraMatchesYARA rule matches (if enabled)

Express Middleware Example

const { createScanner } = require('pompelmi');

const scanner = createScanner({
  maxFileSize: '5mb',
  allowedExtensions: ['.pdf', '.png', '.jpg'],
  yara: { enabled: true, builtinRules: true },
  archive: { enabled: true, maxDepth: 2 },
  policy: 'strict',
});

// As middleware
app.post('/upload', scanner.middleware(), handleUpload);

// Manual scanning
app.post('/upload', async (req, res) => {
  const result = await scanner.scan(req.file.buffer, {
    filename: req.file.originalname,
  });

  if (!result.safe) {
    return res.status(400).json({
      error: 'File rejected',
      threats: result.threats,
    });
  }

  // Process safe file...
});

Koa Adapter Example

const { createScanner } = require('pompelmi/koa');

const scanner = createScanner({
  maxFileSize: '10mb',
  allowedMimeTypes: ['application/pdf', 'image/*'],
});

router.post('/upload', scanner.middleware(), async (ctx) => {
  ctx.body = { files: ctx.request.files };
});

Next.js API Route Example

import { createScanner } from 'pompelmi/next';

const scanner = createScanner({
  maxFileSize: '5mb',
  allowedExtensions: ['.pdf', '.png'],
});

export default scanner.handler(async (req, res) => {
  const files = req.files;
  res.json({ uploaded: files.length });
});

CLI Scanning

CommandDescription
npx pompelmi scan <file>Scan a single file
npx pompelmi scan ./uploads/Scan directory of files
npx pompelmi scan --yara <file>Scan with YARA rules
npx pompelmi scan --json <file>Output results as JSON
npx pompelmi rules listList available YARA rules
npx pompelmi rules updateUpdate built-in YARA rules

Tips and Best Practices

TipDescription
Use strict policy in productionReject anything suspicious
Enable YARA rulesDetect known malware signatures
Set archive limitsPrevent zip bombs and nested payloads
Validate MIME types server-sideDon’t trust client Content-Type
Check double extensionsBlock file.pdf.exe patterns
Set reasonable size limitsPrevent resource exhaustion
Scan in memoryAvoid writing untrusted files to disk
Monitor scan eventsLog and alert on rejections
Update YARA rules regularlyStay current with threat intelligence
Use allowlists over blocklistsWhitelisting is safer than blacklisting