fast-xml-parser 5.4.1 → 5.4.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-xml-parser",
3
- "version": "5.4.1",
3
+ "version": "5.4.2",
4
4
  "description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
5
5
  "main": "./lib/fxp.cjs",
6
6
  "type": "module",
package/src/fxp.d.ts CHANGED
@@ -34,6 +34,13 @@ export type ProcessEntitiesOptions = {
34
34
  */
35
35
  maxExpandedLength?: number;
36
36
 
37
+ /**
38
+ * Maximum number of entities allowed in the XML
39
+ *
40
+ * Defaults to `100`
41
+ */
42
+ maxEntityCount?: number;
43
+
37
44
  /**
38
45
  * Array of tag names where entity replacement is allowed.
39
46
  * If null, entities are replaced in all tags.
@@ -7,8 +7,9 @@ export default class DocTypeReader {
7
7
  }
8
8
 
9
9
  readDocType(xmlData, i) {
10
-
11
10
  const entities = Object.create(null);
11
+ let entityCount = 0;
12
+
12
13
  if (xmlData[i + 3] === 'O' &&
13
14
  xmlData[i + 4] === 'C' &&
14
15
  xmlData[i + 5] === 'T' &&
@@ -26,11 +27,19 @@ export default class DocTypeReader {
26
27
  let entityName, val;
27
28
  [entityName, val, i] = this.readEntityExp(xmlData, i + 1, this.suppressValidationErr);
28
29
  if (val.indexOf("&") === -1) { //Parameter entities are not supported
30
+ if (this.options.enabled !== false &&
31
+ this.options.maxEntityCount &&
32
+ entityCount >= this.options.maxEntityCount) {
33
+ throw new Error(
34
+ `Entity count (${entityCount + 1}) exceeds maximum allowed (${this.options.maxEntityCount})`
35
+ );
36
+ }
29
37
  const escaped = entityName.replace(/[.\-+*:]/g, '\\.');
30
38
  entities[entityName] = {
31
39
  regx: RegExp(`&${escaped};`, "g"),
32
40
  val: val
33
41
  };
42
+ entityCount++;
34
43
  }
35
44
  }
36
45
  else if (hasBody && hasSeq(xmlData, "!ELEMENT", i)) {
@@ -56,6 +56,7 @@ function normalizeProcessEntities(value) {
56
56
  maxExpansionDepth: 10,
57
57
  maxTotalExpansions: 1000,
58
58
  maxExpandedLength: 100000,
59
+ maxEntityCount: 100,
59
60
  allowedTags: null,
60
61
  tagFilter: null
61
62
  };
@@ -69,6 +70,7 @@ function normalizeProcessEntities(value) {
69
70
  maxExpansionDepth: value.maxExpansionDepth ?? 10,
70
71
  maxTotalExpansions: value.maxTotalExpansions ?? 1000,
71
72
  maxExpandedLength: value.maxExpandedLength ?? 100000,
73
+ maxEntityCount: value.maxEntityCount ?? 100,
72
74
  allowedTags: value.allowedTags ?? null,
73
75
  tagFilter: value.tagFilter ?? null
74
76
  };