fix invalid session error handling and remove debug log in whitelist

This commit is contained in:
florian 2023-04-24 14:42:40 +02:00
parent e55912b34d
commit a372ffd521
No known key found for this signature in database
GPG key ID: 3D80806F12602A7C
3 changed files with 7 additions and 17 deletions

View file

@ -439,7 +439,7 @@ utils.get_session = function()
local _session, err, exists, refreshed = session.start()
ngx.ctx.bw.session_err = nil
if err and err ~= "missing session cookie" and err ~= "no session" then
logger:log(ngx.ERR, "can't start session : " .. err)
logger:log(ngx.WARN, "can't start session : " .. err)
ngx.ctx.bw.session_err = err
end
ngx.ctx.bw.session = _session
@ -455,7 +455,7 @@ end
utils.save_session = function()
-- Check if save is needed
if ngx.ctx.bw.session and not ngx.ctx.bw.session_err and not ngx.ctx.bw.session_saved then
if ngx.ctx.bw.session and not ngx.ctx.bw.session_saved then
ngx.ctx.bw.session:set_data(ngx.ctx.bw.session_data)
local ok, err = ngx.ctx.bw.session:save()
if err then
@ -472,7 +472,7 @@ end
utils.set_session_var = function(key, value)
-- Set new data
if ngx.ctx.bw.session and not ngx.ctx.bw.session_err then
if ngx.ctx.bw.session then
ngx.ctx.bw.session_data[key] = value
return true, "value set"
end
@ -481,7 +481,7 @@ end
utils.get_session_var = function(key)
-- Get data
if ngx.ctx.bw.session and not ngx.ctx.bw.session_err then
if ngx.ctx.bw.session then
if ngx.ctx.bw.session_data[key] then
return true, "data present", ngx.ctx.bw.session_data[key]
end

View file

@ -93,9 +93,7 @@ end
function antibot:challenge_resolved()
local session, err, exists, refreshed = utils.get_session()
if err then
return nil, "session error : " .. err
elseif not exists then
if not exists then
return false, "no session set"
end
local ok, err, raw_data = utils.get_session_var("antibot")
@ -111,9 +109,6 @@ end
function antibot:prepare_challenge()
local session, err, exists, refreshed = utils.get_session()
if err then
return false, "session error : " .. err
end
local set_needed = false
local data = nil
if exists then
@ -158,9 +153,7 @@ end
function antibot:display_challenge()
-- Open session
local session, err, exists, refreshed = utils.get_session()
if err then
return false, "can't open session : " .. err
elseif not exists then
if not exists then
return false, "no session set"
end
@ -210,9 +203,7 @@ end
function antibot:check_challenge()
-- Open session
local session, err, exists, refreshed = utils.get_session()
if err then
return nil, "can't open session : " .. err, nil
elseif not exists then
if not exists then
return false, "no session set"
end

View file

@ -35,7 +35,6 @@ function whitelist:initialize()
}
for kind, _ in pairs(kinds) do
for data in self.variables["WHITELIST_" .. kind]:gmatch("%S+") do
self.logger:log(ngx.ERR, data)
table.insert(self.lists[kind], data)
end
end