pompelmi 0.35.5 → 1.0.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/.claude/settings.local.json +40 -0
- package/LICENSE +12 -18
- package/README.md +159 -183
- package/eslint.config.mjs +8 -0
- package/package.json +26 -251
- package/src/ClamAVDatabaseUpdater.js +48 -0
- package/src/ClamAVInstaller.js +49 -0
- package/src/ClamAVScanner.js +31 -0
- package/src/InstallerCommand.js +11 -0
- package/src/config.js +22 -0
- package/src/constants.js +3 -0
- package/src/favicon.ico +0 -0
- package/src/grapefruit.png +0 -0
- package/src/index.js +5 -0
- package/CHANGELOG.md +0 -71
- package/dist/pompelmi.audit.cjs +0 -128
- package/dist/pompelmi.audit.cjs.map +0 -1
- package/dist/pompelmi.audit.esm.js +0 -107
- package/dist/pompelmi.audit.esm.js.map +0 -1
- package/dist/pompelmi.browser.cjs +0 -1549
- package/dist/pompelmi.browser.cjs.map +0 -1
- package/dist/pompelmi.browser.esm.js +0 -1523
- package/dist/pompelmi.browser.esm.js.map +0 -1
- package/dist/pompelmi.cjs +0 -2591
- package/dist/pompelmi.cjs.map +0 -1
- package/dist/pompelmi.esm.js +0 -2525
- package/dist/pompelmi.esm.js.map +0 -1
- package/dist/pompelmi.hooks.cjs +0 -75
- package/dist/pompelmi.hooks.cjs.map +0 -1
- package/dist/pompelmi.hooks.esm.js +0 -72
- package/dist/pompelmi.hooks.esm.js.map +0 -1
- package/dist/pompelmi.policy-packs.cjs +0 -240
- package/dist/pompelmi.policy-packs.cjs.map +0 -1
- package/dist/pompelmi.policy-packs.esm.js +0 -232
- package/dist/pompelmi.policy-packs.esm.js.map +0 -1
- package/dist/pompelmi.quarantine.cjs +0 -317
- package/dist/pompelmi.quarantine.cjs.map +0 -1
- package/dist/pompelmi.quarantine.esm.js +0 -293
- package/dist/pompelmi.quarantine.esm.js.map +0 -1
- package/dist/pompelmi.react.cjs +0 -1580
- package/dist/pompelmi.react.cjs.map +0 -1
- package/dist/pompelmi.react.esm.js +0 -1553
- package/dist/pompelmi.react.esm.js.map +0 -1
- package/dist/types/audit.d.ts +0 -84
- package/dist/types/browser-index.d.ts +0 -29
- package/dist/types/config.d.ts +0 -143
- package/dist/types/engines/dynamic-taint.d.ts +0 -102
- package/dist/types/engines/hybrid-orchestrator.d.ts +0 -65
- package/dist/types/engines/hybrid-taint-integration.d.ts +0 -129
- package/dist/types/engines/taint-policies.d.ts +0 -84
- package/dist/types/hipaa-compliance.d.ts +0 -110
- package/dist/types/hooks.d.ts +0 -89
- package/dist/types/index.d.ts +0 -29
- package/dist/types/magic.d.ts +0 -7
- package/dist/types/node/scanDir.d.ts +0 -30
- package/dist/types/policy-packs.d.ts +0 -98
- package/dist/types/policy.d.ts +0 -12
- package/dist/types/presets.d.ts +0 -72
- package/dist/types/quarantine/index.d.ts +0 -18
- package/dist/types/quarantine/storage.d.ts +0 -77
- package/dist/types/quarantine/types.d.ts +0 -78
- package/dist/types/quarantine/workflow.d.ts +0 -97
- package/dist/types/react-index.d.ts +0 -13
- package/dist/types/risk.d.ts +0 -18
- package/dist/types/scan/remote.d.ts +0 -12
- package/dist/types/scan.d.ts +0 -17
- package/dist/types/scanners/common-heuristics.d.ts +0 -14
- package/dist/types/scanners/zip-bomb-guard.d.ts +0 -9
- package/dist/types/scanners/zipTraversalGuard.d.ts +0 -19
- package/dist/types/src/audit.d.ts +0 -84
- package/dist/types/src/browser-index.d.ts +0 -29
- package/dist/types/src/config.d.ts +0 -143
- package/dist/types/src/engines/dynamic-taint.d.ts +0 -102
- package/dist/types/src/engines/hybrid-orchestrator.d.ts +0 -65
- package/dist/types/src/engines/hybrid-taint-integration.d.ts +0 -129
- package/dist/types/src/engines/taint-policies.d.ts +0 -84
- package/dist/types/src/hipaa-compliance.d.ts +0 -110
- package/dist/types/src/hooks.d.ts +0 -89
- package/dist/types/src/index.d.ts +0 -29
- package/dist/types/src/magic.d.ts +0 -7
- package/dist/types/src/node/scanDir.d.ts +0 -30
- package/dist/types/src/policy-packs.d.ts +0 -98
- package/dist/types/src/policy.d.ts +0 -12
- package/dist/types/src/presets.d.ts +0 -72
- package/dist/types/src/quarantine/index.d.ts +0 -18
- package/dist/types/src/quarantine/storage.d.ts +0 -77
- package/dist/types/src/quarantine/types.d.ts +0 -78
- package/dist/types/src/quarantine/workflow.d.ts +0 -97
- package/dist/types/src/react-index.d.ts +0 -13
- package/dist/types/src/risk.d.ts +0 -18
- package/dist/types/src/scan/remote.d.ts +0 -12
- package/dist/types/src/scan.d.ts +0 -17
- package/dist/types/src/scanners/common-heuristics.d.ts +0 -14
- package/dist/types/src/scanners/zip-bomb-guard.d.ts +0 -11
- package/dist/types/src/scanners/zipTraversalGuard.d.ts +0 -19
- package/dist/types/src/stream.d.ts +0 -10
- package/dist/types/src/types/decompilation.d.ts +0 -96
- package/dist/types/src/types/taint-tracking.d.ts +0 -495
- package/dist/types/src/types.d.ts +0 -48
- package/dist/types/src/useFileScanner.d.ts +0 -15
- package/dist/types/src/utils/advanced-detection.d.ts +0 -21
- package/dist/types/src/utils/batch-scanner.d.ts +0 -62
- package/dist/types/src/utils/cache-manager.d.ts +0 -95
- package/dist/types/src/utils/export.d.ts +0 -51
- package/dist/types/src/utils/performance-metrics.d.ts +0 -68
- package/dist/types/src/utils/threat-intelligence.d.ts +0 -96
- package/dist/types/src/validate.d.ts +0 -7
- package/dist/types/src/verdict.d.ts +0 -2
- package/dist/types/src/yara/browser.d.ts +0 -7
- package/dist/types/src/yara/index.d.ts +0 -17
- package/dist/types/src/yara/node.d.ts +0 -2
- package/dist/types/src/yara/remote.d.ts +0 -10
- package/dist/types/src/yara-bridge.d.ts +0 -3
- package/dist/types/src/zip.d.ts +0 -13
- package/dist/types/stream.d.ts +0 -10
- package/dist/types/types/decompilation.d.ts +0 -96
- package/dist/types/types/taint-tracking.d.ts +0 -495
- package/dist/types/types.d.ts +0 -48
- package/dist/types/useFileScanner.d.ts +0 -15
- package/dist/types/utils/advanced-detection.d.ts +0 -21
- package/dist/types/utils/batch-scanner.d.ts +0 -62
- package/dist/types/utils/cache-manager.d.ts +0 -95
- package/dist/types/utils/export.d.ts +0 -51
- package/dist/types/utils/performance-metrics.d.ts +0 -68
- package/dist/types/utils/threat-intelligence.d.ts +0 -96
- package/dist/types/validate.d.ts +0 -7
- package/dist/types/verdict.d.ts +0 -2
- package/dist/types/yara/browser.d.ts +0 -7
- package/dist/types/yara/index.d.ts +0 -17
- package/dist/types/yara/node.d.ts +0 -2
- package/dist/types/yara/remote.d.ts +0 -10
- package/dist/types/yara-bridge.d.ts +0 -3
- package/dist/types/zip.d.ts +0 -13
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const MB$1 = 1024 * 1024;
|
|
4
|
-
const DEFAULT_POLICY = {
|
|
5
|
-
includeExtensions: ["zip", "png", "jpg", "jpeg", "pdf"],
|
|
6
|
-
allowedMimeTypes: ["application/zip", "image/png", "image/jpeg", "application/pdf", "text/plain"],
|
|
7
|
-
maxFileSizeBytes: 20 * MB$1,
|
|
8
|
-
timeoutMs: 5000,
|
|
9
|
-
concurrency: 4,
|
|
10
|
-
failClosed: true,
|
|
11
|
-
};
|
|
12
|
-
function definePolicy(input = {}) {
|
|
13
|
-
const p = { ...DEFAULT_POLICY, ...input };
|
|
14
|
-
if (!Array.isArray(p.includeExtensions))
|
|
15
|
-
throw new TypeError("includeExtensions must be string[]");
|
|
16
|
-
if (!Array.isArray(p.allowedMimeTypes))
|
|
17
|
-
throw new TypeError("allowedMimeTypes must be string[]");
|
|
18
|
-
if (!(Number.isFinite(p.maxFileSizeBytes) && p.maxFileSizeBytes > 0))
|
|
19
|
-
throw new TypeError("maxFileSizeBytes must be > 0");
|
|
20
|
-
if (!(Number.isFinite(p.timeoutMs) && p.timeoutMs > 0))
|
|
21
|
-
throw new TypeError("timeoutMs must be > 0");
|
|
22
|
-
if (!(Number.isInteger(p.concurrency) && p.concurrency > 0))
|
|
23
|
-
throw new TypeError("concurrency must be > 0");
|
|
24
|
-
return p;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Policy packs for Pompelmi.
|
|
29
|
-
*
|
|
30
|
-
* Pre-configured, named policies for common upload scenarios. Each pack
|
|
31
|
-
* defines the file type allowlist, size limits, and timeout appropriate for
|
|
32
|
-
* its use case.
|
|
33
|
-
*
|
|
34
|
-
* All packs are built on `definePolicy` and are fully overridable:
|
|
35
|
-
*
|
|
36
|
-
* ```ts
|
|
37
|
-
* import { POLICY_PACKS } from 'pompelmi/policy-packs';
|
|
38
|
-
*
|
|
39
|
-
* // Use a pack as-is:
|
|
40
|
-
* const policy = POLICY_PACKS['images-only'];
|
|
41
|
-
*
|
|
42
|
-
* // Or override individual fields:
|
|
43
|
-
* import { definePolicy } from 'pompelmi';
|
|
44
|
-
* const custom = definePolicy({ ...POLICY_PACKS['documents-only'], maxFileSizeBytes: 5 * 1024 * 1024 });
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* These packs are *deterministic* and *descriptor-based* — they do not
|
|
48
|
-
* depend on any external threat intelligence feed.
|
|
49
|
-
*
|
|
50
|
-
* @module policy-packs
|
|
51
|
-
*/
|
|
52
|
-
const KB = 1024;
|
|
53
|
-
const MB = 1024 * KB;
|
|
54
|
-
// ── Policy packs ──────────────────────────────────────────────────────────────
|
|
55
|
-
/**
|
|
56
|
-
* Documents-only policy.
|
|
57
|
-
*
|
|
58
|
-
* Appropriate for: document management APIs, PDF/Office file upload endpoints,
|
|
59
|
-
* data import pipelines.
|
|
60
|
-
*
|
|
61
|
-
* Allowed: PDF, Word (.docx/.doc), Excel (.xlsx/.xls), PowerPoint (.pptx/.ppt),
|
|
62
|
-
* CSV, plain text, JSON, YAML, ODT/ODS/ODP (OpenDocument).
|
|
63
|
-
* Max size: 25 MB.
|
|
64
|
-
*/
|
|
65
|
-
const DOCUMENTS_ONLY = definePolicy({
|
|
66
|
-
includeExtensions: [
|
|
67
|
-
"pdf",
|
|
68
|
-
"doc",
|
|
69
|
-
"docx",
|
|
70
|
-
"xls",
|
|
71
|
-
"xlsx",
|
|
72
|
-
"ppt",
|
|
73
|
-
"pptx",
|
|
74
|
-
"odt",
|
|
75
|
-
"ods",
|
|
76
|
-
"odp",
|
|
77
|
-
"csv",
|
|
78
|
-
"txt",
|
|
79
|
-
"json",
|
|
80
|
-
"yaml",
|
|
81
|
-
"yml",
|
|
82
|
-
"md",
|
|
83
|
-
],
|
|
84
|
-
allowedMimeTypes: [
|
|
85
|
-
"application/pdf",
|
|
86
|
-
"application/msword",
|
|
87
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
88
|
-
"application/vnd.ms-excel",
|
|
89
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
90
|
-
"application/vnd.ms-powerpoint",
|
|
91
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
92
|
-
"application/vnd.oasis.opendocument.text",
|
|
93
|
-
"application/vnd.oasis.opendocument.spreadsheet",
|
|
94
|
-
"application/vnd.oasis.opendocument.presentation",
|
|
95
|
-
"text/csv",
|
|
96
|
-
"text/plain",
|
|
97
|
-
"application/json",
|
|
98
|
-
"text/yaml",
|
|
99
|
-
"text/markdown",
|
|
100
|
-
],
|
|
101
|
-
maxFileSizeBytes: 25 * MB,
|
|
102
|
-
timeoutMs: 10000,
|
|
103
|
-
concurrency: 4,
|
|
104
|
-
failClosed: true,
|
|
105
|
-
});
|
|
106
|
-
/**
|
|
107
|
-
* Images-only policy.
|
|
108
|
-
*
|
|
109
|
-
* Appropriate for: avatar uploads, product image APIs, content platforms with
|
|
110
|
-
* user-generated imagery.
|
|
111
|
-
*
|
|
112
|
-
* Allowed: JPEG, PNG, GIF, WebP, AVIF, TIFF, BMP, ICO.
|
|
113
|
-
* Max size: 10 MB.
|
|
114
|
-
* Note: SVG is intentionally excluded — inline SVGs can contain scripts.
|
|
115
|
-
*/
|
|
116
|
-
const IMAGES_ONLY = definePolicy({
|
|
117
|
-
includeExtensions: ["jpg", "jpeg", "png", "gif", "webp", "avif", "tiff", "tif", "bmp", "ico"],
|
|
118
|
-
allowedMimeTypes: [
|
|
119
|
-
"image/jpeg",
|
|
120
|
-
"image/png",
|
|
121
|
-
"image/gif",
|
|
122
|
-
"image/webp",
|
|
123
|
-
"image/avif",
|
|
124
|
-
"image/tiff",
|
|
125
|
-
"image/bmp",
|
|
126
|
-
"image/x-icon",
|
|
127
|
-
"image/vnd.microsoft.icon",
|
|
128
|
-
],
|
|
129
|
-
maxFileSizeBytes: 10 * MB,
|
|
130
|
-
timeoutMs: 5000,
|
|
131
|
-
concurrency: 8,
|
|
132
|
-
failClosed: true,
|
|
133
|
-
});
|
|
134
|
-
/**
|
|
135
|
-
* Strict public-upload policy.
|
|
136
|
-
*
|
|
137
|
-
* Appropriate for: anonymous or low-trust upload endpoints, public APIs,
|
|
138
|
-
* any surface exposed to untrusted users.
|
|
139
|
-
*
|
|
140
|
-
* Aggressive size limit (5 MB), short timeout, fail-closed, narrow MIME
|
|
141
|
-
* allowlist. Only allows plain images and PDF.
|
|
142
|
-
*/
|
|
143
|
-
const STRICT_PUBLIC_UPLOAD = definePolicy({
|
|
144
|
-
includeExtensions: ["jpg", "jpeg", "png", "webp", "pdf"],
|
|
145
|
-
allowedMimeTypes: ["image/jpeg", "image/png", "image/webp", "application/pdf"],
|
|
146
|
-
maxFileSizeBytes: 5 * MB,
|
|
147
|
-
timeoutMs: 4000,
|
|
148
|
-
concurrency: 2,
|
|
149
|
-
failClosed: true,
|
|
150
|
-
});
|
|
151
|
-
/**
|
|
152
|
-
* Conservative default policy.
|
|
153
|
-
*
|
|
154
|
-
* A hardened version of the built-in `DEFAULT_POLICY` suitable for
|
|
155
|
-
* production without further customisation. Stricter size limit and
|
|
156
|
-
* shorter timeout than the permissive default.
|
|
157
|
-
*/
|
|
158
|
-
const CONSERVATIVE_DEFAULT = definePolicy({
|
|
159
|
-
includeExtensions: ["zip", "png", "jpg", "jpeg", "pdf", "txt", "csv", "docx", "xlsx"],
|
|
160
|
-
allowedMimeTypes: [
|
|
161
|
-
"application/zip",
|
|
162
|
-
"image/png",
|
|
163
|
-
"image/jpeg",
|
|
164
|
-
"application/pdf",
|
|
165
|
-
"text/plain",
|
|
166
|
-
"text/csv",
|
|
167
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
168
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
169
|
-
],
|
|
170
|
-
maxFileSizeBytes: 10 * MB,
|
|
171
|
-
timeoutMs: 8000,
|
|
172
|
-
concurrency: 4,
|
|
173
|
-
failClosed: true,
|
|
174
|
-
});
|
|
175
|
-
/**
|
|
176
|
-
* Archives policy.
|
|
177
|
-
*
|
|
178
|
-
* Appropriate for: endpoints that accept ZIP, tar, or compressed archives.
|
|
179
|
-
* Combines a generous size allowance with a longer timeout for deep inspection.
|
|
180
|
-
*
|
|
181
|
-
* NOTE: Pair this policy with `createZipBombGuard()` to defend against
|
|
182
|
-
* decompression-bomb attacks:
|
|
183
|
-
*
|
|
184
|
-
* ```ts
|
|
185
|
-
* import { composeScanners, createZipBombGuard, CommonHeuristicsScanner } from 'pompelmi';
|
|
186
|
-
* const scanner = composeScanners(
|
|
187
|
-
* [['zipGuard', createZipBombGuard()], ['heuristics', CommonHeuristicsScanner]]
|
|
188
|
-
* );
|
|
189
|
-
* ```
|
|
190
|
-
*/
|
|
191
|
-
const ARCHIVES = definePolicy({
|
|
192
|
-
includeExtensions: ["zip", "tar", "gz", "tgz", "bz2", "xz", "7z", "rar"],
|
|
193
|
-
allowedMimeTypes: [
|
|
194
|
-
"application/zip",
|
|
195
|
-
"application/x-tar",
|
|
196
|
-
"application/gzip",
|
|
197
|
-
"application/x-bzip2",
|
|
198
|
-
"application/x-xz",
|
|
199
|
-
"application/x-7z-compressed",
|
|
200
|
-
"application/x-rar-compressed",
|
|
201
|
-
],
|
|
202
|
-
maxFileSizeBytes: 100 * MB,
|
|
203
|
-
timeoutMs: 30000,
|
|
204
|
-
concurrency: 2,
|
|
205
|
-
failClosed: true,
|
|
206
|
-
});
|
|
207
|
-
/**
|
|
208
|
-
* Named map of all built-in policy packs.
|
|
209
|
-
*
|
|
210
|
-
* ```ts
|
|
211
|
-
* import { POLICY_PACKS } from 'pompelmi/policy-packs';
|
|
212
|
-
* const policy = POLICY_PACKS['strict-public-upload'];
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
const POLICY_PACKS = {
|
|
216
|
-
"documents-only": DOCUMENTS_ONLY,
|
|
217
|
-
"images-only": IMAGES_ONLY,
|
|
218
|
-
"strict-public-upload": STRICT_PUBLIC_UPLOAD,
|
|
219
|
-
"conservative-default": CONSERVATIVE_DEFAULT,
|
|
220
|
-
archives: ARCHIVES,
|
|
221
|
-
};
|
|
222
|
-
/**
|
|
223
|
-
* Look up a policy pack by name.
|
|
224
|
-
* Throws if the name is not recognised.
|
|
225
|
-
*/
|
|
226
|
-
function getPolicyPack(name) {
|
|
227
|
-
const policy = POLICY_PACKS[name];
|
|
228
|
-
if (!policy)
|
|
229
|
-
throw new Error(`Unknown policy pack: '${name}'. Valid names: ${Object.keys(POLICY_PACKS).join(", ")}`);
|
|
230
|
-
return policy;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
exports.ARCHIVES = ARCHIVES;
|
|
234
|
-
exports.CONSERVATIVE_DEFAULT = CONSERVATIVE_DEFAULT;
|
|
235
|
-
exports.DOCUMENTS_ONLY = DOCUMENTS_ONLY;
|
|
236
|
-
exports.IMAGES_ONLY = IMAGES_ONLY;
|
|
237
|
-
exports.POLICY_PACKS = POLICY_PACKS;
|
|
238
|
-
exports.STRICT_PUBLIC_UPLOAD = STRICT_PUBLIC_UPLOAD;
|
|
239
|
-
exports.getPolicyPack = getPolicyPack;
|
|
240
|
-
//# sourceMappingURL=pompelmi.policy-packs.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pompelmi.policy-packs.cjs","sources":["../../src/policy.ts","../../src/policy-packs.ts"],"sourcesContent":["export interface Policy {\n includeExtensions: string[];\n allowedMimeTypes: string[];\n maxFileSizeBytes: number;\n timeoutMs: number;\n concurrency: number;\n failClosed: boolean;\n onScanEvent?: (ev: unknown) => void;\n}\nexport type PolicyInput = Partial<Policy>;\n\nconst MB = 1024 * 1024;\n\nexport const DEFAULT_POLICY: Policy = {\n includeExtensions: [\"zip\", \"png\", \"jpg\", \"jpeg\", \"pdf\"],\n allowedMimeTypes: [\"application/zip\", \"image/png\", \"image/jpeg\", \"application/pdf\", \"text/plain\"],\n maxFileSizeBytes: 20 * MB,\n timeoutMs: 5000,\n concurrency: 4,\n failClosed: true,\n};\n\nexport function definePolicy(input: PolicyInput = {}): Policy {\n const p: Policy = { ...DEFAULT_POLICY, ...input };\n if (!Array.isArray(p.includeExtensions))\n throw new TypeError(\"includeExtensions must be string[]\");\n if (!Array.isArray(p.allowedMimeTypes)) throw new TypeError(\"allowedMimeTypes must be string[]\");\n if (!(Number.isFinite(p.maxFileSizeBytes) && p.maxFileSizeBytes > 0))\n throw new TypeError(\"maxFileSizeBytes must be > 0\");\n if (!(Number.isFinite(p.timeoutMs) && p.timeoutMs > 0))\n throw new TypeError(\"timeoutMs must be > 0\");\n if (!(Number.isInteger(p.concurrency) && p.concurrency > 0))\n throw new TypeError(\"concurrency must be > 0\");\n return p;\n}\n","/**\n * Policy packs for Pompelmi.\n *\n * Pre-configured, named policies for common upload scenarios. Each pack\n * defines the file type allowlist, size limits, and timeout appropriate for\n * its use case.\n *\n * All packs are built on `definePolicy` and are fully overridable:\n *\n * ```ts\n * import { POLICY_PACKS } from 'pompelmi/policy-packs';\n *\n * // Use a pack as-is:\n * const policy = POLICY_PACKS['images-only'];\n *\n * // Or override individual fields:\n * import { definePolicy } from 'pompelmi';\n * const custom = definePolicy({ ...POLICY_PACKS['documents-only'], maxFileSizeBytes: 5 * 1024 * 1024 });\n * ```\n *\n * These packs are *deterministic* and *descriptor-based* — they do not\n * depend on any external threat intelligence feed.\n *\n * @module policy-packs\n */\n\nimport { definePolicy, type Policy } from \"./policy\";\n\nconst KB = 1024;\nconst MB = 1024 * KB;\n\n// ── Policy packs ──────────────────────────────────────────────────────────────\n\n/**\n * Documents-only policy.\n *\n * Appropriate for: document management APIs, PDF/Office file upload endpoints,\n * data import pipelines.\n *\n * Allowed: PDF, Word (.docx/.doc), Excel (.xlsx/.xls), PowerPoint (.pptx/.ppt),\n * CSV, plain text, JSON, YAML, ODT/ODS/ODP (OpenDocument).\n * Max size: 25 MB.\n */\nexport const DOCUMENTS_ONLY: Policy = definePolicy({\n includeExtensions: [\n \"pdf\",\n \"doc\",\n \"docx\",\n \"xls\",\n \"xlsx\",\n \"ppt\",\n \"pptx\",\n \"odt\",\n \"ods\",\n \"odp\",\n \"csv\",\n \"txt\",\n \"json\",\n \"yaml\",\n \"yml\",\n \"md\",\n ],\n allowedMimeTypes: [\n \"application/pdf\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.ms-excel\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"application/vnd.ms-powerpoint\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \"application/vnd.oasis.opendocument.text\",\n \"application/vnd.oasis.opendocument.spreadsheet\",\n \"application/vnd.oasis.opendocument.presentation\",\n \"text/csv\",\n \"text/plain\",\n \"application/json\",\n \"text/yaml\",\n \"text/markdown\",\n ],\n maxFileSizeBytes: 25 * MB,\n timeoutMs: 10_000,\n concurrency: 4,\n failClosed: true,\n});\n\n/**\n * Images-only policy.\n *\n * Appropriate for: avatar uploads, product image APIs, content platforms with\n * user-generated imagery.\n *\n * Allowed: JPEG, PNG, GIF, WebP, AVIF, TIFF, BMP, ICO.\n * Max size: 10 MB.\n * Note: SVG is intentionally excluded — inline SVGs can contain scripts.\n */\nexport const IMAGES_ONLY: Policy = definePolicy({\n includeExtensions: [\"jpg\", \"jpeg\", \"png\", \"gif\", \"webp\", \"avif\", \"tiff\", \"tif\", \"bmp\", \"ico\"],\n allowedMimeTypes: [\n \"image/jpeg\",\n \"image/png\",\n \"image/gif\",\n \"image/webp\",\n \"image/avif\",\n \"image/tiff\",\n \"image/bmp\",\n \"image/x-icon\",\n \"image/vnd.microsoft.icon\",\n ],\n maxFileSizeBytes: 10 * MB,\n timeoutMs: 5_000,\n concurrency: 8,\n failClosed: true,\n});\n\n/**\n * Strict public-upload policy.\n *\n * Appropriate for: anonymous or low-trust upload endpoints, public APIs,\n * any surface exposed to untrusted users.\n *\n * Aggressive size limit (5 MB), short timeout, fail-closed, narrow MIME\n * allowlist. Only allows plain images and PDF.\n */\nexport const STRICT_PUBLIC_UPLOAD: Policy = definePolicy({\n includeExtensions: [\"jpg\", \"jpeg\", \"png\", \"webp\", \"pdf\"],\n allowedMimeTypes: [\"image/jpeg\", \"image/png\", \"image/webp\", \"application/pdf\"],\n maxFileSizeBytes: 5 * MB,\n timeoutMs: 4_000,\n concurrency: 2,\n failClosed: true,\n});\n\n/**\n * Conservative default policy.\n *\n * A hardened version of the built-in `DEFAULT_POLICY` suitable for\n * production without further customisation. Stricter size limit and\n * shorter timeout than the permissive default.\n */\nexport const CONSERVATIVE_DEFAULT: Policy = definePolicy({\n includeExtensions: [\"zip\", \"png\", \"jpg\", \"jpeg\", \"pdf\", \"txt\", \"csv\", \"docx\", \"xlsx\"],\n allowedMimeTypes: [\n \"application/zip\",\n \"image/png\",\n \"image/jpeg\",\n \"application/pdf\",\n \"text/plain\",\n \"text/csv\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n ],\n maxFileSizeBytes: 10 * MB,\n timeoutMs: 8_000,\n concurrency: 4,\n failClosed: true,\n});\n\n/**\n * Archives policy.\n *\n * Appropriate for: endpoints that accept ZIP, tar, or compressed archives.\n * Combines a generous size allowance with a longer timeout for deep inspection.\n *\n * NOTE: Pair this policy with `createZipBombGuard()` to defend against\n * decompression-bomb attacks:\n *\n * ```ts\n * import { composeScanners, createZipBombGuard, CommonHeuristicsScanner } from 'pompelmi';\n * const scanner = composeScanners(\n * [['zipGuard', createZipBombGuard()], ['heuristics', CommonHeuristicsScanner]]\n * );\n * ```\n */\nexport const ARCHIVES: Policy = definePolicy({\n includeExtensions: [\"zip\", \"tar\", \"gz\", \"tgz\", \"bz2\", \"xz\", \"7z\", \"rar\"],\n allowedMimeTypes: [\n \"application/zip\",\n \"application/x-tar\",\n \"application/gzip\",\n \"application/x-bzip2\",\n \"application/x-xz\",\n \"application/x-7z-compressed\",\n \"application/x-rar-compressed\",\n ],\n maxFileSizeBytes: 100 * MB,\n timeoutMs: 30_000,\n concurrency: 2,\n failClosed: true,\n});\n\n// ── Named map ────────────────────────────────────────────────────────────────\n\nexport type PolicyPackName =\n | \"documents-only\"\n | \"images-only\"\n | \"strict-public-upload\"\n | \"conservative-default\"\n | \"archives\";\n\n/**\n * Named map of all built-in policy packs.\n *\n * ```ts\n * import { POLICY_PACKS } from 'pompelmi/policy-packs';\n * const policy = POLICY_PACKS['strict-public-upload'];\n * ```\n */\nexport const POLICY_PACKS: Record<PolicyPackName, Policy> = {\n \"documents-only\": DOCUMENTS_ONLY,\n \"images-only\": IMAGES_ONLY,\n \"strict-public-upload\": STRICT_PUBLIC_UPLOAD,\n \"conservative-default\": CONSERVATIVE_DEFAULT,\n archives: ARCHIVES,\n};\n\n/**\n * Look up a policy pack by name.\n * Throws if the name is not recognised.\n */\nexport function getPolicyPack(name: PolicyPackName): Policy {\n const policy = POLICY_PACKS[name];\n if (!policy)\n throw new Error(\n `Unknown policy pack: '${name}'. Valid names: ${Object.keys(POLICY_PACKS).join(\", \")}`,\n );\n return policy;\n}\n"],"names":["MB"],"mappings":";;AAWA,MAAMA,IAAE,GAAG,IAAI,GAAG,IAAI;AAEf,MAAM,cAAc,GAAW;IACpC,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,E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U,EAAE,IAAI;AACjB,CAAA;AAWD;;;;;;;AAOG;AACI,MAAM,YAAY,GAAmC;AAC1D,IAAA,gBAAgB,EAAE,cAAc;AAChC,IAAA,aAAa,EAAE,WAAW;AAC1B,IAAA,sBAAsB,EAAE,oBAAoB;AAC5C,IAAA,sBAAsB,EAAE,oBAAoB;AAC5C,IAAA,QAAQ,EAAE,QAAQ;;AAGpB;;;AAGG;AACG,SAAU,aAAa,CAAC,IAAoB,EAAA;AAChD,IAAA,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC;AACjC,IAAA,IAAI,CAAC,MAAM;AACT,QAAA,MAAM,IAAI,KAAK,CACb,yBAAyB,IAAI,CAAA,gBAAA,EAAmB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,CAAE,CACvF;AACH,IAAA,OAAO,MAAM;AACf;;;;;;;;;;"}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
const MB$1 = 1024 * 1024;
|
|
2
|
-
const DEFAULT_POLICY = {
|
|
3
|
-
includeExtensions: ["zip", "png", "jpg", "jpeg", "pdf"],
|
|
4
|
-
allowedMimeTypes: ["application/zip", "image/png", "image/jpeg", "application/pdf", "text/plain"],
|
|
5
|
-
maxFileSizeBytes: 20 * MB$1,
|
|
6
|
-
timeoutMs: 5000,
|
|
7
|
-
concurrency: 4,
|
|
8
|
-
failClosed: true,
|
|
9
|
-
};
|
|
10
|
-
function definePolicy(input = {}) {
|
|
11
|
-
const p = { ...DEFAULT_POLICY, ...input };
|
|
12
|
-
if (!Array.isArray(p.includeExtensions))
|
|
13
|
-
throw new TypeError("includeExtensions must be string[]");
|
|
14
|
-
if (!Array.isArray(p.allowedMimeTypes))
|
|
15
|
-
throw new TypeError("allowedMimeTypes must be string[]");
|
|
16
|
-
if (!(Number.isFinite(p.maxFileSizeBytes) && p.maxFileSizeBytes > 0))
|
|
17
|
-
throw new TypeError("maxFileSizeBytes must be > 0");
|
|
18
|
-
if (!(Number.isFinite(p.timeoutMs) && p.timeoutMs > 0))
|
|
19
|
-
throw new TypeError("timeoutMs must be > 0");
|
|
20
|
-
if (!(Number.isInteger(p.concurrency) && p.concurrency > 0))
|
|
21
|
-
throw new TypeError("concurrency must be > 0");
|
|
22
|
-
return p;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Policy packs for Pompelmi.
|
|
27
|
-
*
|
|
28
|
-
* Pre-configured, named policies for common upload scenarios. Each pack
|
|
29
|
-
* defines the file type allowlist, size limits, and timeout appropriate for
|
|
30
|
-
* its use case.
|
|
31
|
-
*
|
|
32
|
-
* All packs are built on `definePolicy` and are fully overridable:
|
|
33
|
-
*
|
|
34
|
-
* ```ts
|
|
35
|
-
* import { POLICY_PACKS } from 'pompelmi/policy-packs';
|
|
36
|
-
*
|
|
37
|
-
* // Use a pack as-is:
|
|
38
|
-
* const policy = POLICY_PACKS['images-only'];
|
|
39
|
-
*
|
|
40
|
-
* // Or override individual fields:
|
|
41
|
-
* import { definePolicy } from 'pompelmi';
|
|
42
|
-
* const custom = definePolicy({ ...POLICY_PACKS['documents-only'], maxFileSizeBytes: 5 * 1024 * 1024 });
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* These packs are *deterministic* and *descriptor-based* — they do not
|
|
46
|
-
* depend on any external threat intelligence feed.
|
|
47
|
-
*
|
|
48
|
-
* @module policy-packs
|
|
49
|
-
*/
|
|
50
|
-
const KB = 1024;
|
|
51
|
-
const MB = 1024 * KB;
|
|
52
|
-
// ── Policy packs ──────────────────────────────────────────────────────────────
|
|
53
|
-
/**
|
|
54
|
-
* Documents-only policy.
|
|
55
|
-
*
|
|
56
|
-
* Appropriate for: document management APIs, PDF/Office file upload endpoints,
|
|
57
|
-
* data import pipelines.
|
|
58
|
-
*
|
|
59
|
-
* Allowed: PDF, Word (.docx/.doc), Excel (.xlsx/.xls), PowerPoint (.pptx/.ppt),
|
|
60
|
-
* CSV, plain text, JSON, YAML, ODT/ODS/ODP (OpenDocument).
|
|
61
|
-
* Max size: 25 MB.
|
|
62
|
-
*/
|
|
63
|
-
const DOCUMENTS_ONLY = definePolicy({
|
|
64
|
-
includeExtensions: [
|
|
65
|
-
"pdf",
|
|
66
|
-
"doc",
|
|
67
|
-
"docx",
|
|
68
|
-
"xls",
|
|
69
|
-
"xlsx",
|
|
70
|
-
"ppt",
|
|
71
|
-
"pptx",
|
|
72
|
-
"odt",
|
|
73
|
-
"ods",
|
|
74
|
-
"odp",
|
|
75
|
-
"csv",
|
|
76
|
-
"txt",
|
|
77
|
-
"json",
|
|
78
|
-
"yaml",
|
|
79
|
-
"yml",
|
|
80
|
-
"md",
|
|
81
|
-
],
|
|
82
|
-
allowedMimeTypes: [
|
|
83
|
-
"application/pdf",
|
|
84
|
-
"application/msword",
|
|
85
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
86
|
-
"application/vnd.ms-excel",
|
|
87
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
88
|
-
"application/vnd.ms-powerpoint",
|
|
89
|
-
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
90
|
-
"application/vnd.oasis.opendocument.text",
|
|
91
|
-
"application/vnd.oasis.opendocument.spreadsheet",
|
|
92
|
-
"application/vnd.oasis.opendocument.presentation",
|
|
93
|
-
"text/csv",
|
|
94
|
-
"text/plain",
|
|
95
|
-
"application/json",
|
|
96
|
-
"text/yaml",
|
|
97
|
-
"text/markdown",
|
|
98
|
-
],
|
|
99
|
-
maxFileSizeBytes: 25 * MB,
|
|
100
|
-
timeoutMs: 10000,
|
|
101
|
-
concurrency: 4,
|
|
102
|
-
failClosed: true,
|
|
103
|
-
});
|
|
104
|
-
/**
|
|
105
|
-
* Images-only policy.
|
|
106
|
-
*
|
|
107
|
-
* Appropriate for: avatar uploads, product image APIs, content platforms with
|
|
108
|
-
* user-generated imagery.
|
|
109
|
-
*
|
|
110
|
-
* Allowed: JPEG, PNG, GIF, WebP, AVIF, TIFF, BMP, ICO.
|
|
111
|
-
* Max size: 10 MB.
|
|
112
|
-
* Note: SVG is intentionally excluded — inline SVGs can contain scripts.
|
|
113
|
-
*/
|
|
114
|
-
const IMAGES_ONLY = definePolicy({
|
|
115
|
-
includeExtensions: ["jpg", "jpeg", "png", "gif", "webp", "avif", "tiff", "tif", "bmp", "ico"],
|
|
116
|
-
allowedMimeTypes: [
|
|
117
|
-
"image/jpeg",
|
|
118
|
-
"image/png",
|
|
119
|
-
"image/gif",
|
|
120
|
-
"image/webp",
|
|
121
|
-
"image/avif",
|
|
122
|
-
"image/tiff",
|
|
123
|
-
"image/bmp",
|
|
124
|
-
"image/x-icon",
|
|
125
|
-
"image/vnd.microsoft.icon",
|
|
126
|
-
],
|
|
127
|
-
maxFileSizeBytes: 10 * MB,
|
|
128
|
-
timeoutMs: 5000,
|
|
129
|
-
concurrency: 8,
|
|
130
|
-
failClosed: true,
|
|
131
|
-
});
|
|
132
|
-
/**
|
|
133
|
-
* Strict public-upload policy.
|
|
134
|
-
*
|
|
135
|
-
* Appropriate for: anonymous or low-trust upload endpoints, public APIs,
|
|
136
|
-
* any surface exposed to untrusted users.
|
|
137
|
-
*
|
|
138
|
-
* Aggressive size limit (5 MB), short timeout, fail-closed, narrow MIME
|
|
139
|
-
* allowlist. Only allows plain images and PDF.
|
|
140
|
-
*/
|
|
141
|
-
const STRICT_PUBLIC_UPLOAD = definePolicy({
|
|
142
|
-
includeExtensions: ["jpg", "jpeg", "png", "webp", "pdf"],
|
|
143
|
-
allowedMimeTypes: ["image/jpeg", "image/png", "image/webp", "application/pdf"],
|
|
144
|
-
maxFileSizeBytes: 5 * MB,
|
|
145
|
-
timeoutMs: 4000,
|
|
146
|
-
concurrency: 2,
|
|
147
|
-
failClosed: true,
|
|
148
|
-
});
|
|
149
|
-
/**
|
|
150
|
-
* Conservative default policy.
|
|
151
|
-
*
|
|
152
|
-
* A hardened version of the built-in `DEFAULT_POLICY` suitable for
|
|
153
|
-
* production without further customisation. Stricter size limit and
|
|
154
|
-
* shorter timeout than the permissive default.
|
|
155
|
-
*/
|
|
156
|
-
const CONSERVATIVE_DEFAULT = definePolicy({
|
|
157
|
-
includeExtensions: ["zip", "png", "jpg", "jpeg", "pdf", "txt", "csv", "docx", "xlsx"],
|
|
158
|
-
allowedMimeTypes: [
|
|
159
|
-
"application/zip",
|
|
160
|
-
"image/png",
|
|
161
|
-
"image/jpeg",
|
|
162
|
-
"application/pdf",
|
|
163
|
-
"text/plain",
|
|
164
|
-
"text/csv",
|
|
165
|
-
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
166
|
-
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
167
|
-
],
|
|
168
|
-
maxFileSizeBytes: 10 * MB,
|
|
169
|
-
timeoutMs: 8000,
|
|
170
|
-
concurrency: 4,
|
|
171
|
-
failClosed: true,
|
|
172
|
-
});
|
|
173
|
-
/**
|
|
174
|
-
* Archives policy.
|
|
175
|
-
*
|
|
176
|
-
* Appropriate for: endpoints that accept ZIP, tar, or compressed archives.
|
|
177
|
-
* Combines a generous size allowance with a longer timeout for deep inspection.
|
|
178
|
-
*
|
|
179
|
-
* NOTE: Pair this policy with `createZipBombGuard()` to defend against
|
|
180
|
-
* decompression-bomb attacks:
|
|
181
|
-
*
|
|
182
|
-
* ```ts
|
|
183
|
-
* import { composeScanners, createZipBombGuard, CommonHeuristicsScanner } from 'pompelmi';
|
|
184
|
-
* const scanner = composeScanners(
|
|
185
|
-
* [['zipGuard', createZipBombGuard()], ['heuristics', CommonHeuristicsScanner]]
|
|
186
|
-
* );
|
|
187
|
-
* ```
|
|
188
|
-
*/
|
|
189
|
-
const ARCHIVES = definePolicy({
|
|
190
|
-
includeExtensions: ["zip", "tar", "gz", "tgz", "bz2", "xz", "7z", "rar"],
|
|
191
|
-
allowedMimeTypes: [
|
|
192
|
-
"application/zip",
|
|
193
|
-
"application/x-tar",
|
|
194
|
-
"application/gzip",
|
|
195
|
-
"application/x-bzip2",
|
|
196
|
-
"application/x-xz",
|
|
197
|
-
"application/x-7z-compressed",
|
|
198
|
-
"application/x-rar-compressed",
|
|
199
|
-
],
|
|
200
|
-
maxFileSizeBytes: 100 * MB,
|
|
201
|
-
timeoutMs: 30000,
|
|
202
|
-
concurrency: 2,
|
|
203
|
-
failClosed: true,
|
|
204
|
-
});
|
|
205
|
-
/**
|
|
206
|
-
* Named map of all built-in policy packs.
|
|
207
|
-
*
|
|
208
|
-
* ```ts
|
|
209
|
-
* import { POLICY_PACKS } from 'pompelmi/policy-packs';
|
|
210
|
-
* const policy = POLICY_PACKS['strict-public-upload'];
|
|
211
|
-
* ```
|
|
212
|
-
*/
|
|
213
|
-
const POLICY_PACKS = {
|
|
214
|
-
"documents-only": DOCUMENTS_ONLY,
|
|
215
|
-
"images-only": IMAGES_ONLY,
|
|
216
|
-
"strict-public-upload": STRICT_PUBLIC_UPLOAD,
|
|
217
|
-
"conservative-default": CONSERVATIVE_DEFAULT,
|
|
218
|
-
archives: ARCHIVES,
|
|
219
|
-
};
|
|
220
|
-
/**
|
|
221
|
-
* Look up a policy pack by name.
|
|
222
|
-
* Throws if the name is not recognised.
|
|
223
|
-
*/
|
|
224
|
-
function getPolicyPack(name) {
|
|
225
|
-
const policy = POLICY_PACKS[name];
|
|
226
|
-
if (!policy)
|
|
227
|
-
throw new Error(`Unknown policy pack: '${name}'. Valid names: ${Object.keys(POLICY_PACKS).join(", ")}`);
|
|
228
|
-
return policy;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export { ARCHIVES, CONSERVATIVE_DEFAULT, DOCUMENTS_ONLY, IMAGES_ONLY, POLICY_PACKS, STRICT_PUBLIC_UPLOAD, getPolicyPack };
|
|
232
|
-
//# sourceMappingURL=pompelmi.policy-packs.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pompelmi.policy-packs.esm.js","sources":["../../src/policy.ts","../../src/policy-packs.ts"],"sourcesContent":["export interface Policy {\n includeExtensions: string[];\n allowedMimeTypes: string[];\n maxFileSizeBytes: number;\n timeoutMs: number;\n concurrency: number;\n failClosed: boolean;\n onScanEvent?: (ev: unknown) => void;\n}\nexport type PolicyInput = Partial<Policy>;\n\nconst MB = 1024 * 1024;\n\nexport const DEFAULT_POLICY: Policy = {\n includeExtensions: [\"zip\", \"png\", \"jpg\", \"jpeg\", \"pdf\"],\n allowedMimeTypes: [\"application/zip\", \"image/png\", \"image/jpeg\", \"application/pdf\", \"text/plain\"],\n maxFileSizeBytes: 20 * MB,\n timeoutMs: 5000,\n concurrency: 4,\n failClosed: true,\n};\n\nexport function definePolicy(input: PolicyInput = {}): Policy {\n const p: Policy = { ...DEFAULT_POLICY, ...input };\n if (!Array.isArray(p.includeExtensions))\n throw new TypeError(\"includeExtensions must be string[]\");\n if (!Array.isArray(p.allowedMimeTypes)) throw new TypeError(\"allowedMimeTypes must be string[]\");\n if (!(Number.isFinite(p.maxFileSizeBytes) && p.maxFileSizeBytes > 0))\n throw new TypeError(\"maxFileSizeBytes must be > 0\");\n if (!(Number.isFinite(p.timeoutMs) && p.timeoutMs > 0))\n throw new TypeError(\"timeoutMs must be > 0\");\n if (!(Number.isInteger(p.concurrency) && p.concurrency > 0))\n throw new TypeError(\"concurrency must be > 0\");\n return p;\n}\n","/**\n * Policy packs for Pompelmi.\n *\n * Pre-configured, named policies for common upload scenarios. Each pack\n * defines the file type allowlist, size limits, and timeout appropriate for\n * its use case.\n *\n * All packs are built on `definePolicy` and are fully overridable:\n *\n * ```ts\n * import { POLICY_PACKS } from 'pompelmi/policy-packs';\n *\n * // Use a pack as-is:\n * const policy = POLICY_PACKS['images-only'];\n *\n * // Or override individual fields:\n * import { definePolicy } from 'pompelmi';\n * const custom = definePolicy({ ...POLICY_PACKS['documents-only'], maxFileSizeBytes: 5 * 1024 * 1024 });\n * ```\n *\n * These packs are *deterministic* and *descriptor-based* — they do not\n * depend on any external threat intelligence feed.\n *\n * @module policy-packs\n */\n\nimport { definePolicy, type Policy } from \"./policy\";\n\nconst KB = 1024;\nconst MB = 1024 * KB;\n\n// ── Policy packs ──────────────────────────────────────────────────────────────\n\n/**\n * Documents-only policy.\n *\n * Appropriate for: document management APIs, PDF/Office file upload endpoints,\n * data import pipelines.\n *\n * Allowed: PDF, Word (.docx/.doc), Excel (.xlsx/.xls), PowerPoint (.pptx/.ppt),\n * CSV, plain text, JSON, YAML, ODT/ODS/ODP (OpenDocument).\n * Max size: 25 MB.\n */\nexport const DOCUMENTS_ONLY: Policy = definePolicy({\n includeExtensions: [\n \"pdf\",\n \"doc\",\n \"docx\",\n \"xls\",\n \"xlsx\",\n \"ppt\",\n \"pptx\",\n \"odt\",\n \"ods\",\n \"odp\",\n \"csv\",\n \"txt\",\n \"json\",\n \"yaml\",\n \"yml\",\n \"md\",\n ],\n allowedMimeTypes: [\n \"application/pdf\",\n \"application/msword\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.ms-excel\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"application/vnd.ms-powerpoint\",\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\",\n \"application/vnd.oasis.opendocument.text\",\n \"application/vnd.oasis.opendocument.spreadsheet\",\n \"application/vnd.oasis.opendocument.presentation\",\n \"text/csv\",\n \"text/plain\",\n \"application/json\",\n \"text/yaml\",\n \"text/markdown\",\n ],\n maxFileSizeBytes: 25 * MB,\n timeoutMs: 10_000,\n concurrency: 4,\n failClosed: true,\n});\n\n/**\n * Images-only policy.\n *\n * Appropriate for: avatar uploads, product image APIs, content platforms with\n * user-generated imagery.\n *\n * Allowed: JPEG, PNG, GIF, WebP, AVIF, TIFF, BMP, ICO.\n * Max size: 10 MB.\n * Note: SVG is intentionally excluded — inline SVGs can contain scripts.\n */\nexport const IMAGES_ONLY: Policy = definePolicy({\n includeExtensions: [\"jpg\", \"jpeg\", \"png\", \"gif\", \"webp\", \"avif\", \"tiff\", \"tif\", \"bmp\", \"ico\"],\n allowedMimeTypes: [\n \"image/jpeg\",\n \"image/png\",\n \"image/gif\",\n \"image/webp\",\n \"image/avif\",\n \"image/tiff\",\n \"image/bmp\",\n \"image/x-icon\",\n \"image/vnd.microsoft.icon\",\n ],\n maxFileSizeBytes: 10 * MB,\n timeoutMs: 5_000,\n concurrency: 8,\n failClosed: true,\n});\n\n/**\n * Strict public-upload policy.\n *\n * Appropriate for: anonymous or low-trust upload endpoints, public APIs,\n * any surface exposed to untrusted users.\n *\n * Aggressive size limit (5 MB), short timeout, fail-closed, narrow MIME\n * allowlist. Only allows plain images and PDF.\n */\nexport const STRICT_PUBLIC_UPLOAD: Policy = definePolicy({\n includeExtensions: [\"jpg\", \"jpeg\", \"png\", \"webp\", \"pdf\"],\n allowedMimeTypes: [\"image/jpeg\", \"image/png\", \"image/webp\", \"application/pdf\"],\n maxFileSizeBytes: 5 * MB,\n timeoutMs: 4_000,\n concurrency: 2,\n failClosed: true,\n});\n\n/**\n * Conservative default policy.\n *\n * A hardened version of the built-in `DEFAULT_POLICY` suitable for\n * production without further customisation. Stricter size limit and\n * shorter timeout than the permissive default.\n */\nexport const CONSERVATIVE_DEFAULT: Policy = definePolicy({\n includeExtensions: [\"zip\", \"png\", \"jpg\", \"jpeg\", \"pdf\", \"txt\", \"csv\", \"docx\", \"xlsx\"],\n allowedMimeTypes: [\n \"application/zip\",\n \"image/png\",\n \"image/jpeg\",\n \"application/pdf\",\n \"text/plain\",\n \"text/csv\",\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\",\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n ],\n maxFileSizeBytes: 10 * MB,\n timeoutMs: 8_000,\n concurrency: 4,\n failClosed: true,\n});\n\n/**\n * Archives policy.\n *\n * Appropriate for: endpoints that accept ZIP, tar, or compressed archives.\n * Combines a generous size allowance with a longer timeout for deep inspection.\n *\n * NOTE: Pair this policy with `createZipBombGuard()` to defend against\n * decompression-bomb attacks:\n *\n * ```ts\n * import { composeScanners, createZipBombGuard, CommonHeuristicsScanner } from 'pompelmi';\n * const scanner = composeScanners(\n * [['zipGuard', createZipBombGuard()], ['heuristics', CommonHeuristicsScanner]]\n * );\n * ```\n */\nexport const ARCHIVES: Policy = definePolicy({\n includeExtensions: [\"zip\", \"tar\", \"gz\", \"tgz\", \"bz2\", \"xz\", \"7z\", \"rar\"],\n allowedMimeTypes: [\n \"application/zip\",\n \"application/x-tar\",\n \"application/gzip\",\n \"application/x-bzip2\",\n \"application/x-xz\",\n \"application/x-7z-compressed\",\n \"application/x-rar-compressed\",\n ],\n maxFileSizeBytes: 100 * MB,\n timeoutMs: 30_000,\n concurrency: 2,\n failClosed: true,\n});\n\n// ── Named map ────────────────────────────────────────────────────────────────\n\nexport type PolicyPackName =\n | \"documents-only\"\n | \"images-only\"\n | \"strict-public-upload\"\n | \"conservative-default\"\n | \"archives\";\n\n/**\n * Named map of all built-in policy packs.\n *\n * ```ts\n * import { POLICY_PACKS } from 'pompelmi/policy-packs';\n * const policy = POLICY_PACKS['strict-public-upload'];\n * ```\n */\nexport const POLICY_PACKS: Record<PolicyPackName, Policy> = {\n \"documents-only\": DOCUMENTS_ONLY,\n \"images-only\": IMAGES_ONLY,\n \"strict-public-upload\": STRICT_PUBLIC_UPLOAD,\n \"conservative-default\": CONSERVATIVE_DEFAULT,\n archives: ARCHIVES,\n};\n\n/**\n * Look up a policy pack by name.\n * Throws if the name is not recognised.\n */\nexport function getPolicyPack(name: PolicyPackName): Policy {\n const policy = POLICY_PACKS[name];\n if (!policy)\n throw new Error(\n `Unknown policy pack: '${name}'. Valid names: ${Object.keys(POLICY_PACKS).join(\", \")}`,\n );\n return policy;\n}\n"],"names":["MB"],"mappings":"AAWA,MAAMA,IAAE,GAAG,IAAI,GAAG,IAAI;AAEf,MAAM,cAAc,GAAW;IACpC,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC;IACvD,gBA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