Skip to content

Commit 42c5270

Browse files
committed
fix: IDToken nonce should not be checked (PS-385)
1 parent 1a70648 commit 42c5270

File tree

4 files changed

+4
-39
lines changed

4 files changed

+4
-39
lines changed

selfservice/strategy/oidc/strategy.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ func (s *Strategy) CompletedAuthenticationMethod(ctx context.Context, _ session.
726726
}
727727
}
728728

729-
func (s *Strategy) processIDToken(w http.ResponseWriter, r *http.Request, provider Provider, idToken, idTokenNonce string) (*Claims, error) {
729+
func (s *Strategy) processIDToken(w http.ResponseWriter, r *http.Request, provider Provider, idToken string) (*Claims, error) {
730730
verifier, ok := provider.(IDTokenVerifier)
731731
if !ok {
732732
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("The provider %s does not support id_token verification", provider.Config().Provider))
@@ -750,14 +750,7 @@ func (s *Strategy) processIDToken(w http.ResponseWriter, r *http.Request, provid
750750
// If the provider does not support nonces, we don't do validation and return the claim.
751751
// This case only applies to Apple, as some of their devices do not support nonces.
752752
// https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_rest_api/authenticating_users_with_sign_in_with_apple
753-
} else if idTokenNonce == "" {
754-
// A nonce was present in the JWT token, but no nonce was submitted in the flow
755-
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("No nonce was provided but is required by the provider"))
756-
} else if idTokenNonce != claims.Nonce {
757-
// The nonce from the JWT token does not match the nonce from the flow.
758-
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("The supplied nonce does not match the nonce from the id_token"))
759-
}
760-
// Nonce checking was successful
753+
}
761754

762755
return claims, nil
763756
}

selfservice/strategy/oidc/strategy_login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (s *Strategy) Login(w http.ResponseWriter, r *http.Request, f *login.Flow,
238238
}
239239

240240
if p.IDToken != "" {
241-
claims, err := s.processIDToken(w, r, provider, p.IDToken, p.IDTokenNonce)
241+
claims, err := s.processIDToken(w, r, provider, p.IDToken)
242242
if err != nil {
243243
return nil, s.handleError(w, r, f, pid, nil, err)
244244
}

selfservice/strategy/oidc/strategy_registration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (s *Strategy) Register(w http.ResponseWriter, r *http.Request, f *registrat
196196
}
197197

198198
if p.IDToken != "" {
199-
claims, err := s.processIDToken(w, r, provider, p.IDToken, p.IDTokenNonce)
199+
claims, err := s.processIDToken(w, r, provider, p.IDToken)
200200
if err != nil {
201201
return s.handleError(w, r, f, pid, nil, err)
202202
}

selfservice/strategy/oidc/strategy_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -800,23 +800,6 @@ func TestStrategy(t *testing.T) {
800800
require.Equal(t, "No nonce was included in the id_token but is required by the provider", gjson.GetBytes(body, "error.reason").String(), "%s", body)
801801
},
802802
},
803-
{
804-
name: "should fail if no nonce is supplied in request",
805-
idToken: `{
806-
"iss": "https://appleid.apple.com",
807-
"sub": "{{sub}}",
808-
"nonce": "{{nonce}}"
809-
}`,
810-
v: func(provider, token, _ string) url.Values {
811-
return url.Values{
812-
"id_token": {token},
813-
"provider": {provider},
814-
}
815-
},
816-
expect: func(t *testing.T, res *http.Response, body []byte) {
817-
require.Equal(t, "No nonce was provided but is required by the provider", gjson.GetBytes(body, "error.reason").String(), "%s", body)
818-
},
819-
},
820803
{
821804
name: "should pass if claims are valid",
822805
idToken: `{
@@ -828,17 +811,6 @@ func TestStrategy(t *testing.T) {
828811
require.NotEmpty(t, gjson.GetBytes(body, "session_token").String(), "%s", body)
829812
},
830813
},
831-
{
832-
name: "nonce mismatch",
833-
idToken: `{
834-
"iss": "https://appleid.apple.com",
835-
"sub": "{{sub}}",
836-
"nonce": "random-nonce"
837-
}`,
838-
expect: func(t *testing.T, res *http.Response, body []byte) {
839-
require.Equal(t, "The supplied nonce does not match the nonce from the id_token", gjson.GetBytes(body, "error.reason").String(), "%s", body)
840-
},
841-
},
842814
} {
843815
tc := tc
844816
t.Run(fmt.Sprintf("flow=registration/case=%s", tc.name), func(t *testing.T) {

0 commit comments

Comments
 (0)