Repository navigation
feat: add crowdsec-hub-authoring skill #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bffa0e1
feat: add crowdsec-hub-authoring skill
sabban bdb15e0
feat(hub-authoring): verify every reference doc, ship it in CI and re…
sabban 6fdde57
docs(hub-authoring): state that #N references are crowdsecurity/hub PRs
sabban 0b2230d
docs(hub-authoring): address review on PR #33
sabban 3db5778
docs(hub-authoring): describe crowdsec-local-mcp from a real run
sabban c9ebc83
Merge remote-tracking branch 'origin/main' into skill/hub-authoring
sabban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --- | ||
| name: crowdsec-hub-authoring | ||
| description: Use when writing, testing, or reviewing CrowdSec hub items for crowdsecurity/hub — parsers (s00/s01/s02), scenarios, parser whitelists and postoverflows, collections, contexts, AppSec (WAF) rules and virtual patches, their same-name .md docs, and cscli hubtest tests (.tests/, .appsec-tests/, parser.assert, scenario.assert). Also use to contribute a hub PR or review one (hub conventions, naming, labels/taxonomy, CI gates, why PRs get rejected). Complements the operational `crowdsec` skill, which covers installing and running CrowdSec. | ||
| --- | ||
|
|
||
| # CrowdSec hub authoring | ||
|
|
||
| Writing and reviewing items for [crowdsecurity/hub](https://github.com/crowdsecurity/hub). | ||
| Distilled from the CrowdSec docs, the hub's CI and lint code, and maintainer | ||
| review comments on merged and closed hub PRs. | ||
|
|
||
| Every `#N` in this skill and its references is a **crowdsecurity/hub** pull request | ||
| (`gh pr view N --repo crowdsecurity/hub`), cited as the evidence for a rule. | ||
|
|
||
| For installing, configuring or debugging a running CrowdSec, use the `crowdsec` skill. | ||
|
|
||
| ## Route by task | ||
|
|
||
| | Task / cue | Read | | ||
| |---|---| | ||
| | "contribute to the hub", "open a hub PR", repo layout, naming, what gets rejected, CI | [references/overview.md](./references/overview.md) | | ||
| | "write a parser", "new log format", grok, `UnmarshalJSON`, `source_ip`, timestamps | [references/parsers.md](./references/parsers.md) | | ||
| | "write a scenario", `capacity` / `leakspeed` / `blackhole`, labels, behavior, MITRE | [references/scenarios.md](./references/scenarios.md) | | ||
| | "false positive in app X — fix it in the hub", app whitelist, postoverflow | [references/whitelists-postoverflows.md](./references/whitelists-postoverflows.md) | | ||
| | collection, context, item `.md`, acquisition example | [references/collections-and-docs.md](./references/collections-and-docs.md) | | ||
| | `cscli hubtest`, asserts, test fails in CI, running tests without root | [references/testing.md](./references/testing.md) | | ||
| | WAF rule, `vpatch-CVE-…`, nuclei test | [references/appsec-rules.md](./references/appsec-rules.md) | | ||
| | "review PR #N", self-review before opening a PR | [references/review-checklist.md](./references/review-checklist.md) | | ||
|
|
||
| ## Non-negotiables | ||
|
|
||
| - 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. | ||
| - 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. | ||
114 changes: 114 additions & 0 deletions
114
skills/crowdsec-hub-authoring/references/appsec-rules.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| --- | ||
| verified: | ||
| - date: 2026-11-27 | ||
| version: "1.8.2" | ||
| env: hubtest | ||
| notes: "example vpatch rule + hubtest create/run --appsec with the hub docker/appsec OpenResty target and nuclei; negative control fails; crowdsec-local-mcp 0.9.3 tools (fetch, validate, lint, run_waf_tests positive + negative, prepare_waf_pr)" | ||
| --- | ||
|
|
||
| # Authoring — AppSec (WAF) rules | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we also need to mention the companion
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added (0b2230d). |
||
|
|
||
| Canonical docs: create <https://docs.crowdsec.net/docs/next/appsec/create_rules> · syntax <https://docs.crowdsec.net/docs/next/appsec/rules_syntax> · contributing <https://docs.crowdsec.net/docs/next/contributing/hub/appsec_rules> | ||
|
|
||
| For deploying/operating the WAF, use the `crowdsec` skill (`references/appsec/`). | ||
|
sabban marked this conversation as resolved.
Resolved
|
||
|
|
||
| To draft and pre-test a rule, use the [crowdsec-local-mcp](https://github.com/crowdsecurity/crowdsec-local-mcp) MCP server (`uvx --from crowdsec-local-mcp init claude-code`): | ||
|
|
||
| - `generate_waf_rule` / `generate_waf_tests` return prompts; you write the rule. | ||
| - `fetch_nuclei_exploit <CVE>` pulls the nuclei template from projectdiscovery. | ||
| - `validate_waf_rule` checks the schema, `lint_waf_rule` gives hints. | ||
| - `run_waf_tests` runs the nuclei template against a Docker CrowdSec + OpenResty stack | ||
| and fails if the request isn't blocked. | ||
|
|
||
| It doesn't replace the rules below: validation accepts a rule that matches every request | ||
| (`.*`, no labels). `prepare_waf_pr` needs `rule_filename` as `appsec-rules/<author>/<name>.yaml` | ||
| (a bare name lands at the hub root), overwrites an existing test's `config.yaml`, and adds | ||
| neither the `.md` nor the collection entry. | ||
|
|
||
| ## Naming | ||
|
|
||
| | Prefix | For | | ||
| |---|---| | ||
| | `vpatch-CVE-YYYY-NNNN` | one vulnerability; test named `CVE-YYYY-NNNN`/`vpatch-CVE-…` | | ||
| | `crs-` | OWASP CRS bridge | | ||
| | `generic-` | behavioral, not tied to one CVE | | ||
| | `experimental-` | detects, never blocks (loaded out of band) | | ||
|
|
||
| Ship a same-name `.md` next to the rule (`appsec-rules/<author>/<name>.md`): what it | ||
| detects, the CVE or advisory link, affected versions. Most existing `vpatch-*` rules | ||
| lack one; new rules include it. Format: [collections-and-docs.md](./collections-and-docs.md). | ||
|
|
||
| ## Rule skeleton | ||
|
|
||
| ```yaml | ||
| name: crowdsecurity/vpatch-CVE-2025-49113 | ||
| description: 'Detects RCE via PHP object deserialization in Roundcube' | ||
| rules: | ||
| - and: | ||
| - zones: [METHOD] | ||
| match: {type: equals, value: POST} | ||
| - zones: [ARGS] | ||
| variables: [_action] | ||
| transform: [urldecode, lowercase] | ||
| match: {type: equals, value: upload} | ||
| - zones: [ARGS] | ||
| variables: [_from] | ||
| transform: [urldecode, lowercase] | ||
| match: {type: regex, value: "[^\\w.-]"} | ||
| labels: | ||
| type: exploit | ||
| service: http | ||
| confidence: 3 | ||
| spoofable: 0 | ||
| behavior: 'http:exploit' | ||
| label: "Roundcube - RCE" | ||
| classification: | ||
| - cve.CVE-2025-49113 | ||
| - attack.T1190 | ||
| - cwe.CWE-502 | ||
| ``` | ||
|
|
||
| ## What reviewers check | ||
|
|
||
| - **Precision over breadth**: scope to the vulnerable endpoint/parameter of the | ||
| vulnerable product. Prefer "value contains characters a legit value never has" | ||
| (`[^a-z0-9]`, negative regex) over matching one exploit string (#1737, #1738, #1739). | ||
| Consider `libinjection` helpers for injection classes (#1299, #1236). | ||
| - If the rule **can't tell an attacker from a legit request** (auth bypass with a | ||
| valid-looking token, legit admin actions), it is closed, not merged (#1604, #1488, #1483, #1486, #1491). | ||
| - Apply `transform` (`urldecode`, `lowercase`) before matching; check body vs args zones. | ||
| - `label`: "Product - Vulnerability class" ("Cacti RCE", "F5 BIG-IP iControl REST - Authentication Bypass"), | ||
| no "Attempt" (#885, #1347, #1011). | ||
| - `classification` must match the CVE; disclosure-only rules shouldn't share the | ||
| RCE CVE bucket unintentionally (#1714). | ||
| - Metadata (product names, versions, URLs) must match what the rule actually covers. | ||
|
|
||
| ## Test (`.appsec-tests/<test>/`) | ||
|
|
||
| ```yaml | ||
| # config.yaml | ||
| appsec-rules: | ||
| - ./appsec-rules/crowdsecurity/base-config.yaml | ||
| - ./appsec-rules/crowdsecurity/vpatch-CVE-2025-49113.yaml | ||
| nuclei_template: vpatch-CVE-2025-49113.yaml | ||
| ``` | ||
|
|
||
| The nuclei template sends the exploit request(s) and expects `403` (blocked). | ||
| Capture real requests with `nc -lvp 4245` + the PoC. Run: | ||
|
|
||
| ```bash | ||
| cscli hubtest create vpatch-CVE-YYYY-NNNN --appsec | ||
| cscli hubtest run vpatch-CVE-YYYY-NNNN --appsec | ||
| ``` | ||
|
|
||
| Add a test when matching logic, transforms or exclusions change. | ||
|
|
||
| ## Collections and CI | ||
|
|
||
| - New `vpatch-*` rules must be listed in `collections/crowdsecurity/appsec-virtual-patching.yaml` | ||
| (`appsec_vpatch_lint` comments otherwise); product-specific ones may go in a product | ||
| vpatch collection (e.g. WordPress) (#1737–#1739). | ||
| - Adding a rule to an appsec-config is not enough for it to be downloaded — it must be | ||
| in a collection (#1393); `generic-*` collections need `crowdsecurity/base-config` (#1011). | ||
| - `waf-check` replays legitimate traffic and fails on false positives even if the rule's | ||
| own test passes. | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.