Skip to content

WAF Bot Detection : Support for challenge mode#138

Open
buixor wants to merge 2 commits into
mainfrom
waf-challenge-mode
Open

WAF Bot Detection : Support for challenge mode#138
buixor wants to merge 2 commits into
mainfrom
waf-challenge-mode

Conversation

@buixor

@buixor buixor commented Mar 24, 2026

Copy link
Copy Markdown
Contributor
  • Support the challenge reponse to serve html/js challenge to the user

Copilot AI review requested due to automatic review settings June 10, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.challenge helper to apply AppSec challenge responses (status/headers/cookies/body).
  • Extends csmod.AppSecCheck / csmod.Allow flow 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 thread lib/crowdsec.lua
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 thread lib/crowdsec.lua
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 thread lib/crowdsec.lua
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
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

Successfully merging this pull request may close these issues.

2 participants