Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V5923. OWASP. Insecure JWT signature...
menu mobile close menu
Analyzing projects
Additional information
toggle menu Contents

V5923. OWASP. Insecure JWT signature verification may lead to an authentication bypass.

Dec 01 2026

The analyzer has detected that the JWT is accepted without reliable signature verification. An attacker can compromise such a token by inserting unauthorized data, such as another user's ID or an administrator role, and bypass authentication.

Vulnerabilities related to incorrect authentication falls under a separate risk category in the OWASP Top 10 Application Security Risks 2025: A07:2025 Authentication Failures.

A JWT consists of three parts, separated by dots: the header, the payload (claims), and the signature. The header and payload are not encrypted; anyone can read and modify them. Only the signature guarantees the token's authenticity; therefore, the data in the token can be trusted only if the signature is verified using the correct key and the correct algorithm.

The example:

func profileHandler(w http.ResponseWriter, r *http.Request) {
  auth := r.Header.Get("Authorization")
  tokenString := strings.TrimPrefix(auth, "Bearer ")

  p := jwt.NewParser()
  token, _, err := p.ParseUnverified(tokenString, jwt.MapClaims{})
  if err != nil {
    http.Error(w, "invalid token", http.StatusUnauthorized)
    return
  }

  claims := token.Claims.(jwt.MapClaims)
  userID, _ := claims["sub"].(string)
  writeProfile(w, userID)
}

The jwt.Parser.ParseUnverified method parses the token from the request header but does not verify its signature. An attacker can take any token, replace the sub value in it, and get another user's data.

The analyzer issues a warning in the following cases:

  • The signature is not verified:
    • the token is parsed using the jwt.Parser.ParseUnverified method;
    • nil is passed instead of the key retrieval function;
    • neither the parsing error nor the Token.Valid field are checked;
    • the payload is decoded manually using base64 and json.Unmarshal.
  • The signature is verified via an insecure key:
    • the key retrieval function returns nil or an empty string;
    • jwt.UnsafeAllowNoneSignatureType as the HMAC secret. The constant allows the none algorithm, that is, an unsigned token or a public key.
    • the public key is used as the HMAC secret. The public key is known to everyone, so anyone can use it to sign a token.
  • The signing algorithm is not validated: the key retrieval function does not access the Token.Method field, and the valid algorithms are not specified by the jwt.WithValidMethods function.

The signing algorithm is specified in the token header, which the attacker controls. If the server does not validate it, an attacker can choose the algorithm it: for example, specify none or sign the token using the HMAC algorithm, using the server's public RSA key as the secret.

The following example uses a key function that does not validate the signing algorithm:

token, err := jwt.Parse(tokenString, func(t *jwt.Token) (any, error) {
  return []byte(os.Getenv("JWT_SECRET")), nil
})

The fixed code, in which the signature is verified and the algorithm is limited:

func profileHandler(w http.ResponseWriter, r *http.Request) {
  auth := r.Header.Get("Authorization")
  tokenString := strings.TrimPrefix(auth, "Bearer ")
  secret := []byte(os.Getenv("JWT_SECRET"))

  keyFunc := func(t *jwt.Token) (any, error) {
    if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
      return nil, errors.New("unexpected signing method")
    }
    return secret, nil
  }

  token, err := jwt.Parse(tokenString, keyFunc)
  if err != nil || !token.Valid {
    http.Error(w, "invalid token", http.StatusUnauthorized)
    return
  }

  claims := token.Claims.(jwt.MapClaims)
  userID, _ := claims["sub"].(string)
  writeProfile(w, userID)
}

Instead of checking t.Method, restrict the algorithms using a parser option:

jwt.WithValidMethods([]string{"HS256"})

This diagnostic rule is classified as: