X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/d6e9200cc35411f3f27426b608bcfdef9348e6d3..b826537cb4aa2358027ffcb1dd6a87274734e962:/filters/simple-authentication.lua diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua index 4cd4983..5935d08 100644 --- a/filters/simple-authentication.lua +++ b/filters/simple-authentication.lua @@ -33,15 +33,28 @@ local secret = "BE SURE TO CUSTOMIZE THIS STRING TO SOMETHING BIG AND RANDOM" -- -- --- Sets HTTP cookie headers based on post +-- Sets HTTP cookie headers based on post and sets up redirection. function authenticate_post() local password = users[post["username"]] - -- TODO: Implement time invariant string comparison function to mitigate against timing attack. + local redirect = validate_value(post["redirect"]) + + if redirect == nil then + not_found() + return 0 + end + + redirect_to(redirect) + + -- TODO: Implement time invariant string comparison function to mitigate timing attack. if password == nil or password ~= post["password"] then - construct_cookie("", "cgitauth") + set_cookie("cgitauth", "") else - construct_cookie(post["username"], "cgitauth") + -- One week expiration time + local username = secure_value(post["username"], os.time() + 604800) + set_cookie("cgitauth", username) end + + html("\n") return 0 end @@ -54,8 +67,8 @@ function authenticate_cookie() return 1 end - local username = validate_cookie(get_cookie(http["cookie"], "cgitauth")) - if username == nil or not accepted_users[username] then + local username = validate_value(get_cookie(http["cookie"], "cgitauth")) + if username == nil or not accepted_users[username:lower()] then return 0 else return 1 @@ -68,6 +81,9 @@ function body() html("