WAF Bot Detection : Support for challenge mode#138
Open
buixor wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for CrowdSec AppSec “challenge” remediation by passing through AppSec-provided HTML/JS content, headers, and cookies to the client.
Changes:
- Introduces a new
plugins.crowdsec.challengehelper to apply AppSec challenge responses (status/headers/cookies/body). - Extends
csmod.AppSecCheck/csmod.Allowflow to carry and serve challenge response payloads. - Updates remediation support list to include
challenge(with fallback-to-ban behavior if response payload is missing).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
lib/plugins/crowdsec/challenge.lua |
New module to render AppSec challenge responses by applying headers/cookies/body and exiting with the provided status. |
lib/crowdsec.lua |
Wires “challenge” into AppSec check + remediation handling, including passing AppSec response payload through to the new challenge module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+733
to
736
| local appsecOk, appsecRemediation, status_code, appsec_resp, err = csmod.AppSecCheck(ip) | ||
| if err ~= nil then | ||
| ngx.log(ngx.ERR, "AppSec check: " .. err) | ||
| end |
Comment on lines
+664
to
+668
| local appsec_response = { | ||
| body = response.user_body_content, | ||
| headers = response.user_headers, | ||
| cookies = response.user_cookies, | ||
| } |
Comment on lines
+12
to
+24
| if headers ~= nil then | ||
| for name, values in pairs(headers) do | ||
| if type(values) == "table" then | ||
| if #values == 1 then | ||
| ngx.header[name] = values[1] | ||
| else | ||
| ngx.header[name] = values | ||
| end | ||
| else | ||
| ngx.header[name] = values | ||
| end | ||
| end | ||
| end |
Comment on lines
+26
to
+32
| if cookies ~= nil and #cookies > 0 then | ||
| if #cookies == 1 then | ||
| ngx.header["Set-Cookie"] = cookies[1] | ||
| else | ||
| ngx.header["Set-Cookie"] = cookies | ||
| end | ||
| end |
Comment on lines
+820
to
+824
| if remediation == "challenge" then | ||
| if appsec_response ~= nil then | ||
| ngx.log(ngx.DEBUG, "[Crowdsec] challenge '" .. ip .. "' (by " .. flag.Flags[remediationSource] .. ")") | ||
| challenge.apply(ret_code, appsec_response.body, appsec_response.headers, appsec_response.cookies) | ||
| return |
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.
challengereponse to serve html/js challenge to the user