Tencent/WeKnora · error
invalid JWK exponent value
Error message
invalid JWK exponent value
What it means
The decoded JWK exponent does not fit in an int64 (big-endian bytes exceed 8 bytes or overflow), so it cannot become the int exponent of an rsa.PublicKey. RFC 7518 exponents are small (typically 65537 = "AQAB"), so this value is not a usable RSA exponent.
Source
Thrown at internal/application/service/user.go:1861
func (k oidcJWK) rsaPublicKey() (*rsa.PublicKey, error) {
if !strings.EqualFold(k.Kty, "RSA") {
return nil, fmt.Errorf("unsupported JWK key type: %s", k.Kty)
}
nBytes, err := decodeJWKBase64(k.N)
if err != nil {
return nil, fmt.Errorf("invalid JWK modulus: %w", err)
}
eBytes, err := decodeJWKBase64(k.E)
if err != nil {
return nil, fmt.Errorf("invalid JWK exponent: %w", err)
}
if len(nBytes) == 0 || len(eBytes) == 0 {
return nil, errors.New("empty JWK modulus or exponent")
}
eInt := new(big.Int).SetBytes(eBytes)
if !eInt.IsInt64() {
return nil, errors.New("invalid JWK exponent value")
}
e := int(eInt.Int64())
if e <= 0 {
return nil, errors.New("invalid JWK exponent value")
}
return &rsa.PublicKey{N: new(big.Int).SetBytes(nBytes), E: e}, nil
}
func (jwks *oidcJWKS) rsaKeyForKid(kid string) (*rsa.PublicKey, error) {
var usable []oidcJWK
for _, k := range jwks.Keys {
if k.Use != "" && !strings.EqualFold(k.Use, "sig") {
continue
}
if k.Kty != "" && !strings.EqualFold(k.Kty, "RSA") {
continue
}
if kid != "" && k.Kid != kid {View on GitHub (pinned to 988cbb0330)
Solutions
- Inspect the 'e' field in the JWKS — it should normally be "AQAB" (65537).
- Re-fetch the JWKS from the provider's canonical jwks_uri.
- Filter out keys with non-standard exponent encodings before use.
- If this is a test, fix the fixture so 'e' decodes to a small positive integer.
Example fix
// before "e": "AAAAAAAAAAAAAAAAAAAAAQAB" // >8 bytes // after "e": "AQAB"
Defensive patterns
Strategy: validation
Validate before calling
eBytes, err := base64.RawURLEncoding.DecodeString(k.E)
if err != nil || len(eBytes) == 0 || len(eBytes) > 8 {
return fmt.Errorf("JWK %q has invalid exponent", k.Kid)
} Type guard
func plausibleExponent(k jwk) bool {
e, err := base64.RawURLEncoding.DecodeString(k.E)
return err == nil && len(e) > 0 && len(e) <= 8
} Prevention
- Expect 'e' to be "AQAB" (65537) in virtually all providers; flag anything else.
- Validate JWK fields when ingesting a JWKS into any local cache.
- Fix test fixtures to use standard exponent encodings.
When it happens
Trigger: decodeJWKBase64(k.E) succeeds but the resulting big.Int does not fit IsInt64() — e.g. 'e' is an absurdly long base64url string in the JWKS entry.
Common situations: Corrupted or maliciously crafted JWKS entries; tests feeding malformed 'e' values; a key with swapped n/e fields.
Related errors
- empty JWK modulus or exponent
- no matching JWKS key for id_token
- JWKS document contains no keys
- OIDC provider returned no user claims
- id_token missing kid and JWKS contains multiple RSA signing
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/7b5ac40d60c4cd2e.
Report an issue: GitHub.