CVE-2026-34211: SandboxJS Denial of Service Vulnerability

MODERATE
Advisory Identifier: GHSA-8pfc-jjgw-6g26
CWE-674
Published
Advisory Summary

CVE-2026-34211 is a MODERATE denial of service vulnerability (CWE-674: Uncontrolled Recursion) affecting SandboxJS libraries in the npm ecosystem. The issue involves stack overflow dos via deeply nested expressions in recursive descent parser. Remediation is available by upgrading affected packages to version 0.8.36.

CVE-2026-34211 at a Glance

CVE Identifier CVE-2026-34211
GHSA Identifier GHSA-8pfc-jjgw-6g26
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-674: Uncontrolled Recursion
Affected Product SandboxJS
Package Ecosystem npm
Published Date
Last Updated

How to Fix CVE-2026-34211

To remediate this vulnerability, upgrade all affected SandboxJS dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@nyariv/sandboxjs fixed: 0.8.36
npm install @nyariv/sandboxjs@0.8.36
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @nyariv/sandboxjs

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2026-34211, inspect your project dependencies using npm:

npm ls @nyariv/sandboxjs

Analyze the terminal output to locate any version of SandboxJS in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.8.36), your application is affected.

Note: The npm ls @nyariv/sandboxjs command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-674: Uncontrolled Recursion, where the product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack. In SandboxJS, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## Summary The `@nyariv/sandboxjs` parser contains unbounded recursion in the `restOfExp` function and the `lispify`/`lispifyExpr` call chain. An attacker can crash any Node.js process that parses untrusted input by supplying deeply nested expressions (e.g., ~2000 nested parentheses), causing a `RangeError: Maximum call stack size exceeded` that terminates the process. ## Details The root cause is in `src/parser.ts`. The `restOfExp` function (line 443) iterates through expression characters, and when it encounters a closing bracket that doesn't match the expected `firstOpening`, it recursively calls itself at line 503: ```typescript // src/parser.ts:486-505 } else if (closings[char]) { // ... if (char === firstOpening) { done = true; break; } else { const skip = restOfExp(constants, part.substring(i + 1), [], char); // line 503 cache.set(skip.start - 1, skip.end); i += skip.length + 1; } } ``` Each nested bracket (`(`, `[`, `{`) adds a stack frame. There is no depth counter or limit check. The function signature has no depth parameter: ```typescript export function restOfExp( constants: IConstants, part: CodeString, tests?: RegExp[], quote?: string, firstOpening?: string, closingsTests?: RegExp[], details: restDetails = {}, ): CodeString { ``` A second unbounded recursive path exists through `lispify` → `lispTypes.get(type)` → `group` handler → `lispifyExpr` (line 672) → `lispify`, which processes parenthesized groups recursively with no depth limit. All public API methods (`Sandbox.parse()`, `Sandbox.compile()`, `Sandbox.compileAsync()`, `Sandbox.compileExpression()`, `Sandbox.compileExpressionAsync()`) pass user input directly to `parse()` with no input validation or depth limiting. A `RangeError: Maximum call stack size exceeded` in Node.js is not a catchable exception in the normal sense — it crashes the current execution context and, in a server handling requests synchronously, can crash the entire process. ## PoC ```bash # Install the package npm install @nyariv/sandboxjs # Create test file cat > poc.js << 'EOF' const { default: Sandbox } = require('@nyariv/sandboxjs'); const s = new Sandbox(); // Trigger via nested parentheses console.log("Testing nested parentheses..."); try { s.compile('('.repeat(2000) + '1' + ')'.repeat(2000)); console.log("No crash"); } catch(e) { console.log(`Crash: ${e.constructor.name}: ${e.message}`); } // Trigger via nested array brackets console.log("Testing nested array brackets..."); try { s.compile('a' + '[0]'.repeat(2000)); console.log("No crash"); } catch(e) { console.log(`Crash: ${e.constructor.name}: ${e.message}`); } EOF node poc.js ``` **Expected output:** ``` Testing nested parentheses... Crash: RangeError: Maximum call stack size exceeded Testing nested array brackets... Crash: RangeError: Maximum call stack size exceeded ``` Verified on Node.js v22 with `@nyariv/sandboxjs@0.8.35`. ## Impact Any application using `@nyariv/sandboxjs` to parse untrusted user input is vulnerable to denial of service. Since SandboxJS is explicitly designed to safely execute untrusted JavaScript, its primary use case involves untrusted input — making this a high-impact vulnerability for its intended deployment scenario. An attacker can crash the host Node.js process with a single crafted input string. In server-side applications, this causes complete service disruption. The attack payload is trivial to construct and requires no authentication. ## Recommended Fix Add a `depth` parameter to `restOfExp` and throw a `ParseError` when a maximum depth is exceeded: ```typescript // src/parser.ts - restOfExp function const MAX_PARSE_DEPTH = 256; export function restOfExp( constants: IConstants, part: CodeString, tests?: RegExp[], quote?: string, firstOpening?: string, closingsTests?: RegExp[], details: restDetails = {}, depth: number = 0, // ADD depth parameter ): CodeString { if (depth > MAX_PARSE_DEPTH) { throw new ParseError('Expression nesting depth exceeded', part.toString()); } // ... existing code ... // At line 503, pass depth + 1: const skip = restOfExp(constants, part.substring(i + 1), [], char, undefined, undefined, {}, depth + 1); // At line 480 (template literal), also pass depth + 1: const skip = restOfExp(constants, part.substring(i + 2), [], '{', undefined, undefined, {}, depth + 1); } ``` Similarly, add depth tracking to `lispify` and `lispifyExpr`: ```typescript function lispify( constants: IConstants, part: CodeString, expected?: readonly string[], lispTree?: Lisp, topLevel = false, depth: number = 0, // ADD depth parameter ): Lisp { if (depth > MAX_PARSE_DEPTH) { throw new ParseError('Expression nesting depth exceeded', part.toString()); } // ... pass depth + 1 to recursive lispify/lispifyExpr calls ... } ```

CVE-2026-34211 Affected SandboxJS Versions

1 component(s)
Fixed Versions:
0.8.36
Product / Package Ecosystem Affected Versions Fixed Version
@nyariv/sandboxjs
npm
< 0.8.36
0.8.36

References

Frequently Asked Questions

What is CVE-2026-34211?
CVE-2026-34211 is a security vulnerability in SandboxJS involving Stack overflow DoS via deeply nested expressions in recursive descent parser under CWE-674: Uncontrolled Recursion.
Which SandboxJS versions are affected?
Affected versions include releases prior to 0.8.36 across affected packages: @nyariv/sandboxjs.
What version fixes CVE-2026-34211?
Upgrading to 0.8.36 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @nyariv/sandboxjs affected?
Yes, @nyariv/sandboxjs is affected in releases prior to 0.8.36. Upgrade your dependency to 0.8.36 or later.
What CWE is associated with CVE-2026-34211?
CVE-2026-34211 is classified under CWE-674: Uncontrolled Recursion (The product does not properly control the amount of recursion that takes place, consuming excessive resources, such as allocated memory or the program stack.).
How can I check npm dependencies for CVE-2026-34211?
Run the dependency tree command: 'npm ls @nyariv/sandboxjs'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-8pfc-jjgw-6g26",
  "modified" : "2026-04-06T23:18:26Z",
  "published" : "2026-04-03T21:45:14Z",
  "aliases" : [ "CVE-2026-34211" ],
  "summary" : "SandboxJS: Stack overflow DoS via deeply nested expressions in recursive descent parser",
  "details" : "## Summary\n\nThe `@nyariv/sandboxjs` parser contains unbounded recursion in the `restOfExp` function and the `lispify`/`lispifyExpr` call chain. An attacker can crash any Node.js process that parses untrusted input by supplying deeply nested expressions (e.g., ~2000 nested parentheses), causing a `RangeError: Maximum call stack size exceeded` that terminates the process.\n\n## Details\n\nThe root cause is in `src/parser.ts`. The `restOfExp` function (line 443) iterates through expression characters, and when it encounters a closing bracket that doesn't match the expected `firstOpening`, it recursively calls itself at line 503:\n\n```typescript\n// src/parser.ts:486-505\n} else if (closings[char]) {\n  // ...\n  if (char === firstOpening) {\n    done = true;\n    break;\n  } else {\n    const skip = restOfExp(constants, part.substring(i + 1), [], char);  // line 503\n    cache.set(skip.start - 1, skip.end);\n    i += skip.length + 1;\n  }\n}\n```\n\nEach nested bracket (`(`, `[`, `{`) adds a stack frame. There is no depth counter or limit check. The function signature has no depth parameter:\n\n```typescript\nexport function restOfExp(\n  constants: IConstants,\n  part: CodeString,\n  tests?: RegExp[],\n  quote?: string,\n  firstOpening?: string,\n  closingsTests?: RegExp[],\n  details: restDetails = {},\n): CodeString {\n```\n\nA second unbounded recursive path exists through `lispify` → `lispTypes.get(type)` → `group` handler → `lispifyExpr` (line 672) → `lispify`, which processes parenthesized groups recursively with no depth limit.\n\nAll public API methods (`Sandbox.parse()`, `Sandbox.compile()`, `Sandbox.compileAsync()`, `Sandbox.compileExpression()`, `Sandbox.compileExpressionAsync()`) pass user input directly to `parse()` with no input validation or depth limiting.\n\nA `RangeError: Maximum call stack size exceeded` in Node.js is not a catchable exception in the normal sense — it crashes the current execution context and, in a server handling requests synchronously, can crash the entire process.\n\n## PoC\n\n```bash\n# Install the package\nnpm install @nyariv/sandboxjs\n\n# Create test file\ncat > poc.js << 'EOF'\nconst { default: Sandbox } = require('@nyariv/sandboxjs');\nconst s = new Sandbox();\n\n// Trigger via nested parentheses\nconsole.log(\"Testing nested parentheses...\");\ntry {\n  s.compile('('.repeat(2000) + '1' + ')'.repeat(2000));\n  console.log(\"No crash\");\n} catch(e) {\n  console.log(`Crash: ${e.constructor.name}: ${e.message}`);\n}\n\n// Trigger via nested array brackets\nconsole.log(\"Testing nested array brackets...\");\ntry {\n  s.compile('a' + '[0]'.repeat(2000));\n  console.log(\"No crash\");\n} catch(e) {\n  console.log(`Crash: ${e.constructor.name}: ${e.message}`);\n}\nEOF\n\nnode poc.js\n```\n\n**Expected output:**\n```\nTesting nested parentheses...\nCrash: RangeError: Maximum call stack size exceeded\nTesting nested array brackets...\nCrash: RangeError: Maximum call stack size exceeded\n```\n\nVerified on Node.js v22 with `@nyariv/sandboxjs@0.8.35`.\n\n## Impact\n\nAny application using `@nyariv/sandboxjs` to parse untrusted user input is vulnerable to denial of service. Since SandboxJS is explicitly designed to safely execute untrusted JavaScript, its primary use case involves untrusted input — making this a high-impact vulnerability for its intended deployment scenario.\n\nAn attacker can crash the host Node.js process with a single crafted input string. In server-side applications, this causes complete service disruption. The attack payload is trivial to construct and requires no authentication.\n\n## Recommended Fix\n\nAdd a `depth` parameter to `restOfExp` and throw a `ParseError` when a maximum depth is exceeded:\n\n```typescript\n// src/parser.ts - restOfExp function\nconst MAX_PARSE_DEPTH = 256;\n\nexport function restOfExp(\n  constants: IConstants,\n  part: CodeString,\n  tests?: RegExp[],\n  quote?: string,\n  firstOpening?: string,\n  closingsTests?: RegExp[],\n  details: restDetails = {},\n  depth: number = 0,          // ADD depth parameter\n): CodeString {\n  if (depth > MAX_PARSE_DEPTH) {\n    throw new ParseError('Expression nesting depth exceeded', part.toString());\n  }\n  // ... existing code ...\n\n  // At line 503, pass depth + 1:\n  const skip = restOfExp(constants, part.substring(i + 1), [], char, undefined, undefined, {}, depth + 1);\n\n  // At line 480 (template literal), also pass depth + 1:\n  const skip = restOfExp(constants, part.substring(i + 2), [], '{', undefined, undefined, {}, depth + 1);\n}\n```\n\nSimilarly, add depth tracking to `lispify` and `lispifyExpr`:\n\n```typescript\nfunction lispify(\n  constants: IConstants,\n  part: CodeString,\n  expected?: readonly string[],\n  lispTree?: Lisp,\n  topLevel = false,\n  depth: number = 0,         // ADD depth parameter\n): Lisp {\n  if (depth > MAX_PARSE_DEPTH) {\n    throw new ParseError('Expression nesting depth exceeded', part.toString());\n  }\n  // ... pass depth + 1 to recursive lispify/lispifyExpr calls ...\n}\n```",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@nyariv/sandboxjs"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.8.36"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.8.35"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nyariv/SandboxJS/security/advisories/GHSA-8pfc-jjgw-6g26"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-34211"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nyariv/SandboxJS"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-674" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-04-03T21:45:14Z",
    "nvd_published_at" : "2026-04-06T16:16:34Z"
  }
}