python
auth_error
ai_generated
true
BadRequest: CSRF 令牌缺失。
BadRequest: The CSRF token is missing.
ID: python/flask-form-csrf-token-missing
80%修复率
88%置信度
0证据数
2024-03-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
启用了 Flask-WTF CSRFProtect,但 HTML 表单缺少 {{ csrf_token() }} 或 AJAX 请求缺少 X-CSRFToken 头。
English
Flask-WTF CSRFProtect is enabled but the HTML form lacks {{ csrf_token() }} or the AJAX request omits the X-CSRFToken header.
解决方案
-
93% 成功率
In template: <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"> -
90% 成功率
In AJAX: headers: {'X-CSRFToken': getCookie('csrf_token')}
无效尝试
常见但无效的做法:
-
30% 失败
Disables CSRF protection entirely; security risk.
-
70% 失败
Flask-WTF looks for form field or header, not JSON.