-
-
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
fix: query by hashed signature only on access code table #3593
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3593 +/- ##
==========================================
- Coverage 76.32% 76.24% -0.08%
==========================================
Files 132 132
Lines 9879 9901 +22
==========================================
+ Hits 7540 7549 +9
- Misses 1824 1837 +13
Partials 515 515
|
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 found all the right places, but the hasing only applies to access tokens (and the respective table), not all the other tables (refresh, id, code, pkce, oidc).
persistence/sql/persister_oauth2.go
Outdated
err = sqlcon.HandleError( | ||
p.QueryWithNetwork(ctx). | ||
Where("signature IN (?, ?)", signature, SignatureHash(signature)). | ||
Where("signature = ?", SignatureHash(signature)). |
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.
Where("signature = ?", SignatureHash(signature)). | |
Where("signature = ?", signature). |
persistence/sql/persister_oauth2.go
Outdated
fmt.Sprintf("UPDATE %s SET active=false WHERE signature=? AND nid = ?", OAuth2RequestSQL{Table: sqlTableCode}.TableName()), | ||
signature, | ||
fmt.Sprintf("UPDATE %s SET active = false WHERE signature = ? AND nid = ?", OAuth2RequestSQL{Table: sqlTableCode}.TableName()), | ||
SignatureHash(signature), |
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.
No need to hash because authorization code signatures are not hashed.
@@ -1448,12 +1450,12 @@ func (s *PersisterTestSuite) TestInvalidateAuthorizeCodeSession() { | |||
|
|||
require.NoError(t, r.Persister().InvalidateAuthorizeCodeSession(s.t2, sig)) | |||
actual := persistencesql.OAuth2RequestSQL{Table: "code"} | |||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, sig)) | |||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, persistencesql.SignatureHash(sig))) |
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.
Change not needed.
@@ -1748,10 +1750,10 @@ func (s *PersisterTestSuite) TestRevokeRefreshToken() { | |||
actual := persistencesql.OAuth2RequestSQL{Table: "refresh"} | |||
|
|||
require.NoError(t, r.Persister().RevokeRefreshToken(s.t2, request.ID)) | |||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, signature)) | |||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, persistencesql.SignatureHash(signature))) |
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.
Change not needed.
require.Equal(t, true, actual.Active) | ||
require.NoError(t, r.Persister().RevokeRefreshToken(s.t1, request.ID)) | ||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, signature)) | ||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, persistencesql.SignatureHash(signature))) |
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.
Change not needed.
@@ -1778,10 +1780,10 @@ func (s *PersisterTestSuite) TestRevokeRefreshTokenMaybeGracePeriod() { | |||
} | |||
|
|||
require.NoError(t, store.RevokeRefreshTokenMaybeGracePeriod(s.t2, request.ID, signature)) | |||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, signature)) | |||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, persistencesql.SignatureHash(signature))) |
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.
Change not needed.
require.Equal(t, true, actual.Active) | ||
require.NoError(t, store.RevokeRefreshTokenMaybeGracePeriod(s.t1, request.ID, signature)) | ||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, signature)) | ||
require.NoError(t, r.Persister().Connection(context.Background()).Find(&actual, persistencesql.SignatureHash(signature))) |
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.
Change not needed.
Doesn't this break BC @hperl ? |
This should not not break backwards compatibility. We introduced undconditionally hashing all new access token signatures (before, we hashed only JWT access tokens). We kept the lookup for the raw signature in place so that old access tokens could still be found. Since some time has passed, all current access tokens should have a hashed signature already, so removing the additional lookup for the raw signature can be removed safely. |
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.
LGTM!
So it does have BC implications and those simply don't apply ONLY if you no longer have active tokens in the store. Scenarios where this isn't the case:
Have we verified that there is indeed no active tokens in Ory Network any more that would be affected by this? |
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.
LGTM!
No description provided.