Description
In golang-jwt/jwt/v5, Parser.ParseUnverified reads the JWT header and claims without verifying the signature. The returned Token.Valid is false.
Conditions for unverified parsing
Both parser forms call ParseUnverified. Use it only when the same token’s signature has already been verified or will be verified independently before you rely on its claims.
parser := jwt.NewParser()
parser.ParseUnverified(rawToken, jwt.MapClaims{})
parser = &jwt.Parser{}
parser.ParseUnverified(rawToken, jwt.MapClaims{})
The verification example uses github.com/golang-jwt/jwt/v5. Check support and API differences for older major versions or github.com/dgrijalva/jwt-go.
Potential impact
Trusting an unverified sub, role or permission can grant someone another user’s access. Unverified alg or kid values can also influence key or algorithm selection. Versions before v5.2.2 can allocate excessive memory while parsing a token (CVE-2025-30204).
Remediation
- Use
jwt.Parseorjwt.ParseWithClaims. Use claims only when there is no error, the token is non-nil andValidistrue. - Restrict algorithms with
jwt.WithValidMethods. Load the key from trusted configuration or a validated JWKS. - Check required claims with
jwt.WithExpirationRequired,jwt.WithIssuer,jwt.WithAudienceorjwt.WithAllAudiencesas appropriate. Usejwt.WithLeewayonly for a defined clock-skew allowance. - Use a maintained v5 release, 5.3.1 or later, and apply security updates. Version 5.2.2 was the first fix for the memory issue above.
Examples
Before
func unverifiedClaims(r *http.Request) (jwt.MapClaims, error) {
rawToken := r.FormValue("token")
token, _, err := jwt.NewParser().ParseUnverified(rawToken, jwt.MapClaims{})
if err != nil {
return nil, err
}
return token.Claims.(jwt.MapClaims), nil
}
This function returns claims from the request’s rawToken without verifying them.
After
func verifiedToken(rawToken string, verificationKey *rsa.PublicKey) (*jwt.Token, error) {
token, err := jwt.Parse(
rawToken,
func(token *jwt.Token) (any, error) {
// Select the key from trusted issuer configuration
// or a validated JWKS cache in production.
return verificationKey, nil
},
jwt.WithValidMethods([]string{jwt.SigningMethodRS256.Alg()}),
jwt.WithExpirationRequired(),
jwt.WithIssuer("https://issuer.example"),
jwt.WithAudience("api.example"),
)
if err != nil {
return nil, fmt.Errorf("JWT verification failed: %w", err)
}
if token == nil || !token.Valid {
return nil, errors.New("invalid JWT")
}
return token, nil
}
The example verifies RS256 with a trusted RSA public key and checks expiration, issuer and audience. Apply the same options and key policy to jwt.ParseWithClaims for custom claims.
References
golang-jwt/jwt/v5package documentationParser.ParseUnverifiedAPI documentationgolang-jwt/jwtreleases- CVE-2025-30204 / GHSA-mh63-6h87-95cp
- CodeQL: Missing JWT signature check
- RFC 8725: JSON Web Token Best Current Practices
- CWE-347: Improper Verification of Cryptographic Signature
- OWASP Top 10:2025 A04 Cryptographic Failures