CVE-2026-41507
Command Injection in math-codegen Library
Publication date: 2026-05-08
Last updated on: 2026-05-08
Assigner: GitHub, Inc.
Description
Description
CVSS Scores
EPSS Scores
| Probability: | |
| Percentile: |
Meta Information
Affected Vendors & Products
| Vendor | Product | Version / Range |
|---|---|---|
| mauriciopoppe | math-codegen | to 0.4.3 (exc) |
| math-codegen | math-codegen | to 0.4.3 (exc) |
Helpful Resources
Exploitability
| CWE ID | Description |
|---|---|
| CWE-94 | 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. |
Attack-Flow Graph
AI Powered Q&A
How does this vulnerability affect compliance with common standards and regulations (like GDPR, HIPAA)?:
This vulnerability allows remote code execution (RCE) through unsanitized user input, which can lead to unauthorized access, data breaches, and system compromise.
Such security failures can result in violations of common standards and regulations like GDPR and HIPAA, which require protection of sensitive data and secure processing environments.
If exploited, the vulnerability could lead to exposure or alteration of confidential information, undermining compliance with confidentiality, integrity, and availability requirements mandated by these regulations.
Therefore, applications using vulnerable versions of math-codegen without proper mitigation may face compliance risks until patched or properly secured.
Can you explain this vulnerability to me?
CVE-2026-41507 is a critical Remote Code Execution (RCE) vulnerability in the math-codegen library versions prior to 0.4.3. The issue occurs because string literal content passed to the cg.parse() function is injected directly into a new Function() body without proper sanitization. This means that if an attacker can control the input to cg.parse(), they can execute arbitrary system commands on the affected system.
This vulnerability arises from improper handling of user input, allowing code injection through unsanitized strings. It affects any application that exposes a math evaluation endpoint where user input flows into cg.parse(). The vulnerability has been fixed in version 0.4.3 by applying JSON.stringify() to string literals to treat them as data rather than executable code.
How can this vulnerability impact me? :
This vulnerability can have severe impacts because it allows an attacker to execute arbitrary system commands remotely without any privileges or user interaction. This means an attacker can take full control of the affected system, potentially leading to data theft, data loss, system compromise, or disruption of services.
The CVSS score of 9.8 indicates a critical severity with high impact on confidentiality, integrity, and availability. An attacker exploiting this vulnerability could compromise sensitive information, alter or destroy data, and disrupt system operations.
How can this vulnerability be detected on my network or system? Can you suggest some commands?
This vulnerability occurs when user-controlled input is passed unsanitized to the cg.parse() function in math-codegen versions prior to 0.4.3, leading to remote code execution.
To detect if your system is vulnerable, first check the version of math-codegen in use. If it is older than 0.4.3, it is vulnerable.
You can search your codebase for usage of cg.parse() with user input to identify potential vulnerable endpoints.
- Use commands like `npm list math-codegen` or `yarn list math-codegen` to determine the installed version.
- Search your project files for `cg.parse(` to find where the parser is used, e.g., `grep -r "cg.parse(" ./`.
- Monitor network traffic or logs for suspicious inputs reaching math evaluation endpoints that might be passed to cg.parse().
What immediate steps should I take to mitigate this vulnerability?
The primary mitigation is to upgrade math-codegen to version 0.4.3 or later, where the vulnerability has been patched by properly escaping string literals and adding input validation.
If upgrading immediately is not possible, avoid passing unsanitized user input to cg.parse() or manually escape string literals before parsing.
Review your code to ensure that no user input flows directly into cg.parse() without validation or sanitization.