Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- `crowdsec-hub-authoring`: new rule for parsers that take `source_ip` from `X-Forwarded-For`.
Use the last entry, anchor so the pattern cannot match inside the logged header, lower the
scenario `confidence` and document the proxy requirement in the `.md`. Do not ask for
private-IP trust logic in the parser. Updated `parsers.md`, `overview.md`, `scenarios.md`,
`review-checklist.md` and `SKILL.md`. Verified with a real Radicale 3.9.2 behind nginx in
docker and `cscli hubtest` (crowdsecurity/hub#2040).

## [0.3.1] - 2026-12-03

### Changed
Expand Down
2 changes: 1 addition & 1 deletion plugin/skills/crowdsec-hub-authoring/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ For installing, configuring or debugging a running CrowdSec, use the `crowdsec`

- Search the hub and open PRs first — extend an existing parser/scenario rather than adding a second one.
- Author dir = name prefix = `author:`; never the `crowdsecurity/` namespace for external items; items can't be renamed.
- Parsers: `filter` on `evt.Parsed.program`, `apply_on: message`, real peer as `source_ip`, anchored patterns around client-controlled text.
- Parsers: `filter` on `evt.Parsed.program`, `apply_on: message`, real peer as `source_ip` (or the last `X-Forwarded-For` entry with lowered scenario `confidence` + proxy requirement in the `.md`, never private-IP trust logic), anchored patterns around client-controlled text.
- Every item has tests (generated asserts, private IPs, scenario tests that actually overflow) and a same-name `.md`.
- No `debug: true`, no YAML anchors, no `.index.json` / version bumps (CI does it).
- Prove review findings with `cscli hubtest` or `cscli explain` on a crafted line before reporting them.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Rejected or closed (with the reasons maintainers gave):
| A second parser for a service that already has one | extend the existing parser instead (#802, #1695, #1762, #1676) |
| A scenario duplicating an existing one | e.g. path traversal already in `http-path-traversal-probing` (#1944), OpenVPN bf (#1762) |
| Bespoke/personal app or private fork | belongs in local config, not the hub (#625, #1635, #1870) |
| Source IP from an untrusted header (`X-Forwarded-For` with no trusted-proxy logic) | spoofable → anyone can get any IP banned; and breaks without a proxy (#738, #1909) |
| Source IP from `X-Forwarded-For` without saying so | spoofable when the app is exposed without a proxy (#738, #1909). Accepted when the app is meant to be behind a proxy, the last entry is used and patterns are anchored, with a lowered scenario `confidence` and the proxy requirement in the `.md` — no private-IP trust logic in the parser (#2040) |
| Whitelists covering huge ranges (all of AWS/Azure/GitHub) | whitelists attackers on those clouds (#834, #1465) |
| Scenarios likely to fire on legit traffic in a default collection | e.g. xmlrpc bf kept out of the wordpress collection (#245); CVE paths used legitimately (#406) |
| Cosmetic churn (whitespace) on popular items | every engine re-downloads and restarts for nothing (#1418) |
Expand Down
25 changes: 20 additions & 5 deletions plugin/skills/crowdsec-hub-authoring/references/parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ verified:
version: "1.8.2"
env: hubtest
notes: "example parser via hubtest (syslog + non-syslog log_type); anchored pattern drops trailing-text line; cscli explain --log/--file and hubtest explain; grok debugging steps on a broken pattern (explain, debug: true, GREEDYDATA bisect)"
- date: 2026-12-04
version: "1.8.2"
env: docker
notes: "XFF guidance: real Radicale 3.9.2 behind nginx; unanchored XFF pattern banned an arbitrary IP from 6 unauthenticated requests (access line); anchored last-entry pattern fixed it; private-IP trust logic rejected by maintainer in favour of lower confidence + docs"
---

# Authoring — parsers
Expand Down Expand Up @@ -105,11 +109,22 @@ statics:

**Source IP — the most important field**
- Set `evt.Meta.source_ip` (and keep it in `Parsed` too). It decides who gets banned.
- Use the TCP peer, not `X-Forwarded-For`, unless the app itself validates trusted
proxies. Header-based IPs are spoofable when the port is exposed and break
without a proxy (#738, #1909). If you must, implement trusted-proxy logic
(right-most untrusted hop, peer must be a trusted range) — see #1909's
`IpInRange` expression — and document it.
- Use the TCP peer when the app logs it. When the app only gives a usable client
IP through `X-Forwarded-For` (it sits behind a reverse proxy), take the
**last** XFF entry (the one the proxy appended) and fall back to the peer when
there is no header. **Don't add trusted-proxy magic in the parser** (guessing
that a private/loopback peer is a proxy with `IpInRange` lists): it is a
deployment guess the hub can't make. Instead (maintainer decision, #2040):
- lower `confidence` on the scenarios fed by this parser (header-based IPs are
spoofable when the app port is exposed without a proxy, #738, #1909);
- state it in the parser `.md` and the collection `.md`: the app must only be
reachable through the proxy, which must overwrite or append XFF;
- tell the contributor in the review why confidence was lowered.
- XFF is logged verbatim, often in more than one line (access line *and* auth
line). Anchor so the pattern can't match inside the header, and accept any
text before the last `, ` (a junk first entry like `unknown` must not drop the
event — attackers use it to evade). Python `%r` switches to `"…"` quoting when
the value holds `'` — handle both quote styles (Radicale, #2040).
- Make sure the field is always a single IP (XFF can be a comma list).

**Meta conventions** (what scenarios and contexts consume)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Reasons and precedents: [overview.md](./overview.md).
## Parser

- [ ] `filter` on `evt.Parsed.program`; `apply_on: message`.
- [ ] Source IP is the real peer, single value, not a client-controlled header; IPv6 handled.
- [ ] Source IP is the real peer, single value; IPv6 handled. If it comes from `X-Forwarded-For`: last entry only, pattern can't match inside the header (check every log line that echoes it), junk first entries don't drop the event, scenario `confidence` lowered and the proxy requirement in the `.md` — ask for that, not for private-IP trust logic.
- [ ] Patterns anchored where client text precedes the IP; no over-broad `DATA`/classes.
- [ ] JSON via `UnmarshalJSON` (+ `startsWith "{"`), numbers cast with `int()`.
- [ ] Custom patterns namespaced; no redefinition of built-ins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Multiple scenarios in one file are separated by `---`; each document needs a `na
| `service` | product or protocol |
| `behavior` | must exist in `taxonomy/behaviors.json` (`http:bruteforce`, `http:exploit`, `http:scan`, `ssh:bruteforce`, `generic:bruteforce`, `generic:scan`, `smtp:spam`, …) |
| `classification` | `attack.Txxxx[.xxx]` (MITRE, validated against `mitre_attack.json`), `cve.CVE-YYYY-N`, `cwe.CWE-N`; must match the actual CVE (#983) |
| `confidence` | int 0–3: likelihood of **no** false positive (3 = 262 scenarios) |
| `confidence` | int 0–3: likelihood of **no** false positive (3 = 262 scenarios). Lower it when the parser takes `source_ip` from a client-controllable header such as `X-Forwarded-For`, and say why in the `.md` (#2040) |
| `spoofable` | int 0–3: 0 for TCP-based sources (312 scenarios) |
| `label` | short human name, consistent wording with existing items ("Myservice Bruteforce", "Myservice User Enumeration") (#325, #963) |
| `remediation` | `true` to ban; `false` for audit/info scenarios |
Expand Down
Loading