Skip to content

Commit e6db689

Browse files
authored
fix: show error page on identity mismatch (#3790)
1 parent dfc931f commit e6db689

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

continuity/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (c *Container) Valid(identity uuid.UUID) error {
6363
}
6464

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

6969
return nil

selfservice/flow/settings/flow.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ func (f *Flow) Valid(s *session.Session) error {
199199
}
200200

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

206206
return nil

selfservice/flow/settings/handler_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,8 @@ func TestHandler(t *testing.T) {
544544
require.NoError(t, json.Unmarshal(body, &f))
545545

546546
actual, res := testhelpers.SettingsMakeRequest(t, true, false, &f, user2, `{"method":"not-exists"}`)
547-
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
548-
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)
547+
assert.Equal(t, http.StatusForbidden, res.StatusCode)
548+
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)
549549
})
550550

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

558558
actual, res := testhelpers.SettingsMakeRequest(t, false, true, &f, user2, `{"method":"not-exists"}`)
559-
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
560-
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)
559+
assert.Equal(t, http.StatusForbidden, res.StatusCode)
560+
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)
561561
})
562562

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

570570
actual, res := testhelpers.SettingsMakeRequest(t, false, false, &f, user2, `{"method":"not-exists"}`)
571-
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
572-
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)
571+
assert.Equal(t, http.StatusForbidden, res.StatusCode)
572+
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)
573573
})
574574
})
575575

selfservice/strategy/password/settings_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ func TestSettings(t *testing.T) {
202202
values.Set("method", "password")
203203
values.Set("password", x.NewUUID().String())
204204
actual, res := testhelpers.SettingsMakeRequest(t, true, false, f, apiUser2, testhelpers.EncodeFormAsJSON(t, true, values))
205-
assert.Equal(t, http.StatusBadRequest, res.StatusCode)
206-
assert.Contains(t, gjson.Get(actual, "ui.messages.0.text").String(), "initiated by another person", "%s", actual)
205+
assert.Equal(t, http.StatusForbidden, res.StatusCode)
206+
assert.Contains(t, gjson.Get(actual, "error.reason").String(), "initiated by someone else", "%s", actual)
207207
})
208208

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

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

selfservice/strategy/profile/strategy_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,17 @@ func TestStrategyTraits(t *testing.T) {
275275

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

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

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

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

0 commit comments

Comments
 (0)