Comparison

mod_rest/mod_rest.lua @ 5962:667ce80937fa

mod_rest: Fix authentication The :contains check failed because case normalization was applied after
author Kim Alvefur <zash@zash.se>
date Mon, 15 Jul 2024 16:24:20 +0200
parent 5961:2739d3db591f
child 5981:eef6cb08f9e7
comparison
equal deleted inserted replaced
5961:2739d3db591f 5962:667ce80937fa
51 size = { code = 413; type = "modify"; condition = "resource-constraint", text = "Payload too large" }; 51 size = { code = 413; type = "modify"; condition = "resource-constraint", text = "Payload too large" };
52 }); 52 });
53 53
54 local function check_credentials(request) -- > session | boolean, error 54 local function check_credentials(request) -- > session | boolean, error
55 local auth_type, auth_data = string.match(request.headers.authorization, "^(%S+)%s(.+)$"); 55 local auth_type, auth_data = string.match(request.headers.authorization, "^(%S+)%s(.+)$");
56 auth_type = auth_type and auth_type:lower();
56 if not (auth_type and auth_data) or not auth_mechanisms:contains(auth_type) then 57 if not (auth_type and auth_data) or not auth_mechanisms:contains(auth_type) then
57 return nil, post_errors.new("noauthz", { request = request }); 58 return nil, post_errors.new("noauthz", { request = request });
58 end 59 end
59 auth_type = auth_type:lower();
60 60
61 if auth_type == "basic" then 61 if auth_type == "basic" then
62 local creds = base64.decode(auth_data); 62 local creds = base64.decode(auth_data);
63 if not creds then 63 if not creds then
64 return nil, post_errors.new("malformauthz", { request = request }); 64 return nil, post_errors.new("malformauthz", { request = request });