# CVE-2024-4030: tempfile.mkdtemp() may be readable and writeable by all users on Windows

> On Windows, tempfile.mkdtemp() may create directories with overly permissive access rights, allowing other users to read or modify temporary files.

- **Severity:** High 7.1 (`CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N`)
- **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:** 7 May 2024
- **Updated:** 7 Sep 2024
- **Also known as:** BIT-python-2024-4030, GHSA-2w87-6hh6-mqrj, PSF-2024-3, openSUSE-SU-2024:14331-1

## What is CVE-2024-4030?

CVE-2024-4030 is a high-severity vulnerability in CPython, published on 7 May 2024. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

On Windows a directory returned by tempfile.mkdtemp() would not always have permissions set to restrict reading and writing to the temporary directory by other users, instead usually inheriting the correct permissions from the default location. Alternate configurations or users without a profile directory may not have the intended permissions.

If you’re not using Windows or haven’t changed the temporary directory location then you aren’t affected by this vulnerability. On other platforms the returned directory is consistently readable and writable only by the current user.

This issue was caused by Python not supporting Unix permissions on Windows. The fix adds support for Unix “700” for the mkdir function on Windows which is used by mkdtemp() to ensure the newly created directory has the proper permissions.

Weakness: CWE-276 (Incorrect Default Permissions)

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

1 open source package ship an affected version, including python.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `python` | Bitnami | All versions | 3.12.4 |
| `python39` | openSUSE:Tumbleweed | All versions | 3.9.20-1.1 |

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

Upgrade python to 3.12.4 or later.

## Is CVE-2024-4030 being exploited?

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

## Fix prompt for AI coding agents

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

What it is: CVE-2024-4030 is a high-severity vulnerability in CPython, published on 7 May 2024. 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-2024-4030 in the wild and no public exploit code.

Affected packages and fixed versions:
- python (Bitnami): affected all versions; fixed in 3.12.4

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

## Sources

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

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