From 2492d58d8e92a73b4a117a4b5ea60f1f20e265e5 Mon Sep 17 00:00:00 2001 From: Tim Rudat Date: Wed, 8 Jul 2020 02:55:18 +0200 Subject: [PATCH] Fix algorithm picking from options Fixes #331. --- lib/jwt/decode.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/jwt/decode.rb b/lib/jwt/decode.rb index 784f6719..486acefe 100644 --- a/lib/jwt/decode.rb +++ b/lib/jwt/decode.rb @@ -47,10 +47,17 @@ def options_includes_algo_in_header? end def allowed_algorithms - if @options.key?(:algorithm) + # Order is very important - first check for string keys, next for symbols + if @options.key?('algorithm') + [@options['algorithm']] + elsif @options.key?(:algorithm) [@options[:algorithm]] - else + elsif @options.key?('algorithms') + @options['algorithms'] || [] + elsif @options.key?(:algorithms) @options[:algorithms] || [] + else + [] end end