CVE-2022-22817: Pillow Arbitrary Expression Injection Vulnerability
CRITICALCVE-2022-22817 is a CRITICAL (CVSS 9.8) arbitrary expression injection vulnerability (CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')) affecting Pillow libraries in the PyPI ecosystem. The issue involves arbitrary expression injection in pillow. Remediation is available by upgrading affected packages to version 9.0.1.
CVE-2022-22817 at a Glance
Security Impact
CVSS: 9.8
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H).
How to Fix CVE-2022-22817
To remediate this vulnerability, upgrade all affected Pillow dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
pip install pillow>=9.0.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
pip show pillow
How to Check if You Are Affected
To determine whether your Python environment is affected by CVE-2022-22817, inspect your installed packages using pip:
pip show pillow
Analyze the terminal output to locate any version of Pillow in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 9.0.1), your application is affected.
Note: The pip show pillow command checks currently installed packages in your active Python environment.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection'), where the product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component. In Pillow, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2022-22817 Affected Pillow Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
pillow
|
PyPI |
< 9.0.1
|
9.0.1
|
References
Frequently Asked Questions
What is CVE-2022-22817?
Which Pillow versions are affected?
What version fixes CVE-2022-22817?
Is pillow affected?
What is the CVSS score of CVE-2022-22817?
What CWE is associated with CVE-2022-22817?
How can I check PyPI dependencies for CVE-2022-22817?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-8vj2-vxx3-667w",
"modified" : "2024-10-11T20:56:01Z",
"published" : "2022-01-12T20:07:33Z",
"aliases" : [ "CVE-2022-22817" ],
"summary" : "Arbitrary expression injection in Pillow",
"details" : "`PIL.ImageMath.eval` in Pillow before 9.0.0 allows evaluation of arbitrary expressions, such as ones that use the Python exec method `ImageMath.eval(\"exec(exit())\")`.\n\nWhile Pillow 9.0.0 restricted top-level builtins available to PIL.ImageMath.eval(), it did not prevent builtins available to lambda expressions. These are now also restricted in 9.0.1.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H"
}, {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "PyPI",
"name" : "pillow"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "9.0.1"
} ]
} ]
} ],
"references" : [ {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2022-22817"
}, {
"type" : "WEB",
"url" : "https://github.com/python-pillow/Pillow/commit/8531b01d6cdf0b70f256f93092caa2a5d91afc11"
}, {
"type" : "ADVISORY",
"url" : "https://github.com/advisories/GHSA-8vj2-vxx3-667w"
}, {
"type" : "WEB",
"url" : "https://github.com/pypa/advisory-database/tree/main/vulns/pillow/PYSEC-2022-10.yaml"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/python-pillow/Pillow"
}, {
"type" : "WEB",
"url" : "https://lists.debian.org/debian-lts-announce/2022/01/msg00018.html"
}, {
"type" : "WEB",
"url" : "https://lists.debian.org/debian-lts-announce/2024/03/msg00021.html"
}, {
"type" : "WEB",
"url" : "https://pillow.readthedocs.io/en/stable/releasenotes/9.0.0.html#restrict-builtins-available-to-imagemath-eval"
}, {
"type" : "WEB",
"url" : "https://pillow.readthedocs.io/en/stable/releasenotes/9.0.1.html#security"
}, {
"type" : "WEB",
"url" : "https://security.gentoo.org/glsa/202211-10"
}, {
"type" : "WEB",
"url" : "https://www.debian.org/security/2022/dsa-5053"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-74" ],
"severity" : "CRITICAL",
"github_reviewed" : true,
"github_reviewed_at" : "2022-01-11T18:03:44Z",
"nvd_published_at" : "2022-01-10T14:12:00Z"
}
}