match the beginning of url permissions

This commit is contained in:
Kay0u 2021-01-20 01:28:08 +01:00
parent 63a9c9bada
commit 384889ae11
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D

View file

@ -291,14 +291,20 @@ end
permission = nil permission = nil
longest_url_match = "" longest_url_match = ""
ngx_full_url = ngx.var.host..ngx.var.uri
for permission_name, permission_infos in pairs(conf["permissions"]) do for permission_name, permission_infos in pairs(conf["permissions"]) do
if next(permission_infos['uris']) ~= nil then if next(permission_infos['uris']) ~= nil then
for _, url in pairs(permission_infos['uris']) do for _, url in pairs(permission_infos['uris']) do
if string.starts(url, "re:") then if string.starts(url, "re:") then
url = string.sub(url, 4, string.len(url)) url = string.sub(url, 4, string.len(url))
end end
-- We want to match the beginning of the url
if not string.starts(url, "^") then
url = "^"..url
end
local m = hlp.match(ngx.var.host..ngx.var.uri..hlp.uri_args_string(), url) local m = hlp.match(ngx_full_url, url)
if m ~= nil and string.len(m) > string.len(longest_url_match) then if m ~= nil and string.len(m) > string.len(longest_url_match) then
longest_url_match = m longest_url_match = m
permission = permission_infos permission = permission_infos