seroval 1.7.8 → 1.7.9

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.
@@ -1703,6 +1703,8 @@ function applyObjectFlag(obj, flag) {
1703
1703
  }
1704
1704
  }
1705
1705
  const DEFAULT_DEPTH_LIMIT = 1e3;
1706
+ const MAX_REGEXP_PROPERTY_ESCAPES = 32;
1707
+ const REGEXP_PROPERTY_ESCAPE = /\\[pP]\{/g;
1706
1708
  function createBaseDeserializerContext(options) {
1707
1709
  const maxBase64Length = options.maxBase64Length ?? DEFAULT_MAX_BASE64_LENGTH;
1708
1710
  if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
@@ -1713,7 +1715,8 @@ function createBaseDeserializerContext(options) {
1713
1715
  refs,
1714
1716
  features: options.features ?? 127 ^ (options.disabledFeatures ?? 0),
1715
1717
  depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
1716
- maxBase64Length
1718
+ maxBase64Length,
1719
+ regexpPropertyEscapes: MAX_REGEXP_PROPERTY_ESCAPES
1717
1720
  };
1718
1721
  }
1719
1722
  function createVanillaDeserializerContext(options) {
@@ -1825,6 +1828,13 @@ function deserializeRegExp(ctx, node) {
1825
1828
  if (ctx.base.features & 32) {
1826
1829
  const source = deserializeString(node.c);
1827
1830
  if (source.length > MAX_REGEXP_SOURCE_LENGTH) throw new SerovalMalformedNodeError(node);
1831
+ if (/[uv]/.test(String(node.m))) {
1832
+ const escapes = source.match(REGEXP_PROPERTY_ESCAPE);
1833
+ if (escapes) {
1834
+ ctx.base.regexpPropertyEscapes -= escapes.length;
1835
+ if (ctx.base.regexpPropertyEscapes < 0) throw new SerovalMalformedNodeError(node);
1836
+ }
1837
+ }
1828
1838
  return assignIndexedValue$1(ctx, node.i, new RegExp(source, node.m));
1829
1839
  }
1830
1840
  throw new SerovalUnsupportedNodeError(node);
@@ -2007,6 +2017,7 @@ function deserialize$1(ctx, depth, node) {
2007
2017
  }
2008
2018
  }
2009
2019
  function deserializeTop(ctx, node) {
2020
+ ctx.base.regexpPropertyEscapes = MAX_REGEXP_PROPERTY_ESCAPES;
2010
2021
  try {
2011
2022
  return deserialize$1(ctx, 0, node);
2012
2023
  } catch (error) {
package/dist/dev/index.js CHANGED
@@ -1702,6 +1702,8 @@ function applyObjectFlag(obj, flag) {
1702
1702
  }
1703
1703
  }
1704
1704
  const DEFAULT_DEPTH_LIMIT = 1e3;
1705
+ const MAX_REGEXP_PROPERTY_ESCAPES = 32;
1706
+ const REGEXP_PROPERTY_ESCAPE = /\\[pP]\{/g;
1705
1707
  function createBaseDeserializerContext(options) {
1706
1708
  const maxBase64Length = options.maxBase64Length ?? DEFAULT_MAX_BASE64_LENGTH;
1707
1709
  if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
@@ -1712,7 +1714,8 @@ function createBaseDeserializerContext(options) {
1712
1714
  refs,
1713
1715
  features: options.features ?? 127 ^ (options.disabledFeatures ?? 0),
1714
1716
  depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
1715
- maxBase64Length
1717
+ maxBase64Length,
1718
+ regexpPropertyEscapes: MAX_REGEXP_PROPERTY_ESCAPES
1716
1719
  };
1717
1720
  }
1718
1721
  function createVanillaDeserializerContext(options) {
@@ -1824,6 +1827,13 @@ function deserializeRegExp(ctx, node) {
1824
1827
  if (ctx.base.features & 32) {
1825
1828
  const source = deserializeString(node.c);
1826
1829
  if (source.length > MAX_REGEXP_SOURCE_LENGTH) throw new SerovalMalformedNodeError(node);
1830
+ if (/[uv]/.test(String(node.m))) {
1831
+ const escapes = source.match(REGEXP_PROPERTY_ESCAPE);
1832
+ if (escapes) {
1833
+ ctx.base.regexpPropertyEscapes -= escapes.length;
1834
+ if (ctx.base.regexpPropertyEscapes < 0) throw new SerovalMalformedNodeError(node);
1835
+ }
1836
+ }
1827
1837
  return assignIndexedValue$1(ctx, node.i, new RegExp(source, node.m));
1828
1838
  }
1829
1839
  throw new SerovalUnsupportedNodeError(node);
@@ -2006,6 +2016,7 @@ function deserialize$1(ctx, depth, node) {
2006
2016
  }
2007
2017
  }
2008
2018
  function deserializeTop(ctx, node) {
2019
+ ctx.base.regexpPropertyEscapes = MAX_REGEXP_PROPERTY_ESCAPES;
2009
2020
  try {
2010
2021
  return deserialize$1(ctx, 0, node);
2011
2022
  } catch (error) {
package/dist/index.cjs CHANGED
@@ -1687,6 +1687,8 @@ function applyObjectFlag(obj, flag) {
1687
1687
  }
1688
1688
  }
1689
1689
  const DEFAULT_DEPTH_LIMIT = 1e3;
1690
+ const MAX_REGEXP_PROPERTY_ESCAPES = 32;
1691
+ const REGEXP_PROPERTY_ESCAPE = /\\[pP]\{/g;
1690
1692
  function createBaseDeserializerContext(options) {
1691
1693
  const maxBase64Length = options.maxBase64Length ?? DEFAULT_MAX_BASE64_LENGTH;
1692
1694
  if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
@@ -1697,7 +1699,8 @@ function createBaseDeserializerContext(options) {
1697
1699
  refs,
1698
1700
  features: options.features ?? 127 ^ (options.disabledFeatures ?? 0),
1699
1701
  depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
1700
- maxBase64Length
1702
+ maxBase64Length,
1703
+ regexpPropertyEscapes: MAX_REGEXP_PROPERTY_ESCAPES
1701
1704
  };
1702
1705
  }
1703
1706
  function createVanillaDeserializerContext(options) {
@@ -1809,6 +1812,13 @@ function deserializeRegExp(ctx, node) {
1809
1812
  if (ctx.base.features & 32) {
1810
1813
  const source = deserializeString(node.c);
1811
1814
  if (source.length > MAX_REGEXP_SOURCE_LENGTH) throw new SerovalMalformedNodeError(node);
1815
+ if (/[uv]/.test(String(node.m))) {
1816
+ const escapes = source.match(REGEXP_PROPERTY_ESCAPE);
1817
+ if (escapes) {
1818
+ ctx.base.regexpPropertyEscapes -= escapes.length;
1819
+ if (ctx.base.regexpPropertyEscapes < 0) throw new SerovalMalformedNodeError(node);
1820
+ }
1821
+ }
1812
1822
  return assignIndexedValue$1(ctx, node.i, new RegExp(source, node.m));
1813
1823
  }
1814
1824
  throw new SerovalUnsupportedNodeError(node);
@@ -1991,6 +2001,7 @@ function deserialize$1(ctx, depth, node) {
1991
2001
  }
1992
2002
  }
1993
2003
  function deserializeTop(ctx, node) {
2004
+ ctx.base.regexpPropertyEscapes = MAX_REGEXP_PROPERTY_ESCAPES;
1994
2005
  try {
1995
2006
  return deserialize$1(ctx, 0, node);
1996
2007
  } catch (error) {
package/dist/index.js CHANGED
@@ -1686,6 +1686,8 @@ function applyObjectFlag(obj, flag) {
1686
1686
  }
1687
1687
  }
1688
1688
  const DEFAULT_DEPTH_LIMIT = 1e3;
1689
+ const MAX_REGEXP_PROPERTY_ESCAPES = 32;
1690
+ const REGEXP_PROPERTY_ESCAPE = /\\[pP]\{/g;
1689
1691
  function createBaseDeserializerContext(options) {
1690
1692
  const maxBase64Length = options.maxBase64Length ?? DEFAULT_MAX_BASE64_LENGTH;
1691
1693
  if (!Number.isSafeInteger(maxBase64Length) || maxBase64Length < 0) throw new RangeError("maxBase64Length must be a non-negative safe integer");
@@ -1696,7 +1698,8 @@ function createBaseDeserializerContext(options) {
1696
1698
  refs,
1697
1699
  features: options.features ?? 127 ^ (options.disabledFeatures ?? 0),
1698
1700
  depthLimit: options.depthLimit || DEFAULT_DEPTH_LIMIT,
1699
- maxBase64Length
1701
+ maxBase64Length,
1702
+ regexpPropertyEscapes: MAX_REGEXP_PROPERTY_ESCAPES
1700
1703
  };
1701
1704
  }
1702
1705
  function createVanillaDeserializerContext(options) {
@@ -1808,6 +1811,13 @@ function deserializeRegExp(ctx, node) {
1808
1811
  if (ctx.base.features & 32) {
1809
1812
  const source = deserializeString(node.c);
1810
1813
  if (source.length > MAX_REGEXP_SOURCE_LENGTH) throw new SerovalMalformedNodeError(node);
1814
+ if (/[uv]/.test(String(node.m))) {
1815
+ const escapes = source.match(REGEXP_PROPERTY_ESCAPE);
1816
+ if (escapes) {
1817
+ ctx.base.regexpPropertyEscapes -= escapes.length;
1818
+ if (ctx.base.regexpPropertyEscapes < 0) throw new SerovalMalformedNodeError(node);
1819
+ }
1820
+ }
1811
1821
  return assignIndexedValue$1(ctx, node.i, new RegExp(source, node.m));
1812
1822
  }
1813
1823
  throw new SerovalUnsupportedNodeError(node);
@@ -1990,6 +2000,7 @@ function deserialize$1(ctx, depth, node) {
1990
2000
  }
1991
2001
  }
1992
2002
  function deserializeTop(ctx, node) {
2003
+ ctx.base.regexpPropertyEscapes = MAX_REGEXP_PROPERTY_ESCAPES;
1993
2004
  try {
1994
2005
  return deserialize$1(ctx, 0, node);
1995
2006
  } catch (error) {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "seroval",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "1.7.8",
5
+ "version": "1.7.9",
6
6
  "files": [
7
7
  "dist"
8
8
  ],