{
  "id": "security/oauth2-jwt-algorithm-confusion-rs256-hs256",
  "signature": "JWT algorithm confusion: RS256 token accepted when HS256 expected",
  "signature_zh": "JWT算法混淆：当期望HS256时接受了RS256令牌",
  "regex": "JWT algorithm confusion|RS256.*HS256|public key.*HMAC secret",
  "domain": "security",
  "category": "auth_error",
  "subcategory": null,
  "root_cause": "The JWT library is configured to accept both RS256 (asymmetric) and HS256 (symmetric) algorithms, allowing an attacker to sign a token with the public key as the HMAC secret, bypassing signature verification.",
  "root_cause_type": "generic",
  "root_cause_zh": "JWT库配置为同时接受RS256（非对称）和HS256（对称）算法，攻击者可以使用公钥作为HMAC密钥对令牌签名，绕过签名验证。",
  "versions": [
    {
      "version": "jsonwebtoken 8.5.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "jjwt 0.11.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PyJWT 2.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Simply disabling HS256 globally breaks legitimate symmetric token use cases in other parts of the system.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Adding a blacklist of known bad keys doesn't address the root cause — the library must enforce a single algorithm per token, not rely on external lists.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Upgrading the JWT library without changing the verification code may not help if the code explicitly passes both algorithms to the verifier.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "In the JWT verification function, explicitly specify the allowed algorithms and reject any token that uses a different one. For example, in Node.js: jwt.verify(token, publicKey, { algorithms: ['RS256'] })",
      "success_rate": 0.9,
      "how": "In the JWT verification function, explicitly specify the allowed algorithms and reject any token that uses a different one. For example, in Node.js: jwt.verify(token, publicKey, { algorithms: ['RS256'] })",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a library that enforces a single algorithm by default, such as jose (v4+) which requires explicit algorithm selection.",
      "success_rate": 0.85,
      "how": "Use a library that enforces a single algorithm by default, such as jose (v4+) which requires explicit algorithm selection.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a check that the 'alg' header is exactly the expected value before calling the verify function, and reject otherwise.",
      "success_rate": 0.8,
      "how": "Add a check that the 'alg' header is exactly the expected value before calling the verify function, and reject otherwise.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在JWT验证函数中，明确指定允许的算法，并拒绝使用不同算法的任何令牌。例如，在Node.js中：jwt.verify(token, publicKey, { algorithms: ['RS256'] })",
    "使用默认强制单一算法的库，例如jose（v4+），它需要显式选择算法。",
    "在调用验证函数之前，添加检查'alg'头是否完全等于预期值的逻辑，否则拒绝。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}