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

An option to return a boolean value from Allow method #95

Open
pokeghosst opened this issue Feb 10, 2025 · 1 comment
Open

An option to return a boolean value from Allow method #95

pokeghosst opened this issue Feb 10, 2025 · 1 comment

Comments

@pokeghosst
Copy link

Currently, Allow method calls ngx.exit regardless of the bouncer's decision, which prevents any other scripts inside access_by_lua_block to be executed after the bouncer.

It would be very handy to have another version of Allow that either:

  • Returns boolean value regardless of the decision, similarly to allowIp;
  • Simply returns on successful pass. In this case, the bouncer would handle all rejections and if the request passes by the bouncer, it can be handled by one of the next scripts.
@FoxxMD
Copy link

FoxxMD commented Feb 12, 2025

I need this functionality as well. I have a scenario where I want to use crowdsec nginx bouncer in a "catch-all" location block and have any allowed requests redirect.

This isn't possible using the normal, declarative directives because return invokes in the rewrite phase, before access phase (and bouncer runs), so ideally I could get around this instead rewriting in lua block after cs by doing

access_by_lua_block {
	local cs = require "crowdsec"
	if ngx.var.unix == "1" then
		ngx.log(ngx.DEBUG, "[Crowdsec] Unix socket request ignoring...")
	else
		cs.Allow(ngx.var.remote_addr)
        ngx.req.set_method(ngx.HTTP_GET)
        return ngx.redirect("https://myTLD.com")
	end
}

BUT since Allow calls exit execution is ended before my code can be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants