# CVE-2023-49797: Local Privilege Escalation in pyinstaller on Windows

> An unprivileged attacker can delete protected files via a race condition in PyInstaller-built apps running as admin with insecure temp directories.

- **Severity:** High 8.8 (`CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H`)
- **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:** 9 Dec 2023
- **Updated:** 13 Feb 2025
- **Also known as:** GHSA-9w2p-rh8c-v9g5, OESA-2024-1742, PYSEC-2023-292

## What is CVE-2023-49797?

CVE-2023-49797 is a high-severity vulnerability in pyinstaller, published on 9 Dec 2023. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

PyInstaller bundles a Python application and all its dependencies into a single package. A PyInstaller built application, elevated as a privileged process, may be tricked by an unprivileged attacker into deleting files the unprivileged user does not otherwise have access to. A user is affected if **all** the following are satisfied: 1. The user runs an application containing either `matplotlib` or `win32com`. 2. The application is ran as administrator (or at least a user with higher privileges than the attacker). 3. The user's temporary directory is not locked to that specific user (most likely due to `TMP`/`TEMP` environment variables pointing to an unprotected, arbitrary, non default location). Either: A. The attacker is able to very carefully time the replacement of a temporary file with a symlink. This switch must occur exactly between `shutil.rmtree()`'s builtin symlink check and the deletion itself B: The application was built with Python 3.7.x or earlier which has no protection against Directory Junctions links. The vulnerability has been addressed in PR #7827 which corresponds to `pyinstaller >= 5.13.1`. Users are advised to upgrade. There are no known workarounds for this vulnerability.

Weakness: CWE-732 (Incorrect Permission Assignment for Critical Resource), CWE-379 (Creation of Temporary File in Directory with Insecure Permissions)

## Which versions are affected by CVE-2023-49797?

3 open source packages ship an affected version, including pyinstaller. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `pyinstaller` | PyPI | All versions | 5.13.1 |
| `pyinstaller` | PyPI | All versions | 5.13.1 |
| `pyinstaller` | PyPI | All versions | 5.13.1 |

Products: Pyinstaller Pyinstaller.

## How do I fix CVE-2023-49797?

Upgrade pyinstaller to 5.13.1 or later.

## Is CVE-2023-49797 being exploited?

There is no known exploitation of CVE-2023-49797 in the wild and no public exploit code.

## Other vulnerabilities in pyinstaller

- [CVE-2019-16784](https://insights.sbomify.com/CVE-2019-16784/): Local Privilege Escalation present only on the Windows version of PyInstaller (high 7.0)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-49797 and fix it if it is affected.

What it is: CVE-2023-49797 is a high-severity vulnerability in pyinstaller, published on 9 Dec 2023. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2023-49797 in the wild and no public exploit code.

Affected packages and fixed versions:
- pyinstaller (PyPI): affected all versions; fixed in 5.13.1
- pyinstaller (PyPI): affected all versions; fixed in 5.13.1
- pyinstaller (PyPI): affected all versions; fixed in 5.13.1

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-2023-49797/ (Markdown: https://insights.sbomify.com/CVE-2023-49797/index.md)
```

## Sources

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

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