maxNestingDepth.js 1.1 KB

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.MAX_NESTING_DEPTH = void 0;
  4. exports.default = resolveMaxNestingDepth;
  5. /**
  6. * The default maximum selector nesting depth allowed when parsing or
  7. * serializing a selector. Going beyond this would otherwise recurse deeply
  8. * enough to overflow the call stack (CVE-2026-9358 / CWE-674). Real-world
  9. * selectors never get anywhere near this, so it acts purely as a safety net
  10. * that turns an uncatchable stack overflow into a catchable error.
  11. */
  12. exports.MAX_NESTING_DEPTH = 256;
  13. /**
  14. * Coerce a user-supplied nesting-depth limit into a safe value. Anything that
  15. * is not a non-negative safe integer (NaN, Infinity, negative numbers, or a
  16. * non-number) would disable or break the guard, so it falls back to the
  17. * default.
  18. *
  19. * @param {unknown} value the limit provided through the `maxNestingDepth` option
  20. * @returns {number} a safe, non-negative integer limit
  21. */
  22. function resolveMaxNestingDepth(value) {
  23. return Number.isSafeInteger(value) && value >= 0 ? value : exports.MAX_NESTING_DEPTH;
  24. }
  25. //# sourceMappingURL=maxNestingDepth.js.map