@pie-qti/ims-cp-core 1.0.0-beta.3 → 1.0.0-beta.4

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.
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Shared archive-extraction safety policy.
3
+ *
4
+ * Single authority for the zip-bomb guardrails applied by the three archive
5
+ * engines (@pie-qti/ims-cp-browser jszip, @pie-qti/ims-cp-node unzipper,
6
+ * @pie-qti/storage adm-zip). The engines differ per platform by necessity;
7
+ * the limits, validation, and ratio math must not drift between them.
8
+ */
9
+ /** Guardrail limits for extracting untrusted archives. */
10
+ export interface ArchiveExtractionLimits {
11
+ /** Maximum compressed input size in bytes. */
12
+ maxCompressedSize: number;
13
+ /** Maximum total advertised uncompressed size in bytes. */
14
+ maxTotalUncompressedSize: number;
15
+ /** Maximum number of archive entries. */
16
+ maxEntries: number;
17
+ /** Maximum allowed uncompressed/compressed size ratio per entry. */
18
+ maxCompressionRatio: number;
19
+ }
20
+ /** Default guardrails: 100 MB compressed, 250 MB uncompressed, 1000 entries, ratio 200. */
21
+ export declare const DEFAULT_ARCHIVE_EXTRACTION_LIMITS: Readonly<ArchiveExtractionLimits>;
22
+ /**
23
+ * Resolve a single configurable limit against its fallback.
24
+ *
25
+ * @param value - Host-provided value (undefined selects the fallback).
26
+ * @param fallback - Default value.
27
+ * @param name - Option name used in error messages.
28
+ * @param requireInteger - Reject non-integer values (counts).
29
+ */
30
+ export declare function resolveArchiveLimit(value: number | undefined, fallback: number, name: string, requireInteger?: boolean): number;
31
+ /**
32
+ * True when an entry's size ratio exceeds `maximum` (possible zip bomb).
33
+ * Zero-sized compressed entries with content are always rejected.
34
+ */
35
+ export declare function exceedsCompressionRatio(uncompressed: number, compressed: number, maximum: number): boolean;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Shared archive-extraction safety policy.
3
+ *
4
+ * Single authority for the zip-bomb guardrails applied by the three archive
5
+ * engines (@pie-qti/ims-cp-browser jszip, @pie-qti/ims-cp-node unzipper,
6
+ * @pie-qti/storage adm-zip). The engines differ per platform by necessity;
7
+ * the limits, validation, and ratio math must not drift between them.
8
+ */
9
+ /** Default guardrails: 100 MB compressed, 250 MB uncompressed, 1000 entries, ratio 200. */
10
+ export const DEFAULT_ARCHIVE_EXTRACTION_LIMITS = {
11
+ maxCompressedSize: 100 * 1024 * 1024,
12
+ maxTotalUncompressedSize: 250 * 1024 * 1024,
13
+ maxEntries: 1000,
14
+ maxCompressionRatio: 200,
15
+ };
16
+ /**
17
+ * Resolve a single configurable limit against its fallback.
18
+ *
19
+ * @param value - Host-provided value (undefined selects the fallback).
20
+ * @param fallback - Default value.
21
+ * @param name - Option name used in error messages.
22
+ * @param requireInteger - Reject non-integer values (counts).
23
+ */
24
+ export function resolveArchiveLimit(value, fallback, name, requireInteger = false) {
25
+ const resolved = value ?? fallback;
26
+ if (resolved !== Number.POSITIVE_INFINITY &&
27
+ (!Number.isFinite(resolved) || resolved < 0 || (requireInteger && !Number.isInteger(resolved)))) {
28
+ throw new Error(`${name} must be a non-negative ${requireInteger ? 'integer' : 'number'}`);
29
+ }
30
+ return resolved;
31
+ }
32
+ /**
33
+ * True when an entry's size ratio exceeds `maximum` (possible zip bomb).
34
+ * Zero-sized compressed entries with content are always rejected.
35
+ */
36
+ export function exceedsCompressionRatio(uncompressed, compressed, maximum) {
37
+ if (uncompressed === 0 || maximum === Number.POSITIVE_INFINITY)
38
+ return false;
39
+ if (compressed <= 0)
40
+ return true;
41
+ return uncompressed / compressed > maximum;
42
+ }
43
+ //# sourceMappingURL=limits.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../../src/archive/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAcH,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iCAAiC,GAAsC;IACnF,iBAAiB,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;IACpC,wBAAwB,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI;IAC3C,UAAU,EAAE,IAAI;IAChB,mBAAmB,EAAE,GAAG;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,KAAyB,EACzB,QAAgB,EAChB,IAAY,EACZ,cAAc,GAAG,KAAK;IAEtB,MAAM,QAAQ,GAAG,KAAK,IAAI,QAAQ,CAAC;IACnC,IACC,QAAQ,KAAK,MAAM,CAAC,iBAAiB;QACrC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,GAAG,CAAC,IAAI,CAAC,cAAc,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAC9F,CAAC;QACF,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,2BAA2B,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACtC,YAAoB,EACpB,UAAkB,EAClB,OAAe;IAEf,IAAI,YAAY,KAAK,CAAC,IAAI,OAAO,KAAK,MAAM,CAAC,iBAAiB;QAAE,OAAO,KAAK,CAAC;IAC7E,IAAI,UAAU,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACjC,OAAO,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC;AAC5C,CAAC","sourcesContent":["/**\n * Shared archive-extraction safety policy.\n *\n * Single authority for the zip-bomb guardrails applied by the three archive\n * engines (@pie-qti/ims-cp-browser jszip, @pie-qti/ims-cp-node unzipper,\n * @pie-qti/storage adm-zip). The engines differ per platform by necessity;\n * the limits, validation, and ratio math must not drift between them.\n */\n\n/** Guardrail limits for extracting untrusted archives. */\nexport interface ArchiveExtractionLimits {\n\t/** Maximum compressed input size in bytes. */\n\tmaxCompressedSize: number;\n\t/** Maximum total advertised uncompressed size in bytes. */\n\tmaxTotalUncompressedSize: number;\n\t/** Maximum number of archive entries. */\n\tmaxEntries: number;\n\t/** Maximum allowed uncompressed/compressed size ratio per entry. */\n\tmaxCompressionRatio: number;\n}\n\n/** Default guardrails: 100 MB compressed, 250 MB uncompressed, 1000 entries, ratio 200. */\nexport const DEFAULT_ARCHIVE_EXTRACTION_LIMITS: Readonly<ArchiveExtractionLimits> = {\n\tmaxCompressedSize: 100 * 1024 * 1024,\n\tmaxTotalUncompressedSize: 250 * 1024 * 1024,\n\tmaxEntries: 1000,\n\tmaxCompressionRatio: 200,\n};\n\n/**\n * Resolve a single configurable limit against its fallback.\n *\n * @param value - Host-provided value (undefined selects the fallback).\n * @param fallback - Default value.\n * @param name - Option name used in error messages.\n * @param requireInteger - Reject non-integer values (counts).\n */\nexport function resolveArchiveLimit(\n\tvalue: number | undefined,\n\tfallback: number,\n\tname: string,\n\trequireInteger = false,\n): number {\n\tconst resolved = value ?? fallback;\n\tif (\n\t\tresolved !== Number.POSITIVE_INFINITY &&\n\t\t(!Number.isFinite(resolved) || resolved < 0 || (requireInteger && !Number.isInteger(resolved)))\n\t) {\n\t\tthrow new Error(`${name} must be a non-negative ${requireInteger ? 'integer' : 'number'}`);\n\t}\n\treturn resolved;\n}\n\n/**\n * True when an entry's size ratio exceeds `maximum` (possible zip bomb).\n * Zero-sized compressed entries with content are always rejected.\n */\nexport function exceedsCompressionRatio(\n\tuncompressed: number,\n\tcompressed: number,\n\tmaximum: number,\n): boolean {\n\tif (uncompressed === 0 || maximum === Number.POSITIVE_INFINITY) return false;\n\tif (compressed <= 0) return true;\n\treturn uncompressed / compressed > maximum;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from './package-path.js';
7
7
  export * from './package-file-resolver.js';
8
8
  export * from './package-graph.js';
9
9
  export * from './security-parsing.js';
10
+ export * from './archive/limits.js';
10
11
  export * from './localized-resources.js';
11
12
  export * from './passage-reusability.js';
12
13
  export * from './qti3-shared-content.js';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ export * from './package-path.js';
7
7
  export * from './package-file-resolver.js';
8
8
  export * from './package-graph.js';
9
9
  export * from './security-parsing.js';
10
+ export * from './archive/limits.js';
10
11
  export * from './localized-resources.js';
11
12
  export * from './passage-reusability.js';
12
13
  export * from './qti3-shared-content.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC","sourcesContent":["/**\n * @pie-qti/ims-cp-core\n * Core IMS Content Package utilities (browser + Node.js compatible)\n */\n\nexport * from './manifest-parser.js';\nexport * from './package-path.js';\nexport * from './package-file-resolver.js';\nexport * from './package-graph.js';\nexport * from './security-parsing.js';\nexport * from './localized-resources.js';\nexport * from './passage-reusability.js';\nexport * from './qti3-shared-content.js';\nexport * from './qti-heuristics.js';\nexport * from './utils/qti-xml.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC","sourcesContent":["/**\n * @pie-qti/ims-cp-core\n * Core IMS Content Package utilities (browser + Node.js compatible)\n */\n\nexport * from './manifest-parser.js';\nexport * from './package-path.js';\nexport * from './package-file-resolver.js';\nexport * from './package-graph.js';\nexport * from './security-parsing.js';\nexport * from './archive/limits.js';\nexport * from './localized-resources.js';\nexport * from './passage-reusability.js';\nexport * from './qti3-shared-content.js';\nexport * from './qti-heuristics.js';\nexport * from './utils/qti-xml.js';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-qti/ims-cp-core",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "Core IMS Content Package manifest parsing utilities (browser + Node.js)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -33,10 +33,14 @@
33
33
  "./qti3-shared-content": {
34
34
  "types": "./dist/qti3-shared-content.d.ts",
35
35
  "import": "./dist/qti3-shared-content.js"
36
+ },
37
+ "./archive-limits": {
38
+ "types": "./dist/archive/limits.d.ts",
39
+ "import": "./dist/archive/limits.js"
36
40
  }
37
41
  },
38
42
  "dependencies": {
39
- "@pie-qti/logger": "1.0.0-beta.3",
43
+ "@pie-qti/logger": "1.0.0-beta.4",
40
44
  "node-html-parser": "^9.0.5"
41
45
  },
42
46
  "devDependencies": {