Skip to content

Commit d8b32e4

Browse files
committed
Preserve claims verification state for unencoded payloads
1 parent bedd65a commit d8b32e4

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
**Fixes and enhancements:**
1212

13+
- 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)
1314
- Fix rejection of unknown algorithms from JWKs for RFC compliance and pquip [#728](https://github.com/jwt/ruby-jwt/pull/728)
1415
- Fix the `Style/DirectiveScope` RuboCop offense failing the build [#752](https://github.com/jwt/ruby-jwt/pull/752)
1516

lib/jwt/claims/crit.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ class Crit
77
# Initializes a new Crit instance.
88
#
99
# @param expected_crits [String] the expected crit header values for the JWT token.
10-
def initialize(expected_crits:)
10+
# @param strict [Boolean] whether the crit header may contain only expected values.
11+
def initialize(expected_crits:, strict: false)
1112
@expected_crits = Array(expected_crits)
13+
@strict = strict
1214
end
1315

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

29+
unexpected = (context.header['crit'] - expected_crits)
30+
raise(JWT::InvalidCritError, "Unsupported critical headers: #{unexpected.join(', ')}") if strict && unexpected.any?
31+
2732
nil
2833
end
2934

3035
private
3136

32-
attr_reader :expected_crits
37+
attr_reader :expected_crits, :strict
3338
end
3439
end
3540
end

lib/jwt/encoded_token.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def decode_payload
190190
raise JWT::DecodeError, 'Encoded payload is empty' if encoded_payload == ''
191191

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

0 commit comments

Comments
 (0)