Skip to content

Commit

Permalink
fix: show error page on identity mismatch (#3790)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Mar 4, 2024
1 parent dfc931f commit e6db689
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion continuity/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *Container) Valid(identity uuid.UUID) error {
}

if identity != uuid.Nil && pointerx.Deref(c.IdentityID) != identity {
return errors.WithStack(herodot.ErrBadRequest.WithReasonf("You must restart the flow because the resumable session was initiated by another person."))
return errors.WithStack(herodot.ErrForbidden.WithReasonf("The flow has been blocked for security reasons because it was initiated by another person.."))
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions selfservice/flow/settings/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func (f *Flow) Valid(s *session.Session) error {
}

if f.IdentityID != s.Identity.ID {
return errors.WithStack(herodot.ErrBadRequest.WithID(text.ErrIDInitiatedBySomeoneElse).WithReasonf(
"You must restart the flow because the resumable session was initiated by another person."))
return errors.WithStack(herodot.ErrForbidden.WithID(text.ErrIDInitiatedBySomeoneElse).WithReasonf(
"The request was initiated by someone else and has been blocked for security reasons. Please go back and try again."))
}

return nil
Expand Down
12 changes: 6 additions & 6 deletions selfservice/flow/settings/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ func TestHandler(t *testing.T) {
require.NoError(t, json.Unmarshal(body, &f))

actual, res := testhelpers.SettingsMakeRequest(t, true, false, &f, user2, `{"method":"not-exists"}`)
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
assert.Equal(t, "You must restart the flow because the resumable session was initiated by another person.", gjson.Get(actual, "ui.messages.0.text").String(), actual)
assert.Equal(t, http.StatusForbidden, res.StatusCode)
assert.Equal(t, "The request was initiated by someone else and has been blocked for security reasons. Please go back and try again.", gjson.Get(actual, "error.reason").String(), actual)
})

t.Run("type=spa", func(t *testing.T) {
Expand All @@ -556,8 +556,8 @@ func TestHandler(t *testing.T) {
require.NoError(t, json.Unmarshal(body, &f))

actual, res := testhelpers.SettingsMakeRequest(t, false, true, &f, user2, `{"method":"not-exists"}`)
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
assert.Equal(t, "You must restart the flow because the resumable session was initiated by another person.", gjson.Get(actual, "ui.messages.0.text").String(), actual)
assert.Equal(t, http.StatusForbidden, res.StatusCode)
assert.Equal(t, "The request was initiated by someone else and has been blocked for security reasons. Please go back and try again.", gjson.Get(actual, "error.reason").String(), actual)
})

t.Run("type=browser", func(t *testing.T) {
Expand All @@ -568,8 +568,8 @@ func TestHandler(t *testing.T) {
require.NoError(t, json.Unmarshal(body, &f))

actual, res := testhelpers.SettingsMakeRequest(t, false, false, &f, user2, `{"method":"not-exists"}`)
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
assert.Equal(t, "You must restart the flow because the resumable session was initiated by another person.", gjson.Get(actual, "ui.messages.0.text").String(), actual)
assert.Equal(t, http.StatusForbidden, res.StatusCode)
assert.Equal(t, "The request was initiated by someone else and has been blocked for security reasons. Please go back and try again.", gjson.Get(actual, "error.reason").String(), actual)
})
})

Expand Down
10 changes: 5 additions & 5 deletions selfservice/strategy/password/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ func TestSettings(t *testing.T) {
values.Set("method", "password")
values.Set("password", x.NewUUID().String())
actual, res := testhelpers.SettingsMakeRequest(t, true, false, f, apiUser2, testhelpers.EncodeFormAsJSON(t, true, values))
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "ui.messages.0.text").String(), "initiated by another person", "%s", actual)
assert.Equal(t, http.StatusForbidden, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "error.reason").String(), "initiated by someone else", "%s", actual)
})

t.Run("type=spa", func(t *testing.T) {
Expand All @@ -212,8 +212,8 @@ func TestSettings(t *testing.T) {
values.Set("method", "password")
values.Set("password", x.NewUUID().String())
actual, res := testhelpers.SettingsMakeRequest(t, false, true, f, browserUser2, values.Encode())
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "ui.messages.0.text").String(), "initiated by another person", "%s", actual)
assert.Equal(t, http.StatusForbidden, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "error.reason").String(), "initiated by someone else", "%s", actual)
})

t.Run("type=browser", func(t *testing.T) {
Expand All @@ -223,7 +223,7 @@ func TestSettings(t *testing.T) {
values.Set("password", x.NewUUID().String())
actual, res := testhelpers.SettingsMakeRequest(t, false, false, f, browserUser2, values.Encode())
assert.Equal(t, http.StatusOK, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "ui.messages.0.text").String(), "initiated by another person", "%s", actual)
assert.Contains(t, gjson.Get(actual, "reason").String(), "initiated by someone else", "%s", actual)
})
})

Expand Down
10 changes: 5 additions & 5 deletions selfservice/strategy/profile/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,17 @@ func TestStrategyTraits(t *testing.T) {

values := testhelpers.SDKFormFieldsToURLValues(f.Ui.Nodes)
actual, res := testhelpers.SettingsMakeRequest(t, true, false, f, apiUser2, testhelpers.EncodeFormAsJSON(t, true, values))
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "ui.messages.0.text").String(), "initiated by another person", "%s", actual)
assert.Equal(t, http.StatusForbidden, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "error.reason").String(), "initiated by someone else", "%s", actual)
})

t.Run("type=spa", func(t *testing.T) {
f := testhelpers.InitializeSettingsFlowViaAPI(t, browserUser1, publicTS)

values := testhelpers.SDKFormFieldsToURLValues(f.Ui.Nodes)
actual, res := testhelpers.SettingsMakeRequest(t, false, true, f, browserUser2, testhelpers.EncodeFormAsJSON(t, true, values))
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "ui.messages.0.text").String(), "initiated by another person", "%s", actual)
assert.Equal(t, http.StatusForbidden, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "error.reason").String(), "initiated by someone else", "%s", actual)
})

t.Run("type=browser", func(t *testing.T) {
Expand All @@ -294,7 +294,7 @@ func TestStrategyTraits(t *testing.T) {
values := testhelpers.SDKFormFieldsToURLValues(f.Ui.Nodes)
actual, res := testhelpers.SettingsMakeRequest(t, false, false, f, browserUser2, values.Encode())
assert.Equal(t, http.StatusOK, res.StatusCode)
assert.Contains(t, gjson.Get(actual, "ui.messages.0.text").String(), "initiated by another person", "%s", actual)
assert.Contains(t, gjson.Get(actual, "reason").String(), "initiated by someone else", "%s", actual)
})
})

Expand Down

0 comments on commit e6db689

Please sign in to comment.