Repository navigation
Record each redeemed authorization code, so one can't mint again once its grant is gone #3206
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
122a41b
Record each redeemed authorization code, so one can't mint again once…
jeremy b45c7df
Point the ledger at #3206
jeremy eff0d09
Remember a code redeemed before redemptions were recorded, once it's …
jeremy ece7739
Merge oauth-token-digests: its migrations can be run again after stop…
jeremy cc5ae8e
Merge oauth-token-digests
jeremy 912fda2
Merge oauth-token-digests into oauth-code-replay-record
jeremy dd4ebd6
Merge oauth-token-digests into oauth-code-replay-record
jeremy 007aaae
Merge oauth-token-digests into oauth-code-replay-record
jeremy 7514dc3
Merge oauth-token-digests into oauth-code-replay-record
jeremy 4835bbc
Merge oauth-token-digests into oauth-code-replay-record
jeremy 2d7f043
Merge oauth-token-digests into oauth-code-replay-record
jeremy 29553f3
Merge oauth-token-digests into oauth-code-replay-record
jeremy 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 hidden or 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 hidden or 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,17 @@ | ||
| # An authorization code that has been redeemed, by its jti. Codes are | ||
| # stateless, and the grant a code minted carries its jti too, but that grant | ||
| # can be destroyed: by a replay of the code, by revocation, by disconnecting | ||
| # the app. This record outlives it, so the code still can't be redeemed again | ||
| # for as long as it could otherwise be presented (RFC 6749 §4.1.2; rubric | ||
| # GP-4, GP-5). | ||
| class Oauth::RedeemedAuthorizationCode < ApplicationRecord | ||
| # Well past the code's 60-second lifetime, as the rubric asks (24 hours past | ||
| # expiry), so a skewed clock or a slow replay is still recognized. | ||
| RETENTION = 25.hours | ||
|
|
||
| scope :stale, -> { where(created_at: ...RETENTION.ago) } | ||
|
|
||
| def self.cleanup | ||
| stale.in_batches.delete_all | ||
| end | ||
| end |
This file contains hidden or 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
14 changes: 14 additions & 0 deletions
14
db/migrate/20261017140000_create_oauth_redeemed_authorization_codes.rb
This file contains hidden or 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,14 @@ | ||
| # A record of every authorization code redeemed, kept past the code's own | ||
| # lifetime, so a code can't be redeemed again once the grant it minted is gone | ||
| # (revoked by a replay, by the person, or by its app). | ||
| class CreateOauthRedeemedAuthorizationCodes < ActiveRecord::Migration[8.2] | ||
| def change | ||
| create_table :oauth_redeemed_authorization_codes, id: :uuid do |t| | ||
|
jeremy marked this conversation as resolved.
jeremy marked this conversation as resolved.
|
||
| t.string :jti, null: false, limit: 36 | ||
| t.datetime :created_at, null: false | ||
|
|
||
| t.index :jti, unique: true | ||
| t.index :created_at | ||
| end | ||
| end | ||
| end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| require "test_helper" | ||
|
|
||
| class Oauth::RedeemedAuthorizationCodeTest < ActiveSupport::TestCase | ||
| test "a jti is recorded once" do | ||
| Oauth::RedeemedAuthorizationCode.create!(jti: "a5f1c0de-0000-4000-8000-000000000001") | ||
|
|
||
| assert_raises(ActiveRecord::RecordNotUnique) do | ||
| Oauth::RedeemedAuthorizationCode.create!(jti: "a5f1c0de-0000-4000-8000-000000000001") | ||
| end | ||
| end | ||
|
|
||
| test "cleanup keeps records well past the code's lifetime, then removes them" do | ||
| kept = travel_to(24.hours.ago) { Oauth::RedeemedAuthorizationCode.create!(jti: "a5f1c0de-0000-4000-8000-000000000002") } | ||
| stale = travel_to(26.hours.ago) { Oauth::RedeemedAuthorizationCode.create!(jti: "a5f1c0de-0000-4000-8000-000000000003") } | ||
|
|
||
| Oauth::RedeemedAuthorizationCode.cleanup | ||
|
|
||
| assert Oauth::RedeemedAuthorizationCode.exists?(kept.id) | ||
| assert_not Oauth::RedeemedAuthorizationCode.exists?(stale.id) | ||
| end | ||
| end |
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.
Uh oh!
There was an error while loading. Please reload this page.