FastAPI CSRF via text/plain Vulnerability

漏洞信息

漏洞名称: FastAPI CSRF via text/plain Vulnerability

漏洞编号:

  • CVE: CVE-2021-32677

漏洞类型: 跨站请求伪造

漏洞等级: 中危

漏洞描述: FastAPI是一个现代、快速(高性能)的Web框架,用于基于标准Python类型提示构建API。它广泛应用于开发RESTful API和微服务架构。在版本0.65.2之前,FastAPI存在一个跨站请求伪造(CSRF)漏洞,该漏洞源于框架在处理HTTP请求时,即使Content-Type头部被设置为text/plain,也会解析JSON格式的请求体。这一行为允许攻击者通过构造特殊的跨站请求,绕过同源策略(CORS)的限制,执行未授权的操作。具体来说,攻击者可以利用此漏洞,通过恶意网站或脚本发送伪造的请求,模拟用户执行非预期的操作,如更改账户信息或执行其他敏感操作。由于这种攻击不需要用户交互即可自动执行,因此对依赖FastAPI构建的Web应用构成了中等级别的安全威胁。为了防范此类攻击,建议开发者将FastAPI升级至0.65.2或更高版本,以确保框架正确处理Content-Type头部,避免CSRF攻击的发生。

产品厂商: FastAPI

产品名称: FastAPI

影响版本: version < 0.65.2

来源: https://github.com/projectdiscovery/nuclei-templates/blob/e0fa7e8642c0e7274eebcad45d95af9ba4b6785b/http%2Fcves%2F2021%2FCVE-2021-32677.yaml

类型: projectdiscovery/nuclei-templates:github issues

POC详情

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

id: CVE-2021-32677

info:
name: FastAPI < 0.65.2 - CSRF via text/plain
author: oxqnd
severity: medium
description: |
FastAPI versions before 0.65.2 parse JSON bodies even when the content-type is text/plain.
This allows CSRF attacks due to CORS bypass with simple requests.
impact: |
Attacker can send forged requests via cross-site forms or scripts to perform unauthorized actions.
remediation: |
Upgrade to FastAPI 0.65.2 or later.
reference:
- https://github.com/advisories/GHSA-8h2j-cgx8-6xv7
- https://nvd.nist.gov/vuln/detail/CVE-2021-32677
classification:
cve-id: CVE-2021-32677
cwe-id: CWE-352
cvss-score: 4.3
tags: cve,cve2021,fastapi,csrf

http:
- raw:
- |
POST / HTTP/1.1
Host: {{Hostname}}
Content-Type: text/plain

{"username":"csrf_test","password":"csrf_test"}

matchers:
- type: word
words:
- '"username":"csrf_test"'
- '"password":"csrf_test"'
condition: and

- type: status
status:
- 200



FastAPI CSRF via text/plain Vulnerability
http://example.com/2025/08/03/github_3557302352/
作者
lianccc
发布于
2025年8月3日
许可协议