-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: remove flow cookie #3639
Merged
Merged
feat: remove flow cookie #3639
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1c238cd
feat: remove flow cookie
hperl f3b99b1
test: add test for consent double-submit
hperl fbe203c
test: fix error message test
hperl 0806721
Revert "chore(deps): bump @cypress/request and cypress (#3641)"
hperl 606c405
fix: proper errors for double-submit
hperl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -480,17 +480,13 @@ func ManagerTests(deps Deps, m Manager, clientManager client.Manager, fositeMana | |
|
||
loginVerifier := x.Must(f.ToLoginVerifier(ctx, deps)) | ||
|
||
got2, err := m.VerifyAndInvalidateLoginRequest(ctx, f, loginVerifier) | ||
got2, err := m.VerifyAndInvalidateLoginRequest(ctx, loginVerifier) | ||
require.NoError(t, err) | ||
compareAuthenticationRequest(t, c, got2.LoginRequest) | ||
|
||
_, err = m.VerifyAndInvalidateLoginRequest(ctx, nil, loginVerifier) | ||
require.Error(t, err) | ||
|
||
loginChallenge = x.Must(f.ToLoginChallenge(ctx, deps)) | ||
got1, err = m.GetLoginRequest(ctx, loginChallenge) | ||
require.NoError(t, err) | ||
assert.True(t, got1.WasHandled) | ||
}) | ||
} | ||
}) | ||
|
@@ -544,32 +540,23 @@ func ManagerTests(deps Deps, m Manager, clientManager client.Manager, fositeMana | |
|
||
consentVerifier := x.Must(f.ToConsentVerifier(ctx, deps)) | ||
|
||
got2, err := m.VerifyAndInvalidateConsentRequest(ctx, f, consentVerifier) | ||
got2, err := m.VerifyAndInvalidateConsentRequest(ctx, consentVerifier) | ||
require.NoError(t, err) | ||
consentRequest.ID = f.ConsentChallengeID.String() | ||
consentRequest.ID = got2.ID | ||
compareConsentRequest(t, consentRequest, got2.ConsentRequest) | ||
assert.Equal(t, consentRequest.ID, got2.ID) | ||
assert.Equal(t, h.GrantedAudience, got2.GrantedAudience) | ||
|
||
// Trying to update this again should return an error because the consent request was used. | ||
h.GrantedAudience = sqlxx.StringSliceJSONFormat{"new-audience", "new-audience-2"} | ||
_, err = m.HandleConsentRequest(ctx, f, h) | ||
require.Error(t, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it ok to remove this assertion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we can't detect double submit any more. |
||
t.Run("sub=detect double-submit for consent verifier", func(t *testing.T) { | ||
_, err := m.VerifyAndInvalidateConsentRequest(ctx, consentVerifier) | ||
require.Error(t, err) | ||
}) | ||
|
||
if tc.hasError { | ||
assert.True(t, got2.HasError()) | ||
} | ||
assert.Equal(t, tc.remember, got2.Remember) | ||
assert.Equal(t, tc.rememberFor, got2.RememberFor) | ||
|
||
_, err = m.VerifyAndInvalidateConsentRequest(ctx, f, makeID("verifier", network, tc.key)) | ||
require.Error(t, err) | ||
|
||
// Because we don't persist the flow any more, we can't check for this. | ||
//got1, err = m.GetConsentRequest(ctx, consentChallenge) | ||
//require.NoError(t, err) | ||
//assert.True(t, got1.WasHandled) | ||
|
||
}) | ||
} | ||
|
||
|
@@ -648,6 +635,7 @@ func ManagerTests(deps Deps, m Manager, clientManager client.Manager, fositeMana | |
challengerv1 := makeID("challenge", network, "rv1") | ||
challengerv2 := makeID("challenge", network, "rv2") | ||
t.Run("case=revoke-used-consent-request", func(t *testing.T) { | ||
|
||
cr1, hcr1, f1 := MockConsentRequest("rv1", false, 0, false, false, false, "fk-login-challenge", network) | ||
cr2, hcr2, f2 := MockConsentRequest("rv2", false, 0, false, false, false, "fk-login-challenge", network) | ||
f1.NID = deps.Contextualizer().Network(context.Background(), gofrsuuid.Nil) | ||
|
@@ -666,30 +654,30 @@ func ManagerTests(deps Deps, m Manager, clientManager client.Manager, fositeMana | |
_, err = m.HandleConsentRequest(ctx, f2, hcr2) | ||
require.NoError(t, err) | ||
|
||
_, err = m.VerifyAndInvalidateConsentRequest(ctx, f1, x.Must(f1.ToConsentVerifier(ctx, deps))) | ||
crr1, err := m.VerifyAndInvalidateConsentRequest(ctx, x.Must(f1.ToConsentVerifier(ctx, deps))) | ||
require.NoError(t, err) | ||
_, err = m.VerifyAndInvalidateConsentRequest(ctx, f2, x.Must(f2.ToConsentVerifier(ctx, deps))) | ||
crr2, err := m.VerifyAndInvalidateConsentRequest(ctx, x.Must(f2.ToConsentVerifier(ctx, deps))) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, fositeManager.CreateAccessTokenSession( | ||
ctx, | ||
makeID("", network, "trva1"), | ||
&fosite.Request{Client: cr1.Client, ID: f1.ConsentChallengeID.String(), RequestedAt: time.Now()}, | ||
&fosite.Request{Client: cr1.Client, ID: crr1.ID, RequestedAt: time.Now()}, | ||
)) | ||
require.NoError(t, fositeManager.CreateRefreshTokenSession( | ||
ctx, | ||
makeID("", network, "rrva1"), | ||
&fosite.Request{Client: cr1.Client, ID: f1.ConsentChallengeID.String(), RequestedAt: time.Now()}, | ||
&fosite.Request{Client: cr1.Client, ID: crr1.ID, RequestedAt: time.Now()}, | ||
)) | ||
require.NoError(t, fositeManager.CreateAccessTokenSession( | ||
ctx, | ||
makeID("", network, "trva2"), | ||
&fosite.Request{Client: cr2.Client, ID: f2.ConsentChallengeID.String(), RequestedAt: time.Now()}, | ||
&fosite.Request{Client: cr2.Client, ID: crr2.ID, RequestedAt: time.Now()}, | ||
)) | ||
require.NoError(t, fositeManager.CreateRefreshTokenSession( | ||
ctx, | ||
makeID("", network, "rrva2"), | ||
&fosite.Request{Client: cr2.Client, ID: f2.ConsentChallengeID.String(), RequestedAt: time.Now()}, | ||
&fosite.Request{Client: cr2.Client, ID: crr2.ID, RequestedAt: time.Now()}, | ||
)) | ||
|
||
for i, tc := range []struct { | ||
|
@@ -765,9 +753,9 @@ func ManagerTests(deps Deps, m Manager, clientManager client.Manager, fositeMana | |
require.NoError(t, err) | ||
_, err = m.HandleConsentRequest(ctx, f2, hcr2) | ||
require.NoError(t, err) | ||
handledConsentRequest1, err := m.VerifyAndInvalidateConsentRequest(ctx, f1, x.Must(f1.ToConsentVerifier(ctx, deps))) | ||
handledConsentRequest1, err := m.VerifyAndInvalidateConsentRequest(ctx, x.Must(f1.ToConsentVerifier(ctx, deps))) | ||
require.NoError(t, err) | ||
handledConsentRequest2, err := m.VerifyAndInvalidateConsentRequest(ctx, f2, x.Must(f2.ToConsentVerifier(ctx, deps))) | ||
handledConsentRequest2, err := m.VerifyAndInvalidateConsentRequest(ctx, x.Must(f2.ToConsentVerifier(ctx, deps))) | ||
require.NoError(t, err) | ||
|
||
for i, tc := range []struct { | ||
|
@@ -937,7 +925,7 @@ func ManagerTests(deps Deps, m Manager, clientManager client.Manager, fositeMana | |
f.NID = deps.Contextualizer().Network(ctx, gofrsuuid.Nil) | ||
cr := SaneMockConsentRequest(t, m, f, false) | ||
_ = SaneMockHandleConsentRequest(t, m, f, cr, time.Time{}, 0, false, false) | ||
_, err = m.VerifyAndInvalidateConsentRequest(ctx, f, x.Must(f.ToConsentVerifier(ctx, deps))) | ||
_, err = m.VerifyAndInvalidateConsentRequest(ctx, x.Must(f.ToConsentVerifier(ctx, deps))) | ||
require.NoError(t, err) | ||
|
||
sessions[k] = *ls | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this assertion not still be here? The flow was handled so it should be true right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously we persisted the flow in the database, so
VerifyAndInvalidateLoginRequest
setWasHandled
totrue
in the DB. Since we now store the flow in the login verifier, there is no place to store information about whether the flow was already handled.This is already true even without this patch.
If we want double-submit protection, we should build a separate
NonceService
(new
creates a new nonce,use
uses a nonce once) to make sure that the verifiers are only used once.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see - do we protect against double submit for the consent verifier? Or can I generate as many authorization codes as I want with the same consent verifier?
Can I log in as often as I want to using the same login verifier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can log in as often as you want, but the double-submit will be caught at the consent verification step.
I added a test case for consent verifier double submit here: f482f4e