pompelmi 1.6.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,17 @@
19
19
 
20
20
  ---
21
21
 
22
+ ## Documentation
23
+
24
+ | Guide | Description |
25
+ |-------|-------------|
26
+ | [Getting Started](./docs/getting-started.md) | Installation, prerequisites, quickstart examples |
27
+ | [API Reference](./docs/api.md) | Full function signatures, options, verdicts, error conditions |
28
+ | [Docker / Remote Scanning](./docs/docker.md) | TCP sidecar, UNIX socket mount, docker-compose patterns |
29
+ | [GitHub Action](./docs/github-action.md) | CI scanning, inputs/outputs, caching, example workflows |
30
+
31
+ ---
32
+
22
33
  ## Overview
23
34
 
24
35
  pompelmi is a minimal Node.js wrapper around [ClamAV](https://www.clamav.net/) that exposes a single async function — `scan()` — and returns one of three typed verdict Symbols: `Verdict.Clean`, `Verdict.Malicious`, or `Verdict.ScanError`. Full documentation at [pompelmi.app](https://pompelmi.app).
@@ -265,23 +276,17 @@ if (result === Verdict.ScanError) console.warn('Scan incomplete.');
265
276
 
266
277
  Pass `host` and `port` (or `socket`) to switch from the local `clamscan` CLI to the clamd daemon. Everything else — the returned verdicts, error types — is identical.
267
278
 
268
- **TCP (Docker / remote clamd):**
279
+ **TCP:**
269
280
  ```js
270
- const result = await scan('/path/to/file.zip', {
271
- host: '127.0.0.1',
272
- port: 3310,
273
- timeout: 30_000, // socket idle timeout, ms — default 15 000
274
- });
281
+ const result = await scan('/path/to/file.zip', { host: '127.0.0.1', port: 3310 });
275
282
  ```
276
283
 
277
- **UNIX socket (local clamd daemon):**
284
+ **UNIX socket:**
278
285
  ```js
279
- const result = await scan('/path/to/file.zip', {
280
- socket: '/run/clamav/clamd.sock', // path to clamd's UNIX domain socket
281
- });
286
+ const result = await scan('/path/to/file.zip', { socket: '/run/clamav/clamd.sock' });
282
287
  ```
283
288
 
284
- pompelmi uses the ClamAV `INSTREAM` protocol: the file is streamed in 64 KB chunks, each prefixed with a 4-byte big-endian length header, terminated by four zero bytes. The response line (`stream: OK`, `stream: <name> FOUND`, or an error) is mapped to the same verdict Symbols.
289
+ See **[docs/docker.md](./docs/docker.md)** for Docker Compose examples, UNIX socket volume mounts, `scanBuffer` / `scanStream` in clamd mode, and connection retry patterns.
285
290
 
286
291
  ---
287
292
 
@@ -302,155 +307,24 @@ When none of `socket`, `host`, or `port` is provided, pompelmi spawns `clamscan
302
307
 
303
308
  ## API Reference
304
309
 
305
- ### `scan(filePath, [options])`
306
-
307
- ```ts
308
- scan(
309
- filePath: string,
310
- options?: { socket?: string; host?: string; port?: number; timeout?: number }
311
- ): Promise<symbol>
312
- ```
313
-
314
- **Returns** a Promise that resolves to one of:
315
-
316
- | Verdict | ClamAV exit code / response | Meaning |
317
- |---------------------|-----------------------------|-------------------------------------------------------------------------|
318
- | `Verdict.Clean` | `0` / `stream: OK` | No threats found. |
319
- | `Verdict.Malicious` | `1` / `<name> FOUND` | A known virus or malware signature was matched. |
320
- | `Verdict.ScanError` | `2` / other response | Scan failed — I/O error, encrypted archive, permission denied. Treat file as untrusted. |
321
-
322
- **Rejects** with an `Error` in these cases:
323
-
324
- | Condition | Error message |
325
- |---------------------------------------|-----------------------------------|
326
- | `filePath` is not a string | `filePath must be a string` |
327
- | File does not exist | `File not found: <path>` |
328
- | `clamscan` not in PATH | `ENOENT` (from the OS) |
329
- | ClamAV returns an unknown exit code | `Unexpected exit code: N` |
330
- | Process killed by signal | `Process killed by signal: <SIG>` |
331
- | clamd connection timed out | `clamd connection timed out after Nms` |
332
-
333
- Each `Verdict` Symbol exposes a `.description` property for safe serialisation:
334
-
335
- ```js
336
- Verdict.Clean.description // 'Clean'
337
- Verdict.Malicious.description // 'Malicious'
338
- Verdict.ScanError.description // 'ScanError'
339
- ```
340
-
341
- ---
342
-
343
- ### `scanBuffer(buffer, [options])`
310
+ See **[docs/api.md](./docs/api.md)** for the full reference: function signatures, options table, verdict Symbols, error conditions, and error handling patterns.
344
311
 
345
- ```ts
346
- scanBuffer(
347
- buffer: Buffer,
348
- options?: { socket?: string; host?: string; port?: number; timeout?: number }
349
- ): Promise<symbol>
350
- ```
351
-
352
- | Parameter | Type | Description |
353
- |---|---|---|
354
- | `buffer` | `Buffer` | The in-memory buffer to scan |
355
- | `options` | `object` | Same options as `scan()` — socket, host, port, timeout |
356
-
357
- **Returns** the same three Symbol verdicts as `scan()`: `Verdict.Clean`, `Verdict.Malicious`, `Verdict.ScanError`.
312
+ **Quick summary:**
358
313
 
359
- **Rejects** with the same error types as `scan()` where applicable, plus:
314
+ | Function | Input | clamd mode disk I/O |
315
+ |----------|-------|---------------------|
316
+ | `scan(filePath, [options])` | File path on disk | None (streamed) |
317
+ | `scanBuffer(buffer, [options])` | `Buffer` | None (streamed) |
318
+ | `scanStream(stream, [options])` | Node.js `Readable` | None (streamed) |
319
+ | `scanDirectory(dirPath, [options])` | Directory path | None (streamed) |
360
320
 
361
- | Condition | Error message |
362
- |---|---|
363
- | `buffer` is not a Buffer | `buffer must be a Buffer` |
364
- | `buffer` is empty | `buffer is empty` |
321
+ All four functions accept the same `options` object and resolve to the same three verdict Symbols:
365
322
 
366
- In clamd mode (`socket`, `host`, or `port` provided), the buffer is streamed directly to clamd via the INSTREAM protocol — no data is written to disk. In local mode, a temp file is written to `os.tmpdir()` and deleted automatically in a `finally` block regardless of outcome.
367
-
368
- ---
369
-
370
- ### `scanStream(stream, [options])`
371
-
372
- ```ts
373
- scanStream(
374
- stream: Readable,
375
- options?: { socket?: string; host?: string; port?: number; timeout?: number }
376
- ): Promise<symbol>
377
- ```
378
-
379
- | Parameter | Type | Description |
380
- |---|---|---|
381
- | `stream` | `Readable` | Node.js Readable stream to scan |
382
- | `options` | `object` | Same options as `scan()` — socket, host, port, timeout |
383
-
384
- **Returns** the same three Symbol verdicts as `scan()`: `Verdict.Clean`, `Verdict.Malicious`, `Verdict.ScanError`.
385
-
386
- **Rejects** with the same error types as `scan()` where applicable, plus:
387
-
388
- | Condition | Error message |
389
- |---|---|
390
- | `stream` is not a Readable | `stream must be a Readable` |
391
- | Stream emits error | propagated as-is |
392
-
393
- In clamd mode (`socket`, `host`, or `port` provided), the stream is piped directly to clamd via the INSTREAM protocol — no data is written to disk. In local mode, the stream is piped to a temp file in `os.tmpdir()` that is deleted automatically in a `finally` block.
394
-
395
- ---
396
-
397
- ### `scanDirectory(dirPath, [options])`
398
-
399
- ```ts
400
- scanDirectory(
401
- dirPath: string,
402
- options?: { socket?: string; host?: string; port?: number; timeout?: number }
403
- ): Promise<{ clean: string[], malicious: string[], errors: string[] }>
404
- ```
405
-
406
- Recursively scans every file in `dirPath` and returns three arrays of absolute paths.
407
-
408
- | Field | Type | Description |
409
- |---|---|---|
410
- | `clean` | `string[]` | Paths of files with no threats found |
411
- | `malicious` | `string[]` | Paths of files with a matched signature |
412
- | `errors` | `string[]` | Paths of files that could not be scanned |
413
-
414
- Per-file scan failures are caught and collected into `errors` — the function never throws because of an individual file.
415
-
416
- **Rejects** with an `Error` in these cases:
417
-
418
- | Condition | Error message |
419
- |---|---|
420
- | `dirPath` is not a string | `dirPath must be a string` |
421
- | Directory does not exist | `Directory not found: <path>` |
422
-
423
- ---
424
-
425
- ### `ClamAVInstaller()` _(internal)_
426
-
427
- Installs ClamAV using the platform's native package manager. Resolves immediately if ClamAV is already installed.
428
-
429
- ```ts
430
- ClamAVInstaller(): Promise<string>
431
- ```
432
-
433
- | Platform | Package manager | Command |
434
- |----------|-----------------|-------------------------------------------|
435
- | macOS | Homebrew | `brew install clamav` |
436
- | Linux | apt-get | `sudo apt-get install -y clamav clamav-daemon` |
437
- | Windows | Chocolatey | `choco install clamav -y` |
438
-
439
- ---
440
-
441
- ### `updateClamAVDatabase()` _(internal)_
442
-
443
- Runs `freshclam` to download or refresh the virus definition database. Skips if the database file is already present.
444
-
445
- ```ts
446
- updateClamAVDatabase(): Promise<string>
447
- ```
448
-
449
- | Platform | Database path |
450
- |----------|---------------------------------------|
451
- | macOS | `/usr/local/share/clamav/main.cvd` |
452
- | Linux | `/var/lib/clamav/main.cvd` |
453
- | Windows | `C:\ProgramData\ClamAV\main.cvd` |
323
+ | Symbol | Meaning |
324
+ |--------|---------|
325
+ | `Verdict.Clean` | No threats found |
326
+ | `Verdict.Malicious` | Known signature matched |
327
+ | `Verdict.ScanError` | Scan could not complete — treat as untrusted |
454
328
 
455
329
  ---
456
330
 
@@ -499,6 +373,56 @@ The [`examples/`](./examples/) directory contains standalone runnable scripts. E
499
373
 
500
374
  ---
501
375
 
376
+ ## GitHub Action
377
+
378
+ [![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Pompelmi%20ClamAV%20Scanner-blue?logo=github)](https://github.com/marketplace/actions/pompelmi-clamav-scanner)
379
+
380
+ Scan any repository for viruses on every push or pull request — ClamAV is bundled inside a Docker container, virus definitions are auto-updated at runtime, and no external services are required.
381
+
382
+ ### Minimal usage
383
+
384
+ ```yaml
385
+ - uses: actions/checkout@v4
386
+
387
+ - name: Virus scan
388
+ uses: pompelmi/pompelmi@v1.7.0
389
+ ```
390
+
391
+ ### Full example
392
+
393
+ ```yaml
394
+ - uses: actions/checkout@v4
395
+
396
+ - name: Virus scan
397
+ id: scan
398
+ uses: pompelmi/pompelmi@v1.7.0
399
+ with:
400
+ path: 'uploads/' # scan a subdirectory instead of the whole workspace
401
+ fail-on-virus: 'true' # fail the workflow step on detection (default)
402
+
403
+ - name: Print infected files
404
+ if: always()
405
+ run: echo "${{ steps.scan.outputs.infected-files }}"
406
+ ```
407
+
408
+ ### Inputs
409
+
410
+ | Input | Description | Default |
411
+ |-------|-------------|---------|
412
+ | `path` | Directory or file to scan | `.` (full workspace) |
413
+ | `fail-on-virus` | Fail the workflow step when infected files are found | `true` |
414
+
415
+ ### Outputs
416
+
417
+ | Output | Description |
418
+ |--------|-------------|
419
+ | `infected-files` | Newline-separated list of infected file paths (empty when clean) |
420
+ | `status` | `"clean"` or `"infected"` |
421
+
422
+ A ready-to-copy workflow is available at [`.github/workflows/action-example.yml`](./.github/workflows/action-example.yml). Full reference — inputs, outputs, layer caching, and more examples — in **[docs/github-action.md](./docs/github-action.md)**.
423
+
424
+ ---
425
+
502
426
  ## Contributing
503
427
 
504
428
  Full documentation and guides are available in the [Wiki](https://github.com/pompelmi/pompelmi/wiki).
@@ -0,0 +1,24 @@
1
+ FROM node:20-slim
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+
5
+ RUN apt-get update && \
6
+ apt-get install -y --no-install-recommends \
7
+ clamav \
8
+ clamav-freshclam \
9
+ && rm -rf /var/lib/apt/lists/* \
10
+ && sed -i 's/^Example/#Example/' /etc/clamav/freshclam.conf \
11
+ && mkdir -p /var/lib/clamav /run/clamav
12
+
13
+ WORKDIR /action
14
+
15
+ # Bundle the pompelmi library from this repository
16
+ COPY src/ ./src/
17
+ COPY package.json ./
18
+
19
+ # Action scripts
20
+ COPY action/entrypoint.sh ./entrypoint.sh
21
+ COPY action/scanner.js ./scanner.js
22
+ RUN chmod +x ./entrypoint.sh
23
+
24
+ ENTRYPOINT ["/action/entrypoint.sh"]
@@ -0,0 +1,23 @@
1
+ #!/bin/sh
2
+ set -e
3
+
4
+ SCAN_PATH="${1:-.}"
5
+ FAIL_ON_VIRUS="${2:-true}"
6
+
7
+ # Resolve relative paths against the GitHub workspace mount point
8
+ WORKSPACE="${GITHUB_WORKSPACE:-/github/workspace}"
9
+ case "$SCAN_PATH" in
10
+ /*) FULL_PATH="$SCAN_PATH" ;;
11
+ *) FULL_PATH="${WORKSPACE}/${SCAN_PATH}" ;;
12
+ esac
13
+
14
+ echo "::group::Updating ClamAV virus definitions (freshclam)"
15
+ # Remove any stale lock left from previous container runs
16
+ rm -f /run/clamav/freshclam.pid /run/lock/freshclam 2>/dev/null || true
17
+ freshclam --quiet 2>&1 \
18
+ && echo "Definitions updated successfully." \
19
+ || echo "Warning: freshclam update failed — scanning with cached definitions."
20
+ echo "::endgroup::"
21
+
22
+ echo "Scanning: ${FULL_PATH}"
23
+ exec node /action/scanner.js "${FULL_PATH}" "${FAIL_ON_VIRUS}"
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { scan, scanDirectory, Verdict } = require('./src/index.js');
6
+
7
+ const scanPath = process.argv[2] || '.';
8
+ const failOnVirus = process.argv[3] !== 'false';
9
+
10
+ async function main() {
11
+ const resolved = path.resolve(scanPath);
12
+
13
+ if (!fs.existsSync(resolved)) {
14
+ console.error(`::error::Path not found: ${resolved}`);
15
+ process.exit(2);
16
+ }
17
+
18
+ let clean = [], malicious = [], errors = [];
19
+ const stat = fs.statSync(resolved);
20
+
21
+ if (stat.isDirectory()) {
22
+ const result = await scanDirectory(resolved);
23
+ clean = result.clean;
24
+ malicious = result.malicious;
25
+ errors = result.errors;
26
+ } else {
27
+ const verdict = await scan(resolved);
28
+ if (verdict === Verdict.Clean) clean.push(resolved);
29
+ else if (verdict === Verdict.Malicious) malicious.push(resolved);
30
+ else errors.push(resolved);
31
+ }
32
+
33
+ const total = clean.length + malicious.length + errors.length;
34
+ const status = malicious.length > 0 ? 'infected' : 'clean';
35
+
36
+ // --- GitHub outputs ---
37
+ const outputFile = process.env.GITHUB_OUTPUT;
38
+ if (outputFile) {
39
+ const lines = [
40
+ `status=${status}`,
41
+ `infected-files<<POMPELMI_EOF`,
42
+ malicious.join('\n'),
43
+ `POMPELMI_EOF`,
44
+ ].join('\n') + '\n';
45
+ fs.appendFileSync(outputFile, lines);
46
+ }
47
+
48
+ // --- Job summary ---
49
+ const summaryFile = process.env.GITHUB_STEP_SUMMARY;
50
+ if (summaryFile) {
51
+ const icon = status === 'clean' ? '✅' : '❌';
52
+ const rows = [
53
+ `## ${icon} ClamAV Scan Results`,
54
+ '',
55
+ `| Metric | Count |`,
56
+ `|--------|-------|`,
57
+ `| Files scanned | ${total} |`,
58
+ `| Clean | ${clean.length} |`,
59
+ `| Infected | **${malicious.length}** |`,
60
+ `| Errors | ${errors.length} |`,
61
+ ];
62
+ if (malicious.length > 0) {
63
+ rows.push('', '### Infected Files', '');
64
+ malicious.forEach(f => rows.push(`- \`${f}\``));
65
+ }
66
+ fs.appendFileSync(summaryFile, rows.join('\n') + '\n');
67
+ }
68
+
69
+ // --- Console ---
70
+ console.log(`\nScan complete — ${total} file(s) scanned`);
71
+ console.log(` Clean: ${clean.length}`);
72
+ console.log(` Infected: ${malicious.length}`);
73
+ console.log(` Errors: ${errors.length}`);
74
+ console.log(` Status: ${status.toUpperCase()}`);
75
+
76
+ if (malicious.length > 0) {
77
+ console.error('\nInfected files:');
78
+ malicious.forEach(f => console.error(` ${f}`));
79
+ if (failOnVirus) {
80
+ console.error('\n::error::Virus(es) detected — failing workflow.');
81
+ process.exit(1);
82
+ }
83
+ }
84
+ }
85
+
86
+ main().catch(err => {
87
+ console.error(`::error::Scanner crashed: ${err.message}`);
88
+ process.exit(2);
89
+ });
package/action.yml ADDED
@@ -0,0 +1,29 @@
1
+ name: 'Pompelmi ClamAV Scanner'
2
+ description: 'Scan for viruses with ClamAV (bundled) — no daemon, no cloud, zero external dependencies'
3
+ author: 'pompelmi'
4
+ branding:
5
+ icon: 'shield'
6
+ color: 'orange'
7
+
8
+ inputs:
9
+ path:
10
+ description: 'Directory or file to scan (default: full workspace)'
11
+ required: false
12
+ default: '.'
13
+ fail-on-virus:
14
+ description: 'Fail the workflow step when infected files are found'
15
+ required: false
16
+ default: 'true'
17
+
18
+ outputs:
19
+ infected-files:
20
+ description: 'Newline-separated list of infected file paths (empty when clean)'
21
+ status:
22
+ description: '"clean" or "infected"'
23
+
24
+ runs:
25
+ using: 'docker'
26
+ image: './action/Dockerfile'
27
+ args:
28
+ - ${{ inputs.path }}
29
+ - ${{ inputs.fail-on-virus }}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pompelmi",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "ClamAV for humans — scan any file and get back Clean, Malicious, or ScanError. No daemons. No cloud. No native bindings.",
5
5
  "license": "ISC",
6
6
  "author": "pompelmi contributors",
package/pr_info.tmp ADDED
@@ -0,0 +1,2 @@
1
+ {"branch":null,"number":null,"url":null}
2
+ EOF