Skip to content

appsec and bot detection support - #21

Merged
buixor merged 21 commits into
lapi-revamp-stage1-stream-supportfrom
lapi-revamp-stage2-waf-and-bot-support
Oct 22, 2026
Merged

buixor merged 21 commits into
lapi-revamp-stage1-stream-supportfrom
lapi-revamp-stage2-waf-and-bot-support

Conversation

@buixor

@buixor buixor commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

@buixor
buixor added this pull request to stack #20 October 16, 2026 08:22
Copilot AI balanced review requested due to automatic review settings October 16, 2026 08:22

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.

🟡 Changes recommended

Unresolved cleanup lifetime errors and inspection bypasses prevent safe approval.

7 open findings
What changed in this PR

Adds AppSec inspection and bot-detection challenges to the Apache CrowdSec bouncer alongside existing local API decisions.

Changes:

  • Adds request forwarding, body capture and replay, and challenge response handling.
  • Introduces AppSec configuration and bounded verdict parsing.
  • Adds unit and integration coverage with a stub AppSec service.
File Description
test/​unit/​t_verdict.c Tests AppSec verdict parsing and validation.
test/​README.md Documents AppSec tests and live-engine checks.
test/​lib/​stub_appsec.py Simulates AppSec responses and records requests.
test/​lib/​harness.sh Adds AppSec lifecycle helpers and runtime directory configuration.
test/​bats/​challenge.bats Tests challenge responses, cookies, and endpoints.
test/​bats/​appsec.bats Tests forwarding, verdicts, and failure policies.
test/​bats/​appsec-body.bats Tests body inspection, replay, and limits.
mod_crowdsec.c Integrates AppSec checks and configuration directives.
Makefile.am Includes AppSec sources in the build.
crowdsec_verdict.h Defines AppSec verdict structures and bounds.
crowdsec_verdict.c Parses and validates AppSec responses.
crowdsec_config.h Adds AppSec settings and defaults.
crowdsec_appsec.h Declares AppSec interfaces and request state.
crowdsec_appsec.c Implements inspection, replay, and challenge serving.
config/​crowdsec-apache2-bouncer.conf Documents optional AppSec configuration.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crowdsec_appsec.c Outdated
Comment thread mod_crowdsec.c Outdated
Comment thread mod_crowdsec.c
Comment on lines +538 to 539
if (!sconf->url && !sconf->appsec_url) {
continue;
Comment thread crowdsec_appsec.c Outdated
Comment thread crowdsec_verdict.c Outdated
Comment thread mod_crowdsec.c
rem = crowdsec_rem_merge(rem, CROWDSEC_REM_BAN);
break;
case CROWDSEC_APPSEC_BADREQ:
return HTTP_BAD_REQUEST;
Comment thread mod_crowdsec.c Outdated
@buixor
buixor force-pushed the lapi-revamp-stage2-waf-and-bot-support branch from d95f393 to 5031013 Compare October 16, 2026 13:02
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

Comment thread crowdsec_appsec.h
/* True for the challenge's own assets and submit endpoint. Matched on the
* decoded path so a traversal cannot dodge it.
*/
int crowdsec_is_challenge_path(const char *uri, const char *prefix);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

check this: it seems fragile. shouldn't we want it to be enabled "server wide" and disabled in some specific location ?

Comment thread README.md

<Location />
Crowdsec On
CrowdsecAppsec On

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

In documentation we want to suggest to enable the bouncer and appsec globally (per vhost) and just show that you can disable it in specific locations.

Comment thread README.md
|---|---|---|---|
| `Crowdsec` | S+D | `Off` | Check requests in this scope. |
| `CrowdsecBlockedHTTPCode` | S+D | `429` | Status for a blocked client: `429`, `403` or `500`. |
| `CrowdsecLocation` | S+D | — | Redirect a blocked client here instead. Supports expressions, e.g. `/blocked?ip=%{REMOTE_ADDR}`. |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

investigate:

  • is this an internal redirect ?
  • if not, we might want to do the same approach as for nginx bouncer, where the bouncer just serves a static html that the user can override

Comment thread README.md
|---|---|---|---|
| `CrowdsecAppsecURL` | S | — | AppSec address: `http://127.0.0.1:7422` or `unix:/run/crowdsec/appsec.sock`. Unset disables AppSec. |
| `CrowdsecAppsecPath` | S | `/` | Path AppSec listens on. Must match the datasource's `path`. |
| `CrowdsecAppsec` | S+D | `Off` | Send requests in this scope for inspection. |

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

CrowdsecAppsec should be on by default as long as the AppSecURL is configured

Comment thread README.md

## Known limits

**A gzipped request body is inspected compressed.** The body is captured before

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

investigate : perform a test on live vm, the appsec should decompress the body.

@buixor
buixor merged commit 955201d into main Oct 22, 2026
12 checks passed
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.

Appsec integration

3 participants