-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap access token grant and refresh in transactions.
It's possible to exchange a single grant/refresh token for multiple access tokens. This is definitely _unexpected_ behavior, whether its a vulnerability is a bit murkier. In a highly concurrent environment, it may provide unexpected results to consumers of the API as well. For the initial exchange of grant for access token, using a grant more than once seems to violate Section 4.2.1 [1]: 4.1.2. Authorization Response code The authorization code generated by the authorization server. ...The client MUST NOT use the authorization code more than once. In the transaction, the `lock!` and error raise is the important part to prevent multiple writes concurrently. In ActiveRecord, `lock!` reloads the record after doing a SELECT ... FOR UPDATE so if two parallel requests come, the first one to the DB locks and revokes the token, while the second waits for the lock to be be released, then acquires the lock, reloading the (now revoked) record and raises an error. A side effect of this change is that granting and refreshing tokens is now transactional - a token cannot be granted without also revoking the grant which should improve consistency. [1] https://tools.ietf.org/html/rfc6749#section-4.1.2
- Loading branch information
1 parent
d1312d5
commit 3146f40
Showing
7 changed files
with
63 additions
and
7 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
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