Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

**Fixes and enhancements:**

- Preserve claims verification state and reject unsupported critical headers when decoding unencoded payloads [#753](https://github.com/jwt/ruby-jwt/pull/753) - [@OskarEichler](https://github.com/OskarEichler)
- Fix rejection of unknown algorithms from JWKs for RFC compliance and pquip [#728](https://github.com/jwt/ruby-jwt/pull/728)
- Fix the `Style/DirectiveScope` RuboCop offense failing the build [#752](https://github.com/jwt/ruby-jwt/pull/752)

Expand Down
9 changes: 7 additions & 2 deletions lib/jwt/claims/crit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ class Crit
# Initializes a new Crit instance.
#
# @param expected_crits [String] the expected crit header values for the JWT token.
def initialize(expected_crits:)
# @param strict [Boolean] whether the crit header may contain only expected values.
def initialize(expected_crits:, strict: false)
@expected_crits = Array(expected_crits)
@strict = strict
end

# Verifies the critical claim ('crit') in the JWT token header.
Expand All @@ -24,12 +26,15 @@ def verify!(context:, **_args)
missing = (expected_crits - context.header['crit'])
raise(JWT::InvalidCritError, "Crit header missing expected values: #{missing.join(', ')}") if missing.any?

unexpected = (context.header['crit'] - expected_crits)
raise(JWT::InvalidCritError, "Unsupported critical headers: #{unexpected.join(', ')}") if strict && unexpected.any?

nil
end

private

attr_reader :expected_crits
attr_reader :expected_crits, :strict
end
end
end
2 changes: 1 addition & 1 deletion lib/jwt/encoded_token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def decode_payload
raise JWT::DecodeError, 'Encoded payload is empty' if encoded_payload == ''

if unencoded_payload?
verify_claims!(crit: ['b64'])
Claims::Crit.new(expected_crits: ['b64'], strict: true).verify!(context: ClaimsContext.new(self))
return parse_unencoded(encoded_payload)
end

Expand Down