A JWT Keyfunc returns the verification key without checking token.Method, enabling algorithm confusion.
Why AI tools produce this: AI coding tools generate this anti-pattern by default, it appears in a large share of AI-written auth code.
Why this matters
It is passed to jwt.Parse/jwt.ParseWithClaims and hands back the key without first asserting the signing algorithm. If the server verifies RS256 tokens with an RSA public key, an attacker can forge an HS256 token using that public key as the HMAC secret, and the library will accept it: a complete authentication bypass (CWE-347).
Always assert the signing method inside the keyfunc before returning the key, e.g.: if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok { return nil, err } (or *jwt.SigningMethodRSA / *jwt.SigningMethodECDSA as appropriate), so a token signed with an unexpected algorithm is rejected.
Suppressing this rule
If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.
// oauthlint-disable-next-line auth.go.jwt.unchecked-method -- <reason>