python
auth_error
ai_generated
true
BadRequest: The CSRF token is missing.
ID: python/flask-form-csrf-token-missing
80%Fix Rate
88%Confidence
0Evidence
2024-03-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.x | active | — | — | — |
Root Cause
Flask-WTF CSRFProtect is enabled but the HTML form lacks {{ csrf_token() }} or the AJAX request omits the X-CSRFToken header.
generic中文
启用了 Flask-WTF CSRFProtect,但 HTML 表单缺少 {{ csrf_token() }} 或 AJAX 请求缺少 X-CSRFToken 头。
Workarounds
-
93% success
In template: <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"> -
90% success
In AJAX: headers: {'X-CSRFToken': getCookie('csrf_token')}
Dead Ends
Common approaches that don't work:
-
30% fail
Disables CSRF protection entirely; security risk.
-
70% fail
Flask-WTF looks for form field or header, not JSON.