{
  "id": "python/starlette-trustedhost-invalid-host-header",
  "signature": "starlette.middleware.trustedhost: Invalid host header: 'evil.example.com'",
  "signature_zh": "starlette.middleware.trustedhost: 无效的 Host 头：'evil.example.com'",
  "regex": "starlette\\.middleware\\.trustedhost:\\ Invalid\\ host\\ header:\\ 'evil\\.example\\.com'",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "TrustedHostMiddleware rejects requests whose Host header isn't in allowed_hosts, common behind proxies with wrong host forwarding.",
  "root_cause_type": "generic",
  "root_cause_zh": "TrustedHostMiddleware 拒绝 Host 头不在 allowed_hosts 中的请求，常见于代理未正确转发 Host。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Disables the protection entirely, defeating the middleware purpose.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Reopens host header injection and loses the security control.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.88,
      "how": "Configure proxy to forward Host, and list real hosts:\napp.add_middleware(TrustedHostMiddleware, allowed_hosts=['api.example.com'])",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.82,
      "how": "Use ProxyHeadersMiddleware/forwarded headers in the ASGI server config.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-02-11",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}