"ddos challenge" style script #4
1 changed files with 3 additions and 12 deletions
|
|
@ -21,12 +21,10 @@ local function getCookieValue(cookie_header, cookie_name)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
-- Parse cookie header to find our cookie
|
-- Parse cookie header to find our cookie
|
||||||
|
-- Use Lua patterns instead of PCRE for better test compatibility
|
||||||
local pattern = cookie_name .. "=([^;]+)"
|
local pattern = cookie_name .. "=([^;]+)"
|
||||||
local match = ngx.re.match(cookie_header, pattern)
|
local value = string.match(cookie_header, pattern)
|
||||||
if match then
|
return value
|
||||||
return match[1]
|
|
||||||
end
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Question pool for multiple-choice challenges
|
-- Question pool for multiple-choice challenges
|
||||||
|
|
@ -539,19 +537,12 @@ local function challengeCallback(cfg, state)
|
||||||
|
|
||||||
-- Check for valid token cookie
|
-- Check for valid token cookie
|
||||||
local headers = ngx.req.get_headers()
|
local headers = ngx.req.get_headers()
|
||||||
ngx.log(ngx.DEBUG, "DEBUG: headers type = " .. type(headers))
|
|
||||||
if headers then
|
|
||||||
ngx.log(ngx.DEBUG, "DEBUG: headers.Cookie = " .. tostring(headers["Cookie"]))
|
|
||||||
ngx.log(ngx.DEBUG, "DEBUG: headers.cookie = " .. tostring(headers["cookie"]))
|
|
||||||
end
|
|
||||||
local cookie_header = headers["Cookie"]
|
local cookie_header = headers["Cookie"]
|
||||||
local token = getCookieValue(cookie_header, cfg.cookie_name)
|
local token = getCookieValue(cookie_header, cfg.cookie_name)
|
||||||
ngx.log(ngx.DEBUG, "DEBUG: token extracted = " .. tostring(token))
|
|
||||||
|
|
||||||
if token then
|
if token then
|
||||||
-- Verify token is still valid in shared dict
|
-- Verify token is still valid in shared dict
|
||||||
local is_valid = state.tokens_dict:get(token)
|
local is_valid = state.tokens_dict:get(token)
|
||||||
ngx.log(ngx.DEBUG, "DEBUG: token is_valid = " .. tostring(is_valid))
|
|
||||||
if is_valid then
|
if is_valid then
|
||||||
-- Token is valid, allow request through
|
-- Token is valid, allow request through
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue