@@ -229,21 +229,43 @@ end
229229
230230
231231function _M .verify_claims (self , claims , conf )
232- if not claims then
233- claims = default_claims
232+ -- When `claims_to_verify` is not configured (nil or an explicitly empty
233+ -- array), fall back to the default claims (exp/nbf) and validate them only
234+ -- if they are present in the payload. This closes the expired-token hole
235+ -- while staying lenient for tokens that legitimately omit these claims.
236+ -- An empty array must NOT skip validation, otherwise it reopens the bypass.
237+ if not claims or # claims == 0 then
238+ for _ , claim_name in ipairs (default_claims ) do
239+ local claim = self .payload [claim_name ]
240+ if claim ~= nil then
241+ local checker = claims_checker [claim_name ]
242+ if type (claim ) ~= checker .type then
243+ return false , " claim " .. claim_name .. " is not a " .. checker .type
244+ end
245+ local ok , err = checker .check (claim , conf )
246+ if not ok then
247+ return false , err
248+ end
249+ end
250+ end
251+
252+ return true
234253 end
235254
255+ -- When `claims_to_verify` is explicitly configured, the listed claims are
256+ -- required: they must exist in the payload and be valid.
236257 for _ , claim_name in ipairs (claims ) do
237258 local claim = self .payload [claim_name ]
238- if claim then
239- local checker = claims_checker [claim_name ]
240- if type (claim ) ~= checker .type then
241- return false , " claim " .. claim_name .. " is not a " .. checker .type
242- end
243- local ok , err = checker .check (claim , conf )
244- if not ok then
245- return false , err
246- end
259+ if claim == nil then
260+ return false , " claim " .. claim_name .. " is missing"
261+ end
262+ local checker = claims_checker [claim_name ]
263+ if type (claim ) ~= checker .type then
264+ return false , " claim " .. claim_name .. " is not a " .. checker .type
265+ end
266+ local ok , err = checker .check (claim , conf )
267+ if not ok then
268+ return false , err
247269 end
248270 end
249271
0 commit comments