python
auth_error
ai_generated
true
BadRequest: CSRF 令牌缺失。
BadRequest: The CSRF token is missing.
ID: python/flask-wtf-csrf-token-missing
80%修复率
88%置信度
0证据数
2025-05-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.2.x | active | — | — | — |
根因分析
POST/PUT/DELETE 请求缺少 `csrf_token` 表单字段或 `X-CSRFToken` 头,或启用了 CSRFProtect 但模板中未包含令牌。
English
POST/PUT/DELETE request lacks the `csrf_token` form field or `X-CSRFToken` header, or CSRFProtect is enabled without token in template.
解决方案
-
95% 成功率
In template: `<form method="post">{{ csrf_token() }}...` or `<meta name="csrf-token" content="{{ csrf_token() }}">` and send as `X-CSRFToken` header from JS. -
85% 成功率
For APIs using token auth, exempt only token-protected blueprints: `csrf.exempt(api_bp)`.
无效尝试
常见但无效的做法:
-
95% 失败
Removes protection; opens CSRF vulnerability.
-
90% 失败
Same as disabling; negates the extension.