Skip to content

Commit

Permalink
fix: maintain backward compatibility for asymmetric JWTs (supabase#1690)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?
* Use the original value of `GOTRUE_JWT_SECRET` - no need to check for
base64 decoding.
* Don't include the kid claim if the kid is an empty string

## What is the current behavior?

Please link any relevant issues here.

## What is the new behavior?

Feel free to include screenshots if it includes visual changes.

## Additional context

Add any other context or screenshots.
  • Loading branch information
kangmingtay authored Jul 29, 2024
1 parent ae091aa commit 0ad1402
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 3 additions & 2 deletions internal/api/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,9 @@ func (a *API) generateAccessToken(r *http.Request, tx *storage.Connection, user
}

if _, ok := token.Header["kid"]; !ok {
kid := signingJwk.KeyID()
token.Header["kid"] = kid
if kid := signingJwk.KeyID(); kid != "" {
token.Header["kid"] = kid
}
}

// this serializes the aud claim to a string
Expand Down
6 changes: 1 addition & 5 deletions internal/conf/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,7 @@ func (config *GlobalConfiguration) ApplyDefaults() error {

if config.JWT.Keys == nil || len(config.JWT.Keys) == 0 {
// transform the secret into a JWK for consistency
bytes, err := base64.StdEncoding.DecodeString(config.JWT.Secret)
if err != nil {
bytes = []byte(config.JWT.Secret)
}
privKey, err := jwk.FromRaw(bytes)
privKey, err := jwk.FromRaw([]byte(config.JWT.Secret))
if err != nil {
return err
}
Expand Down

0 comments on commit 0ad1402

Please sign in to comment.