{
  "id": "security/csrf-token-missing-in-ajax-request",
  "signature": "CSRF token missing in AJAX request header",
  "signature_zh": "AJAX请求头中缺少CSRF令牌",
  "regex": "CSRF token missing|X-CSRF-Token.*undefined|Forbidden.*CSRF",
  "domain": "security",
  "category": "auth_error",
  "subcategory": null,
  "root_cause": "The frontend JavaScript code does not include the CSRF token in the X-CSRF-Token header for AJAX requests, so the server-side middleware rejects the request with a 403 status.",
  "root_cause_type": "generic",
  "root_cause_zh": "前端JavaScript代码未在AJAX请求的X-CSRF-Token头中包含CSRF令牌，导致服务端中间件以403状态拒绝请求。",
  "versions": [
    {
      "version": "Django 4.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Spring Security 6.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Rails 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Disabling CSRF protection globally in the framework removes a critical security control, making the application vulnerable to CSRF attacks.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Only adding the token to form submissions but not to AJAX requests leaves the AJAX endpoints unprotected.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Placing the token in a query parameter instead of a header can leak it in server logs and browser history.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "In the frontend, add a global AJAX setup to include the CSRF token. For jQuery: $.ajaxSetup({ headers: { 'X-CSRF-Token': $('meta[name=\"csrf-token\"]').attr('content') } })",
      "success_rate": 0.95,
      "how": "In the frontend, add a global AJAX setup to include the CSRF token. For jQuery: $.ajaxSetup({ headers: { 'X-CSRF-Token': $('meta[name=\"csrf-token\"]').attr('content') } })",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure the meta tag containing the CSRF token is rendered in the HTML template and is accessible to the JavaScript code.",
      "success_rate": 0.9,
      "how": "Ensure the meta tag containing the CSRF token is rendered in the HTML template and is accessible to the JavaScript code.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a fetch wrapper that automatically adds the CSRF header from a cookie or meta tag to all requests.",
      "success_rate": 0.85,
      "how": "Use a fetch wrapper that automatically adds the CSRF header from a cookie or meta tag to all requests.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在前端，添加全局AJAX设置以包含CSRF令牌。对于jQuery：$.ajaxSetup({ headers: { 'X-CSRF-Token': $('meta[name=\"csrf-token\"]').attr('content') } })",
    "确保包含CSRF令牌的meta标签在HTML模板中渲染，并且JavaScript代码可以访问它。",
    "使用自动从cookie或meta标签添加CSRF头到所有请求的fetch包装器。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://owasp.org/www-community/attacks/csrf",
  "official_doc_section": null,
  "error_code": "403",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}