"ddos challenge" style script #4

Open
luna wants to merge 20 commits from claude/ddos-protection-challenge-01CMAtrK6Dt24x9Q3v6Gz9fS into mistress
2 changed files with 13 additions and 0 deletions
Showing only changes of commit d8b1b861ab - Show all commits

Add debug logging to diagnose token validation failures

Added debug logging to see what's happening with cookie header
parsing in the failing token validation tests. This will help
identify whether:
- ngx.req.get_headers() is returning the expected headers
- The Cookie header is being found (case sensitivity check)
- The token is being extracted correctly
- The token is found in the shared dict

Also added ngx log level constants (DEBUG, INFO, WARN, ERR) to
the test framework since the module uses them.
Claude 2025-11-22 23:20:55 +00:00 committed by Luna

View file

@ -539,12 +539,19 @@ 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

View file

@ -20,6 +20,12 @@ function createNgx()
print(msg) print(msg)
end end
-- Log level constants
ngx.DEBUG = 7
ngx.INFO = 6
ngx.WARN = 4
ngx.ERR = 3
-- only hold data here -- only hold data here
ngx.var = {} ngx.var = {}