Path: blob/main/databases/couchdb3/files/patch-src_jwtf_src_jwtf.erl
16124 views
--- src/jwtf/src/jwtf.erl.orig 2021-03-31 15:23:39 UTC1+++ src/jwtf/src/jwtf.erl2@@ -188,8 +188,7 @@ validate_alg(Props, Checks) ->3end.456-%% Not all these fields have to be present, but if they _are_ present7-%% they must be valid.8+%% Only validate required checks.9validate_payload(Props, Checks) ->10validate_iss(Props, Checks),11validate_iat(Props, Checks),12@@ -202,7 +201,7 @@ validate_iss(Props, Checks) ->13ActualISS = prop(<<"iss">>, Props),1415case {ExpectedISS, ActualISS} of16- {undefined, undefined} ->17+ {undefined, _} -> % ignore unrequired check18ok;19{ISS, undefined} when ISS /= undefined ->20throw({bad_request, <<"Missing iss claim">>});21@@ -218,11 +217,11 @@ validate_iat(Props, Checks) ->22IAT = prop(<<"iat">>, Props),2324case {Required, IAT} of25- {undefined, undefined} ->26+ {undefined, _} -> % ignore unrequired check27ok;28{true, undefined} ->29throw({bad_request, <<"Missing iat claim">>});30- {_, IAT} when is_integer(IAT) ->31+ {true, IAT} when is_integer(IAT) ->32ok;33{true, _} ->34throw({bad_request, <<"Invalid iat claim">>})35@@ -234,12 +233,12 @@ validate_nbf(Props, Checks) ->36NBF = prop(<<"nbf">>, Props),3738case {Required, NBF} of39- {undefined, undefined} ->40+ {undefined, _} -> % ignore unrequired check41ok;42{true, undefined} ->43throw({bad_request, <<"Missing nbf claim">>});44- {_, IAT} ->45- assert_past(<<"nbf">>, IAT)46+ {true, NBF} ->47+ assert_past(<<"nbf">>, NBF)48end.495051@@ -248,11 +247,11 @@ validate_exp(Props, Checks) ->52EXP = prop(<<"exp">>, Props),5354case {Required, EXP} of55- {undefined, undefined} ->56+ {undefined, _} -> % ignore unrequired check57ok;58{true, undefined} ->59throw({bad_request, <<"Missing exp claim">>});60- {_, EXP} ->61+ {true, EXP} ->62assert_future(<<"exp">>, EXP)63end.6465@@ -351,3 +350,20 @@ now_seconds() ->6667prop(Prop, Props) ->68proplists:get_value(Prop, Props).69+70+71+-ifdef(TEST).72+-include_lib("eunit/include/eunit.hrl").73+74+validate_payload_ignore_unchecked_props_test() ->75+ ?assertEqual(ok, validate_payload(_Props = [], _Checks = [])),76+ BogusProps = [77+ {iss, bogus},78+ {iat, bogus},79+ {nbf, bogus},80+ {exp, bogus}81+ ],82+ ?assertEqual(ok, validate_payload(BogusProps, _Checks = [])),83+ ok.84+85+-endif.868788