CVE-2026-41507: Math codegen Remote Code Execution Vulnerability

CRITICAL
Advisory Identifier: GHSA-p6x5-p4xf-cc4r
CVSS 9.8
CWE-94
Published
Advisory Summary

CVE-2026-41507 is a CRITICAL (CVSS 9.8) remote code execution vulnerability (CWE-94: Improper Control of Generation of Code ('Code Injection')) affecting Math codegen libraries in the npm ecosystem. The issue involves remote code execution (rce) via string literal injection into math-codegen. Remediation is available by upgrading affected packages to version 0.4.3.

CVE-2026-41507 at a Glance

CVE Identifier CVE-2026-41507
GHSA Identifier GHSA-p6x5-p4xf-cc4r
Severity CRITICAL
CVSS v3.1 Base Score 9.8
CWE Classification CWE-94: Improper Control of Generation of Code ('Code Injection')
Affected Product Math codegen
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 9.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2026-41507

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

math-codegen fixed: 0.4.3
npm install math-codegen@0.4.3
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 math-codegen

How to Check if You Are Affected

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

npm ls math-codegen

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

Note: The npm ls math-codegen 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-94: Improper Control of Generation of Code ('Code Injection'), where the product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment. In Math codegen, 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

### Impact String literal content passed to `cg.parse()` is injected verbatim into a `new Function()` body without sanitization. This allows an attacker to execute arbitrary system commands when user-controlled input reaches the parser. Any application exposing a math evaluation endpoint where user input flows into `cg.parse()` is vulnerable to full RCE. ### Patches The vulnerability is addressed by using `JSON.stringify()` on string literal values in `lib/node/ConstantNode.js` to ensure they are treated as data rather than code. Users should upgrade to version 0.4.3 or later. ### Workarounds Avoid passing un-sanitized user input to the parser or manually escape string literals in the input.

CVE-2026-41507 Affected Math codegen Versions

1 component(s)
Fixed Versions:
0.4.3
Product / Package Ecosystem Affected Versions Fixed Version
math-codegen
npm
< 0.4.3
0.4.3

References

Frequently Asked Questions

What is CVE-2026-41507?
CVE-2026-41507 is a security vulnerability in Math codegen involving Remote Code Execution (RCE) via String Literal Injection into math-codegen under CWE-94: Improper Control of Generation of Code ('Code Injection').
Which Math codegen versions are affected?
Affected versions include releases prior to 0.4.3 across affected packages: math-codegen.
What version fixes CVE-2026-41507?
Upgrading to 0.4.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is math-codegen affected?
Yes, math-codegen is affected in releases prior to 0.4.3. Upgrade your dependency to 0.4.3 or later.
What is the CVSS score of CVE-2026-41507?
CVE-2026-41507 has a CVSS v3.1 base score of 9.8 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2026-41507?
CVE-2026-41507 is classified under CWE-94: Improper Control of Generation of Code ('Code Injection') (The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.).
How can I check npm dependencies for CVE-2026-41507?
Run the dependency tree command: 'npm ls math-codegen'. 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-p6x5-p4xf-cc4r",
  "modified" : "2026-05-12T13:32:44Z",
  "published" : "2026-04-17T22:31:45Z",
  "aliases" : [ "CVE-2026-41507" ],
  "summary" : "Remote Code Execution (RCE) via String Literal Injection into math-codegen",
  "details" : "### Impact\n\nString literal content passed to `cg.parse()` is injected verbatim into a `new Function()` body without sanitization. This allows an attacker to execute arbitrary system commands when user-controlled input reaches the parser. Any application exposing a math evaluation endpoint where user input flows into `cg.parse()` is vulnerable to full RCE.\n    \n### Patches\n\nThe vulnerability is addressed by using `JSON.stringify()` on string literal values in `lib/node/ConstantNode.js` to ensure they are treated as data rather than code. Users should upgrade to version 0.4.3 or later.\n    \n### Workarounds\n\nAvoid passing un-sanitized user input to the parser or manually escape string literals in the input.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "math-codegen"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.3"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/mauriciopoppe/math-codegen/security/advisories/GHSA-p6x5-p4xf-cc4r"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-41507"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mauriciopoppe/math-codegen/pull/11"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mauriciopoppe/math-codegen/commit/4bb52d3030683362b3559ee8dd91350555a05f6b"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/hits3134"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mauriciopoppe/math-codegen"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-94" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-04-17T22:31:45Z",
    "nvd_published_at" : "2026-05-08T14:16:34Z"
  }
}