Skip to content

Commit 9bd5358

Browse files
committed
Fix issue with http2 requests and captcha
The lua-nginx-module requires the content-length header to be set on http2 requests when ngx.req.read_body() is called and throws an error otherwise. This fix checks for POST request method before reading the body to avoid the error on other request methods. Ref #130
1 parent 8bd0821 commit 9bd5358

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/crowdsec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ function csmod.Allow(ip)
730730
local previous_uri, flags = ngx.shared.crowdsec_cache:get("captcha_" .. ip)
731731
local source, state_id, err = flag.GetFlags(flags)
732732

733-
if previous_uri ~= nil and state_id == flag.VERIFY_STATE then
733+
if previous_uri ~= nil and state_id == flag.VERIFY_STATE and ngx.req.get_method() == "POST" then
734734
ngx.req.read_body()
735735
local args, err = ngx.req.get_post_args()
736736

@@ -789,7 +789,7 @@ function csmod.Allow(ip)
789789
local previous_uri, flags = ngx.shared.crowdsec_cache:get("captcha_"..ip)
790790
local source, state_id, err = flag.GetFlags(flags)
791791
-- we check if the IP is already in cache for captcha and not yet validated
792-
if previous_uri == nil or state_id ~= flag.VALIDATED_STATE or remediationSource == flag.APPSEC_SOURCE then
792+
if previous_uri == nil or state_id ~= flag.VALIDATED_STATE or remediationSource == flag.APPSEC_SOURCE then
793793
local uri = ngx.var.uri
794794
-- in case its not a GET request, we prefer to fallback on referer
795795
if ngx.req.get_method() ~= "GET" then

0 commit comments

Comments
 (0)