{
  "id": "security/timing-attack-user-enumeration-login",
  "signature": "Login response time differs for valid vs invalid usernames enabling user enumeration",
  "signature_zh": "有效和无效用户名的登录响应时间不同，导致用户枚举",
  "regex": "user enumeration|timing attack|login.*response time",
  "domain": "security",
  "category": "auth_error",
  "subcategory": null,
  "root_cause": "The authentication logic performs a password hash comparison only after a database lookup confirms the user exists, causing a measurable time difference between requests for existing and non-existing usernames.",
  "root_cause_type": "generic",
  "root_cause_zh": "认证逻辑仅在数据库查询确认用户存在后才进行密码哈希比较，导致现有用户名和不存在用户名的请求之间出现可测量的时间差异。",
  "versions": [
    {
      "version": "Node.js 20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Python 3.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Java 17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Adding artificial delays to all responses increases latency for legitimate users and may not fully mask the timing difference if the delay is predictable.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Removing the user existence check entirely breaks the authentication flow and may allow login with any password for non-existent users unless handled carefully.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using a simple sleep() function after a failed login is easily bypassed by attackers who can sample multiple requests and average out the delay.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Always perform a dummy password hash comparison, even when the user does not exist. In Node.js with bcrypt: const hash = user ? user.hash : DUMMY_HASH; await bcrypt.compare(password, hash);",
      "success_rate": 0.9,
      "how": "Always perform a dummy password hash comparison, even when the user does not exist. In Node.js with bcrypt: const hash = user ? user.hash : DUMMY_HASH; await bcrypt.compare(password, hash);",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a constant-time comparison function like crypto.timingSafeEqual for all password checks, and ensure the same code path executes regardless of user existence.",
      "success_rate": 0.85,
      "how": "Use a constant-time comparison function like crypto.timingSafeEqual for all password checks, and ensure the same code path executes regardless of user existence.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement a generic error message for both invalid username and invalid password, and log the specific reason server-side only.",
      "success_rate": 0.8,
      "how": "Implement a generic error message for both invalid username and invalid password, and log the specific reason server-side only.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "即使当用户不存在时，也始终执行虚拟密码哈希比较。在Node.js中使用bcrypt：const hash = user ? user.hash : DUMMY_HASH; await bcrypt.compare(password, hash);",
    "对所有密码检查使用常数时间比较函数，如crypto.timingSafeEqual，并确保无论用户是否存在，都执行相同的代码路径。",
    "对无效用户名和无效密码都实现通用错误消息，并仅在服务器端记录具体原因。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-08-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}