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