{
  "id": "security/oauth2-authorization-code-reuse-detection",
  "signature": "OAuth2 authorization code reuse detected: same authorization code used more than once",
  "signature_zh": "OAuth2授权码重用检测到：同一授权码被多次使用",
  "regex": "(authorization code.*reuse|code.*already.*used|duplicate authorization code)",
  "domain": "security",
  "category": "auth_error",
  "subcategory": null,
  "root_cause": "The authorization server fails to properly mark authorization codes as consumed after first use, allowing an attacker to replay a previously intercepted code to obtain a new access token.",
  "root_cause_type": "generic",
  "root_cause_zh": "授权服务器未能正确标记授权码在首次使用后已消耗，允许攻击者重放之前截获的授权码以获取新的访问令牌。",
  "versions": [
    {
      "version": "Spring Security OAuth2 2.5.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Keycloak 21.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Okta 2024.02.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Longer expiration times actually increase the window for replay attacks, making the problem worse.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Authorization codes are randomly generated and not meant to be guessed; the issue is replay, not brute force.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Manual review is not scalable and cannot prevent real-time attacks; automated detection must be implemented.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure the authorization server marks the code as consumed atomically upon first use. For example, in a database-backed implementation, use a transaction: UPDATE auth_codes SET consumed=true WHERE code=? AND consumed=false. If affected rows is 0, reject the request.",
      "success_rate": 0.95,
      "how": "Ensure the authorization server marks the code as consumed atomically upon first use. For example, in a database-backed implementation, use a transaction: UPDATE auth_codes SET consumed=true WHERE code=? AND consumed=false. If affected rows is 0, reject the request.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Implement a one-time use token pattern: after issuing the access token, immediately invalidate the authorization code from the store (e.g., Redis: DEL auth_code:<code>).",
      "success_rate": 0.9,
      "how": "Implement a one-time use token pattern: after issuing the access token, immediately invalidate the authorization code from the store (e.g., Redis: DEL auth_code:<code>).",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a nonce or state parameter that must be unique per authorization request and validated during token exchange, preventing replay even if the code is intercepted.",
      "success_rate": 0.85,
      "how": "Add a nonce or state parameter that must be unique per authorization request and validated during token exchange, preventing replay even if the code is intercepted.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure the authorization server marks the code as consumed atomically upon first use. For example, in a database-backed implementation, use a transaction: UPDATE auth_codes SET consumed=true WHERE code=? AND consumed=false. If affected rows is 0, reject the request.",
    "Implement a one-time use token pattern: after issuing the access token, immediately invalidate the authorization code from the store (e.g., Redis: DEL auth_code:<code>).",
    "Add a nonce or state parameter that must be unique per authorization request and validated during token exchange, preventing replay even if the code is intercepted."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://datatracker.ietf.org/doc/html/rfc6749#section-10.5",
  "official_doc_section": null,
  "error_code": "invalid_grant",
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "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": []
}