Zum Inhalt springen

JWT No Validation (ARCH5126)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key go.security.jwt-no-validation · Severity error · Category security · CWE CWE-347

Decoding a JWT without verifying its signature (ParseUnverified or accepting alg: none) lets an attacker freely tamper with the claims. The signature must always be validated.

token, _, _ := new(jwt.Parser).ParseUnverified(
tokenString, jwt.MapClaims{})
claims := token.Claims.(jwt.MapClaims)
token, err := jwt.Parse(tokenString, func(t *jwt.Token) (any, error) {
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, errors.New("unexpected alg")
}
return signingKey, nil
})

Verify the signature with Parse and explicitly check the expected signing algorithm.