"ddos challenge" style script #4

Open
luna wants to merge 20 commits from claude/ddos-protection-challenge-01CMAtrK6Dt24x9Q3v6Gz9fS into mistress
Showing only changes of commit d8aece9d70 - Show all commits

View file

@ -7,11 +7,8 @@ local resty_string = require "resty.string"
local function generateToken()
-- Generate a cryptographically strong random token
local strong_random = resty_random.bytes(16, true)
while strong_random == nil do
strong_random = resty_random.bytes(16, true)
end
return resty_string.to_hex(strong_random)
-- Uses RAND_pseudo_bytes which is secure and won't fail
return resty_string.to_hex(resty_random.bytes(16))
end
local function getCookieValue(cookie_header, cookie_name)
@ -159,10 +156,7 @@ end
local function serveQuestionChallenge(original_uri, state)
-- Select a random question
local random_byte = resty_random.bytes(1, true)
while random_byte == nil do
random_byte = resty_random.bytes(1, true)
end
local random_byte = resty_random.bytes(1)
local q_idx = (string.byte(random_byte) % #QUESTIONS) + 1
local question = QUESTIONS[q_idx]