fix: guard read_body against HTTP/2 reload crash in captcha verify state#142
Open
drlogout wants to merge 1 commit into
Open
fix: guard read_body against HTTP/2 reload crash in captcha verify state#142drlogout wants to merge 1 commit into
drlogout wants to merge 1 commit into
Conversation
ngx.req.read_body() raises a runtime error for HTTP/2 (and HTTP/3) requests without a Content-Length header. The captcha verify-state handler in csmod.Allow() called read_body unconditionally, causing nginx to return HTTP 500 whenever a client with an active captcha decision reloaded the challenge page over HTTP/2. The guard mirrors the one already used in get_body(): if the protocol is HTTP/2+ and Content-Length is missing, skip the body read and treat the request as having no POST args. Genuine captcha form submissions are POSTs from browsers that always include Content-Length, so the guard does not interfere with the verification flow. Closes crowdsecurity#63
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a runtime crash when a client with a
captcha-type decision reloads thechallenge page over HTTP/2. Closes #63.
Problem
ngx.req.read_body()raises an error for HTTP/2 (and HTTP/3) requests withouta Content-Length header. The body-read inside
csmod.Allow()'s captchaverify-state handler is unguarded, so any HTTP/2 GET reload of the captcha
page crashes nginx with HTTP 500:
The
get_body()helper already implements the correct guard; this PR appliesthe same pattern to the second
read_bodycall site.Reproduction
crowdsec-nginx-bouncerwith a captcha provider configured (e.g. Turnstile, hCaptcha)cscli decisions add -i <your-ip> -t captcha -d 10mread_bodyerror in nginx error logFix
Mirror the HTTP/2 protocol-version guard from
get_body(). When the body isunreadable, skip the read and fall through with an empty args table, which
correctly re-serves the captcha page. Captcha form submissions are POSTs
with Content-Length, so they're unaffected.
Compatibility
get_bodybehavior)Tested
crowdsec-nginx-bouncer v1.1.6EOF
)"