CVE-2021-32677
Cross-Site Request Forgery (CSRF) in FastAPI
Check your servers for CVE-2021-32677
The Vulnpocalypse collector sends the package list of each Linux server and of its container images once a day. Vulnpocalypse shows every server where CVE-2021-32677 affects fastapi, with the command that installs the fix. The free plan covers one server and one domain and does not need a credit card.
Description
FastAPI is a web framework for building APIs with Python 3.6+ based on standard Python type hints. FastAPI versions lower than 0.65.2 that used cookies for authentication in path operations that received JSON payloads sent by browsers were vulnerable to a Cross-Site Request Forgery (CSRF) attack. In versions lower than 0.65.2, FastAPI would try to read the request payload as JSON even if the content-type header sent was not set to application/json or a compatible JSON media type (e.g. application/geo+json). A request with a content type of text/plain containing JSON data would be accepted and the JSON data would be extracted. Requests with content type text/plain are exempt from CORS preflights, for being considered Simple requests. The browser will execute them right away including cookies, and the text content could be a JSON string that would be parsed and accepted by the FastAPI application. This is fixed in FastAPI 0.65.2. The request data is now parsed as JSON only if the content-type header is application/json or another JSON compatible media type like application/geo+json. It's best to upgrade to the latest FastAPI, but if updating is not possible then a middleware or a dependency that checks the content-type header and aborts the request if it is not application/json or another JSON compatible content type can act as a mitigating workaround.
Severity (CVSS)
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N
- Attack vector
- network: an attacker can reach the vulnerable part over the network, often from the internet
- Attack complexity
- low: an attack works without special conditions
- Privileges required
- none: the attacker does not need an account
- User interaction
- none: nobody has to click or open anything
- Scope
- unchanged: the damage stays inside the vulnerable component
- Impact
- confidentiality low, integrity high, availability none: what an attacker can read (confidentiality), change (integrity) or stop (availability)
Exploitation
EPSS 0.72%: the probability of exploitation activity in the next 30 days, from the EPSS model of FIRST. The score is higher than 55.2% of all scored CVEs. Scores of 1 Dec 2026.
Weakness
- CWE-352 Cross-Site Request Forgery
Affected products
As the CNA lists them.
Is my server affected?
Find the installed version of fastapi and compare it with the fixed version of your distribution. Distributions often fix a CVE in a package version of their own, so the version number of the upstream project can mislead.
Debian, Ubuntu
dpkg -l | grep -i fastapi
# packages whose changelog names the CVE (fixed in the installed version)
zgrep -l CVE-2021-32677 /usr/share/doc/*/changelog.Debian.gz
# Ubuntu
pro fix CVE-2021-32677RHEL, Rocky, Alma, Fedora
rpm -q fastapi
# lists the advisory while the fix is not installed
dnf updateinfo list --cve CVE-2021-32677Alpine
apk list --installed | grep -i fastapiWith Trivy, on the host and for a container image. When a package is affected, it prints the installed and the fixed version:
trivy rootfs --scanners vuln / | grep CVE-2021-32677
trivy image --scanners vuln IMAGE | grep CVE-2021-32677
Vulnpocalypse makes this comparison every day for the package lists of your servers and container images, including language packages (npm, PyPI, Go, Maven and others), and sends the command that installs the fix. Start free with one server and one domain or read how to install the collector.
References
Advisories
- https://github.com/tiangolo/fastapi/security/advisories/GHSA-8h2j-cgx8-6xv7 github.com
- FEDORA-2021-917e89c036 lists.fedoraproject.org · vendor advisory
Other references
Source: the record CVE-2021-32677 of the CVE List (CVE Program), CVE Terms of Use; EPSS of FIRST; the CWE catalog of MITRE, CWE Terms of Use. The text of the record is shown as published. Data sources and licences.
Vulnpocalypse