Skip to content

appsec-configs: Allow forgejo's path blocked by WAF - #1974

Open
Dryusdan wants to merge 1 commit into
crowdsecurity:masterfrom
Dryusdan:feature/forgejo
Open

Dryusdan wants to merge 1 commit into
crowdsecurity:masterfrom
Dryusdan:feature/forgejo

Conversation

@Dryusdan

@Dryusdan Dryusdan commented Nov 2, 2026

Copy link
Copy Markdown

Description

Add a community appsec-config skipping WAF evaluation for legitimate Forgejo automation (Actions runner RPC, job-container idtoken/artifacts/OIDC, Git Smart HTTP). Anonymous public clone works; receive-pack push, root /.git/, and non-protocol traffic stay evaluated. Tested locally via a harness through the real appsec runtime (29/29) + mkindex/hublint (0 errors).

Checklist

  • I have read the contributing guide
  • I have tested my changes locally
  • For new parsers or scenarios, tests have been added
  • No hub linter for Crowdsec appsec-configs | I have run the hub linter and no issues were reported (see contributing guide)
  • Automated tests are passing
  • AI was used to generate any/all content of this PR

Additional Information

Script to make test

#!/usr/bin/env bash
APIKEY=""
# base headers carrying the ORIGINAL request as metadata (the URL sent to the datasource is irrelevant)
fwd() { # method uri ua extra...
  local method="$1" uri="$2" ua="$3"; shift 3
  curl -s -o /dev/null -w '%{http_code}' --max-time 10 \
    -H "X-Crowdsec-Appsec-Api-Key: ${APIKEY}" \
    -H "X-Crowdsec-Appsec-Ip: 1.2.3.4" \
    -H "X-Crowdsec-Appsec-Verb: ${method}" \
    -H "X-Crowdsec-Appsec-Uri: ${uri}" \
    -H "X-Crowdsec-Appsec-User-Agent: ${ua}" \
    "$@" "http://127.0.0.1:${PORT}/"
}

report() {   # label  code
  printf '  %-30s %s\n' "$1" "$2"
}

pk_upload="0032want 0000000000000000000000000000000000000000\n00000009done\n"
pk_recv="0000000000"

for mode in baseline fj; do
  PORT=$([ "$mode" = baseline ] && echo 7422 || echo 7423)
  echo "=== $mode (:${PORT}) ==="
  report "anon info/refs (clone)"       "$(fwd GET  "/owner/repo.git/info/refs?service=git-upload-pack" "tortoisegit/9.4.0")"
  report "anon upload-pack (clone)"     "$(fwd POST "/owner/repo.git/git-upload-pack" "tortoisegit/9.4.0" -H "Content-Type: application/x-git-upload-pack-request" --data-binary "$pk_upload")"
  report "anon receive-pack"            "$(fwd POST "/owner/repo.git/git-receive-pack" "tortoisegit/9.4.0" -H "Content-Type: application/x-git-receive-pack-request" --data-binary "$pk_recv")"
  report "basic push receive-pack"      "$(fwd POST "/owner/repo.git/git-receive-pack" "git/2.43.0" -H "Authorization: Basic dXNlcjpwYXNz" -H "Content-Type: application/x-git-receive-pack-request" --data-binary "$pk_recv")"
  report "basic auth upload-pack"       "$(fwd POST "/owner/repo.git/git-upload-pack" "git/2.43.0" -H "Authorization: Basic dXNlcjpwYXNz" -H "Content-Type: application/x-git-upload-pack-request" --data-binary "$pk_upload")"
  report "bearer runner upload-pack"    "$(fwd POST "/owner/repo.git/git-upload-pack" "git/2.43.0" -H "Authorization: Bearer runnerToken123" -H "Content-Type: application/x-git-upload-pack-request" --data-binary "$pk_upload")"
  report "sqli (web, must stay blocked)" "$(fwd POST "/owner/repo/issues" "Mozilla/5.0 Chrome/120" -H "Content-Type: application/x-www-form-urlencoded" -d "q=1' OR '1'='1")"
done

@sabban sabban left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi, thank you for your contribution!

  1. The bypass relies on client-controlled markers: any request with a fake Authorization: Basic … header (or a forgejo-runner/ User-Agent) skips the WAF. I checked locally: GET /v2/.env is blocked, but passes with Authorization: Basic Zm9vOmJhcg==. Since there's no Host check, this applies to every site behind the WAF, and /v2/ is a very common API prefix. As SkipProcessing also creates no event, such requests would go through unnoticed.

  2. Rather than skipping the whole WAF, could you narrow it down? Depending on what fires:

    • if it's the binary bodies (git packs, artifacts), DisableBodyInspection() in a pre_eval on those paths keeps all the other checks;
    • if specific rules misfire, RemoveInBandRuleByName(...) / RemoveOutBandRuleByID(...) in a pre_eval disables only those, on those paths;
    • if it's one of our virtual patches, we'd rather fix the rule itself.

    Which rules were blocking your Forgejo traffic? cscli alerts inspect <id> -d shows them.

  3. Please revert the .index.json change: this file is generated by CI after merge and must not be modified in PRs.

@sabban sabban added the waiting-for-user Waiting for submitter answer regarding specific points in the PR label Nov 13, 2026
@Dryusdan

Copy link
Copy Markdown
Author

Hi,

/v2/ path is used by Docker for pull and push image from forgejo registry

user agent docker/29.9.3 go/go1.26.10 git-commit/70efc0e kernel/6.12.115+deb13.1-amd64 os/linux arch/amd64 containerd-client/v2.4.2 storage-driver/overlayfs UpstreamClient(moby-client/v0.6.1 linux/amd64)
GET /v2/dryusdan/python/blobs/sha256

Debian apt use /api/ which is already unlocked by another rule

I would like create an appsec rule with custom Host, but I don't know how to share a rule with a configurable filter req.Host.

There is a bunch of different scenario that trigger Crowdsec.
ArgoCD when it sync many git repo.

I tried to reproduce the alerts, but I haven't been able to do so yet.

I remember getting a lot of “Content-Type not allowed” errors (x-git-pack) and “too many browser submissions,” but I think my configuration was a little more... strict back then than it is now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-for-user Waiting for submitter answer regarding specific points in the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants