@@ -203,7 +203,14 @@ fn decode_token(
203
203
insecure_validator. required_spec_claims = HashSet :: new ( ) ;
204
204
insecure_validator. validate_exp = false ;
205
205
insecure_validator. validate_aud = false ;
206
- let insecure_decoding_key = DecodingKey :: from_secret ( "" . as_ref ( ) ) ;
206
+
207
+ let insecure_decoding_key = match algorithm {
208
+ Algorithm :: HS256 | Algorithm :: HS384 | Algorithm :: HS512 => Ok ( DecodingKey :: from_secret ( b"" ) ) ,
209
+ Algorithm :: ES256 | Algorithm :: ES384 => DecodingKey :: from_ec_components ( "" , "" ) ,
210
+ Algorithm :: EdDSA => DecodingKey :: from_ed_components ( "" ) ,
211
+ _ => DecodingKey :: from_rsa_components ( "" , "" ) ,
212
+ }
213
+ . map_or ( DecodingKey :: from_secret ( b"" ) , |key| key) ;
207
214
208
215
let decode_only = decode :: < Payload > ( & arguments. jwt , & insecure_decoding_key, & insecure_validator)
209
216
. map_err ( Error :: into) ;
@@ -366,7 +373,10 @@ mod tests {
366
373
let ( decode_only, verified_token_data) = decode_token ( & args) ;
367
374
368
375
assert ! ( decode_only. is_ok( ) ) ;
369
- assert ! ( verified_token_data. is_err( ) ) ;
376
+ assert ! ( verified_token_data
377
+ . unwrap_err( )
378
+ . to_string( )
379
+ . contains( "The JWT provided has an invalid signature: InvalidSignature" ) ) ;
370
380
371
381
let decode_only_token = decode_only. unwrap ( ) ;
372
382
0 commit comments