CVE-2021-33890: jwt-go string-typed exp/nbf/iat validation bypass
jwt-go's MapClaims treats string-typed exp, nbf, and iat claims as absent, and therefore valid (these claims are optional per RFC 7519). A token carrying "exp": "1300819380" (a string where the RFC requires a number) therefore passes validation despite being expired. The affected functions are VerifyExpiresAt, VerifyNotBefore, and VerifyIssuedAt.
Affected versions:
- dgrijalva/jwt-go: up to v3.2.0, its last release. The repository was superseded during disclosure in 2021 and is currently archived. The replacement is golang-jwt/jwt.
- form3tech-oss/jwt-go: up to v3.2.3. Fixed in commit a211650, tag v3.2.4, installable from v3.2.5.
- golang-jwt/jwt: v3.2.1. Fixed in commit 8e9d9eb, released as v3.2.2.
- Anything that validates tokens through the vulnerable
MapClaims. This was the case in now-updated middleware such asauth0/go-jwt-middlewareandory/oathkeeper.
The vulnerability is only effective when a trusted issuer serializes timestamps as strings, contrary to RFC 7519. It does not allow token forgery.
This bug was discovered due to an internal tool that issued tokens for end-to-end tests. An ASP.NET Core API rejected its expired tokens while an API behind an affected version of middleware let the same tokens through.
Mechanism
Vulnerable example:
func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
switch exp := m["exp"].(type) {
case float64:
return verifyExp(int64(exp), cmp, req)
case json.Number:
v, _ := exp.Int64()
return verifyExp(v, cmp, req)
}
// ^ string-typed values are considered absent for the optionality check
return req == false
}
Fixed example:
func (m MapClaims) VerifyExpiresAt(cmp int64, req bool) bool {
// Optionality check verifies key presence
exp, ok := m["exp"]
if !ok {
return !req
}
switch expType := exp.(type) {
case float64:
return verifyExp(int64(expType), cmp, req)
case json.Number:
v, _ := expType.Int64()
return verifyExp(v, cmp, req)
}
// string-typed values are rejected
return false
}
Disclosure timeline
- 2021-06-06: MITRE assigns CVE-2021-33890.
- 2021-06-08: Reported to the maintainers of the affected projects.
- 2021-06-25: Fixed in form3tech-oss/jwt-go (PR 14, v3.2.4).
- 2021-06-28: dgrijalva/jwt-go's README declares it unmaintained.
- 2021-07-30: Fixed in golang-jwt/jwt (PR 40, v3.2.2).
- 2021-09-19: Issue 482 opened at dgrijalva/jwt-go.
- 2022-05-13: Confirmed in golang-jwt/jwt issue 185 that PR 40 fixes CVE-2021-33890.
- 2022-05-21: dgrijalva/jwt-go archived unfixed.
- 2026-11-17: Details published in this post.