BIT-python-2024-3220: Default mimetype known files writeable on Windows
There is a defect in the CPython standard library module “mimetypes” where on Windows the default list of known file locations are writable meaning other users can create invalid files to cause MemoryError to be raised on Python runtime startup or have file extensions be interpreted as the incorrect file type.
This defect is caused by the default locations of Linux and macOS platforms (such as “/etc/mime.types”) also being used on Windows, where they are user-writable locations (“C:\etc\mime.types”).
To work-around this issue a user can call mimetypes.init() with an empty list (“[]”) on Windows platforms to avoid using the default list of known file locations.
Affected Software
Event History
Frequently Asked Questions
Who is realistically exposed to this issue?
Windows systems running CPython are affected when the mimetypes module uses its default known-file locations. The issue depends on other users being able to create or alter files at Windows paths derived from locations such as C:\etc\mime.types.
What does an attacker need to exploit it?
An attacker needs the ability to create an invalid mime.types file in one of the default locations that is writable on Windows. Exploitation does not require interaction from the Python application once the affected runtime initializes mimetypes using those locations.
What can be done if patching is not immediately possible?
On Windows, call mimetypes.init([]) to prevent the module from using the default list of known file locations. This avoids loading files from the user-writable paths implicated by the issue.
How could this issue affect an application?
A malicious file can cause a MemoryError during Python runtime startup or cause file extensions to be interpreted as an incorrect MIME type. The integrity and availability effects are limited in the provided severity vector.