Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit with ngx.DECLINED when the request is allowed #62

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/crowdsec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,11 @@ end

function csmod.Allow(ip)
if runtime.conf["ENABLED"] == "false" then
return "Disabled", nil
ngx.exit(ngx.DECLINED)
end

if ngx.req.is_internal() then
return
ngx.exit(ngx.DECLINED)
end

local remediationSource = flag.BOUNCER_SOURCE
Expand All @@ -583,7 +583,7 @@ function csmod.Allow(ip)
for k, v in pairs(runtime.conf["EXCLUDE_LOCATION"]) do
if ngx.var.uri == v then
ngx.log(ngx.ERR, "whitelisted location: " .. v)
return
ngx.exit(ngx.DECLINED)
end
local uri_to_check = v
if utils.ends_with(uri_to_check, "/") == false then
Expand Down Expand Up @@ -667,8 +667,7 @@ function csmod.Allow(ip)
end
-- captcha is valid, we redirect the IP to its previous URI but in GET method
ngx.req.set_method(ngx.HTTP_GET)
ngx.redirect(previous_uri)
return
return ngx.redirect(previous_uri)
else
ngx.log(ngx.ALERT, "Invalid captcha from " .. ip)
end
Expand Down Expand Up @@ -708,9 +707,11 @@ function csmod.Allow(ip)
ngx.log(ngx.ERR, "Lua shared dict (crowdsec cache) is full, please increase dict size in config")
end
ngx.log(ngx.ALERT, "[Crowdsec] denied '" .. ip .. "' with '"..remediation.."'")
return
end
end
end
ngx.exit(ngx.DECLINED)
end


Expand Down