-
Notifications
You must be signed in to change notification settings - Fork 372
Add duplicate claim name detection per RFC 7519 Section 4 #713
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
Open
ydah
wants to merge
10
commits into
jwt:main
Choose a base branch
from
ydah:duplicate_claim_detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a57548
Add duplicate claim name detection per RFC 7519 Section 4
ydah 798b92e
Remove duplicate key detection from JWT.decode API in favor of Encode…
ydah bb1f74c
Update Ruby version requirements and modify CI configurations
ydah 5328698
Lower minimum Ruby version to 2.5 and make JSON duplicate key detecti…
ydah 9e357f2
Remove verbose YARD documentation comments from JWT::JSON class
ydah 730ebdc
Simplify JSON parse logic by consolidating duplicate branching into a…
ydah 22db63a
Add UnsupportedError for unsupported features and update raise_on_dup…
ydah f3365e6
Extract EncodedToken internals into ClaimsContext, SegmentParser, and…
ydah befe5a8
Revert drop 2.5, 2.6 support
ydah ad53ab7
Add conditional guards for duplicate key detection specs based on JSO…
ydah 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
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 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module JWT | ||
| class EncodedToken | ||
| # @private | ||
| # Allow access to the unverified payload for claim verification. | ||
| class ClaimsContext | ||
| extend Forwardable | ||
|
|
||
| def_delegators :@token, :header, :unverified_payload | ||
|
|
||
| def initialize(token) | ||
| @token = token | ||
| end | ||
|
|
||
| def payload | ||
| unverified_payload | ||
| end | ||
| end | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module JWT | ||
| class EncodedToken | ||
| # @private | ||
| # Handles segment parsing and duplicate key detection. | ||
| class SegmentParser | ||
| def initialize(allow_duplicate_keys:) | ||
| @allow_duplicate_keys = allow_duplicate_keys | ||
| end | ||
|
|
||
| def parse_and_decode(segment) | ||
| parse(::JWT::Base64.url_decode(segment || '')) | ||
| end | ||
|
|
||
| def parse_unencoded(segment) | ||
| parse(segment) | ||
| end | ||
|
|
||
| def parse(segment) | ||
| JWT::JSON.parse(segment, allow_duplicate_keys: @allow_duplicate_keys) | ||
| rescue ::JSON::ParserError | ||
| raise JWT::DecodeError, 'Invalid segment encoding' | ||
| end | ||
| end | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module JWT | ||
| class EncodedToken | ||
| # @private | ||
| # Handles signature verification logic. | ||
| class SignatureVerifier | ||
| def initialize(token) | ||
| @token = token | ||
| end | ||
|
|
||
| def verify(algorithm:, key: nil, key_finder: nil) | ||
| raise ArgumentError, 'Provide either key or key_finder, not both or neither' if key.nil? == key_finder.nil? | ||
|
|
||
| keys = Array(key || key_finder.call(@token)) | ||
| verifiers = JWA.create_verifiers(algorithms: algorithm, keys: keys, preferred_algorithm: @token.header['alg']) | ||
|
|
||
| raise JWT::VerificationError, 'No algorithm provided' if verifiers.empty? | ||
|
|
||
| verifiers.any? { |jwa| jwa.verify(data: @token.signing_input, signature: @token.signature) } | ||
| end | ||
| end | ||
| 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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Could we here detect if the JSON gem is supporting the feature and raise if we are not compatible? Would allow us to support older Ruby versions still.
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.
It sounds good! I modified it that way. WDYT?