# CVE-2024-28397: js2py allows remote code execution

> Attackers can execute arbitrary code via crafted API calls in the js2py library due to improper neutralization of special elements used in code generation.

- **Severity:** Medium 5.3 (`CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 20 Jun 2024
- **Updated:** 2 Aug 2024
- **Also known as:** ECHO-af95-1da0-5a17, GHSA-h95x-26f3-88hr, MGASA-2024-0256, PYSEC-2026-1476, SUSE-SU-2024:2272-1, UBUNTU-CVE-2024-28397, openSUSE-SU-2024:14086-1, openSUSE-SU-2026:11322-1

## What is CVE-2024-28397?

CVE-2024-28397 is a medium-severity code injection vulnerability in n/a, published on 20 Jun 2024. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

An issue in the component js2py.disable_pyimport() of js2py up to v0.74 allows attackers to execute arbitrary code via a crafted API call.

Weakness: CWE-94 (Improper Control of Generation of Code)

## Which versions are affected by CVE-2024-28397?

3 open source packages ship an affected version, including js2py.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `js2py` | PyPI | All versions to 0.74 | None |
| `js2py` | PyPI | All versions to 0.74 | None |
| `js2py` | PyPI | All versions to 0.74 | None |
| `python-Js2Py` | openSUSE:Leap 15.6 | All versions | 0.74-150400.9.6.1 |
| `python-Js2Py` | openSUSE:Tumbleweed | All versions | 0.74-3.1 |
| `python-Js2Py` | openSUSE:Tumbleweed | All versions | 0.74-6.1 |

## How do I fix CVE-2024-28397?

Upgrade to a fixed version.

## Is CVE-2024-28397 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-28397 exists.

Public exploit code:

- CVE-2024-28397: js2py sandbox escape, bypass pyimport restriction. (github_poc): https://github.com/Marven11/CVE-2024-28397-js2py-Sandbox-Escape
- This repository contains a python exploit code for CVE-2024-28397 intended for use on the "CodePartTwo" machine on Hack The Box (HTB). (github_poc): https://github.com/naclapor/CVE-2024-28397
- This vulnerability arises from incomplete sandboxing in js2py, where crafted JavaScript can traverse Python’s internal object model and access dangerous classes like subprocess.Popen, leading to arbitrary command execution. (github_poc): https://github.com/GhostOverflow/CVE-2024-28397-command-execution-poc
- A Python automation script for exploiting the **js2py Sandbox Escape** vulnerability (CVE-2024-28397). This tool automates the payload generation and delivery process to achieve Remote Code Execution (RCE) on vulnerable instances. (github_poc): https://github.com/L1337Xi/CVE-2024-28397-Exploit-Automation
- Professional exploit for CVE-2024-28397: Js2Py Sandbox Escape leading to Remote Code Execution (RCE). Includes modular payload generation. (github_poc): https://github.com/xeloxa/CVE-2024-28397-Js2Py-RCE-Exploit
- The CVE-2024-28397 vulnerability affects versions of js2py up to v0.74, a Python library that allows JavaScript code to be executed within the Python interpreter.  (github_poc): https://github.com/RianJuniorSf/exploit-js2py

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-28397 and fix it if it is affected.

What it is: CVE-2024-28397 is a medium-severity code injection vulnerability in n/a, published on 20 Jun 2024. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2024-28397 exists.

Affected packages and fixed versions:
- js2py (PyPI): affected all versions up to 0.74; no fix listed
- js2py (PyPI): affected all versions up to 0.74; no fix listed
- js2py (PyPI): affected all versions up to 0.74; no fix listed

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-28397/ (Markdown: https://insights.sbomify.com/CVE-2024-28397/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-28397
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-28397
- OSV: https://osv.dev/vulnerability/CVE-2024-28397

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-28397/
Summaries are generated and may contain mistakes; the official description above is the record.
