-
-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: accept recovery link from authenticated users (#2195)
When a recovery link is opened while the user already has a session cookie (possibly for another account), the endpoint will now correctly complete the recovery process and issue new cookies. BREAKING CHANGES: Calling /self-service/recovery without flow ID or with an invalid flow ID while authenticated will now respond with an error instead of redirecting to the default page. Closes https://github.com/ory-corp/cloud/issues/2173 Co-authored-by: aeneasr <3372410+aeneasr@users.noreply.github.com>
- Loading branch information
Showing
13 changed files
with
257 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package flow | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/ory/nosurf" | ||
) | ||
|
||
func TestGetCSRFToken(t *testing.T) { | ||
noToken := &mockReg{ | ||
presentToken: "", | ||
regeneratedToken: "regenerated", | ||
} | ||
|
||
tokenPresent := &mockReg{ | ||
presentToken: "existing", | ||
regeneratedToken: "regenerated", | ||
} | ||
|
||
t.Run("case=no token, browser flow", func(t *testing.T) { | ||
assert.Equal(t, "regenerated", GetCSRFToken(noToken, nil, nil, TypeBrowser)) | ||
}) | ||
|
||
t.Run("case=token present, browser flow", func(t *testing.T) { | ||
assert.Equal(t, "existing", GetCSRFToken(tokenPresent, nil, nil, TypeBrowser)) | ||
}) | ||
|
||
t.Run("case=no token, api flow", func(t *testing.T) { | ||
assert.Equal(t, "", GetCSRFToken(noToken, nil, nil, TypeAPI)) | ||
}) | ||
|
||
t.Run("case=token present, api flow", func(t *testing.T) { | ||
assert.Equal(t, "existing", GetCSRFToken(tokenPresent, nil, nil, TypeAPI)) | ||
}) | ||
} | ||
|
||
type mockReg struct { | ||
presentToken, regeneratedToken string | ||
|
||
nosurf.Handler | ||
} | ||
|
||
func (m *mockReg) GenerateCSRFToken(*http.Request) string { | ||
return m.presentToken | ||
} | ||
|
||
func (m *mockReg) CSRFHandler() nosurf.Handler { | ||
return m | ||
} | ||
|
||
func (m *mockReg) RegenerateToken(http.ResponseWriter, *http.Request) string { | ||
return m.regeneratedToken | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.