Skip to content

API: GET /v1/alerts returns null instead of [] when nothing matches #4652

Description

@shamoon

What happened?

Filing this from gethomepage/homepage, where it broke a widget.

GET /v1/alerts returns a bare null when the filters match nothing, rather than an empty array. The swagger says the response is an array:

GetAlertsResponse:
  title: AlertsResponse
  type: array
  items:
    $ref: '#/definitions/Alert'

Same issue is present on decisions.

I tried searching and actually found #2397 which looks like it was fixed but not for the API?

What did you expect to happen?

Would expect an empty array []

How can we reproduce it (as minimally and precisely as possible)?

Repro is any filter that matches nothing, like limiting to since=1s

$ curl -si -H "Authorization: Bearer $TOKEN" "http://lapi:8180/v1/alerts?since=1s"
HTTP/1.1 200 OK
Content-Length: 4

null

Anything else we need to know?

No response

Crowdsec version

Details
$ cscli version
version: v1.8.0-cc76dbbc
Codename: alphaga
BuildDate: 2026-09-01_12:31:35
GoVersion: 1.26.7
Platform: docker
libre2: C++
User-Agent: crowdsec/v1.8.0-cc76dbbc-docker
Constraint_parser: >= 1.0, <= 3.0
Constraint_scenario: >= 1.0, <= 3.0
Constraint_api: v1
Constraint_acquis: >= 1.0, < 2.0
Built-in optional components: cscli_setup, datasource_appsec, datasource_cloudwatch, datasource_docker, datasource_file, datasource_http, datasource_journalctl, datasource_k8s-audit, datasource_kafka, datasource_kinesis, datasource_kubernetes, datasource_loki, datasource_s3, datasource_syslog, datasource_victorialogs, datasource_wineventlog, db_mysql, db_postgres, db_sqlite

OS version

Details
# On Linux:
$ cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.24.1
PRETTY_NAME="Alpine Linux v3.24"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
$ uname -a
Linux 965fdfd8a117 6.8.0-51-generic #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec  5 13:09:44 UTC 2024 x86_64 Linux

Enabled collections and parsers

Details
$ cscli hub list -o raw
Loaded: 166 parsers, 12 postoverflows, 786 scenarios, 10 contexts, 18 appsec-configs, 222 appsec-rules, 171 collections
Unmanaged items: 1 local, 0 tainted
name,status,version,description,type
crowdsecurity/cri-logs,enabled,0.1,CRI logging format parser,parsers
crowdsecurity/dateparse-enrich,enabled,0.2,,parsers
crowdsecurity/docker-logs,enabled,0.1,docker json logs parser,parsers
crowdsecurity/geoip-enrich,enabled,0.5,"Populate event with geoloc info : as, country, coords, source range.",parsers
crowdsecurity/http-logs,enabled,1.3,"Parse more Specifically HTTP logs, such as HTTP Code, HTTP path, HTTP args and if its a static ressource",parsers
crowdsecurity/public-dns-allowlist,enabled,0.1,Allow events from public DNS servers,parsers
crowdsecurity/sshd-logs,enabled,3.1,Parse openSSH logs,parsers
crowdsecurity/sshd-success-logs,enabled,0.1,Parse successful ssh logins,parsers
crowdsecurity/syslog-logs,enabled,1.0,,parsers
crowdsecurity/traefik-logs,enabled,1.5,Parse Traefik access logs,parsers
crowdsecurity/whitelists,"enabled,local",,,parsers
LePresidente/authelia-logs,enabled,0.9,Parse Authelia logs,parsers
crowdsecurity/cdn-whitelist,enabled,0.5,Whitelist CDN providers,postoverflows
crowdsecurity/google-special-crawlers-whitelist,enabled,0.1,"Whitelist events from Google special crawlers (e.g. Google-InspectionTool, GoogleOther)",postoverflows
crowdsecurity/rdns,enabled,0.4,Lookup the DNS associated to the source IP only for overflows,postoverflows
crowdsecurity/seo-bots-whitelist,enabled,0.5,Whitelist good search engine crawlers,postoverflows
crowdsecurity/apache_log4j2_cve-2021-44228,enabled,0.7,Detect cve-2021-44228 exploitation attempts,scenarios
crowdsecurity/CVE-2017-9841,enabled,0.2,Detect CVE-2017-9841 exploits,scenarios
crowdsecurity/CVE-2019-18935,enabled,0.2,Detect Telerik CVE-2019-18935 exploitation attempts,scenarios
crowdsecurity/CVE-2022-26134,enabled,0.4,Confluence - RCE (CVE-2022-26134),scenarios
crowdsecurity/CVE-2022-35914,enabled,0.2,Detect CVE-2022-35914 exploits,scenarios
crowdsecurity/CVE-2022-37042,enabled,0.2,Detect CVE-2022-37042 exploits,scenarios
crowdsecurity/CVE-2022-40684,enabled,0.3,Detect cve-2022-40684 exploitation attempts,scenarios
crowdsecurity/CVE-2022-41082,enabled,0.4,Detect CVE-2022-41082 exploits,scenarios
crowdsecurity/CVE-2022-41697,enabled,0.2,Detect CVE-2022-41697 enumeration,scenarios
crowdsecurity/CVE-2022-42889,enabled,0.3,Detect CVE-2022-42889 exploits (Text4Shell),scenarios
crowdsecurity/CVE-2022-44877,enabled,0.4,Detect CVE-2022-44877 exploits,scenarios
crowdsecurity/CVE-2022-46169,enabled,0.2,Detect CVE-2022-46169 brute forcing,scenarios
crowdsecurity/CVE-2023-22515,enabled,0.1,Detect CVE-2023-22515 exploitation,scenarios
crowdsecurity/CVE-2023-22518,enabled,0.3,Detect CVE-2023-22518 exploits,scenarios
crowdsecurity/CVE-2023-49103,enabled,0.3,Detect owncloud CVE-2023-49103 exploitation attempts,scenarios
crowdsecurity/CVE-2024-0012,enabled,0.1,Detect CVE-2024-0012 exploitation attempts,scenarios
crowdsecurity/CVE-2024-38475,enabled,0.1,Detect CVE-2024-38475 exploitation attempts,scenarios
crowdsecurity/CVE-2024-9474,enabled,0.1,Detect CVE-2024-9474 exploitation attempts,scenarios
crowdsecurity/f5-big-ip-cve-2020-5902,enabled,0.3,F5 BIG-IP TMUI - RCE (CVE-2020-5902),scenarios
crowdsecurity/fortinet-cve-2018-13379,enabled,0.4,Detect cve-2018-13379 exploitation attempts,scenarios
crowdsecurity/grafana-cve-2021-43798,enabled,0.3,Grafana - Arbitrary File Read (CVE-2021-43798),scenarios
crowdsecurity/http-admin-interface-probing,enabled,0.5,Detect generic HTTP admin interface probing,scenarios
crowdsecurity/http-backdoors-attempts,enabled,0.6,Detect attempt to common backdoors,scenarios
crowdsecurity/http-bad-user-agent,enabled,1.2,Detect usage of bad User Agent,scenarios
crowdsecurity/http-crawl-non_statics,enabled,0.7,Detect aggressive crawl on non static resources,scenarios
crowdsecurity/http-cve-2021-41773,enabled,0.3,Apache - Path Traversal (CVE-2021-41773),scenarios
crowdsecurity/http-cve-2021-42013,enabled,0.3,Apache - Path Traversal (CVE-2021-42013),scenarios
crowdsecurity/http-cve-probing,enabled,0.6,Detect generic HTTP cve probing,scenarios
crowdsecurity/http-generic-bf,enabled,0.9,Detect generic http brute force,scenarios
crowdsecurity/http-generic-test,enabled,0.2,Crowdsec Generic Test Scenario: basic HTTP trigger,scenarios
crowdsecurity/http-open-proxy,enabled,0.5,Detect scan for open proxy,scenarios
crowdsecurity/http-path-traversal-probing,enabled,0.4,Detect path traversal attempt,scenarios
crowdsecurity/http-probing,enabled,0.4,Detect site scanning/probing from a single ip,scenarios
crowdsecurity/http-sap-interface-probing,enabled,0.1,Detect generic HTTP SAP interface probing,scenarios
crowdsecurity/http-sensitive-files,enabled,0.4,"Detect attempt to access to sensitive files (.log, .db ..) or folders (.git)",scenarios
crowdsecurity/http-sqli-probing,enabled,0.4,A scenario that detects SQL injection probing with minimal false positives,scenarios
crowdsecurity/http-technology-probing,enabled,0.1,Detect HTTP technology/vendor probing,scenarios
crowdsecurity/http-wordpress-scan,enabled,0.4,Detect exploitation attempts against common WordPress endpoints,scenarios
crowdsecurity/http-xss-probing,enabled,0.4,A scenario that detects XSS probing with minimal false positives,scenarios
crowdsecurity/jira_cve-2021-26086,enabled,0.4,Detect Atlassian Jira CVE-2021-26086 exploitation attempts,scenarios
crowdsecurity/netgear_rce,enabled,0.4,Detect Netgear RCE DGN1000/DGN220 exploitation attempts,scenarios
crowdsecurity/pulse-secure-sslvpn-cve-2019-11510,enabled,0.4,Detect cve-2019-11510 exploitation attempts,scenarios
crowdsecurity/spring4shell_cve-2022-22965,enabled,0.3,Detect cve-2022-22965 probing,scenarios
crowdsecurity/ssh-bf,enabled,0.3,Detect ssh bruteforce,scenarios
crowdsecurity/ssh-cve-2024-6387,enabled,0.2,Detect exploitation attempt of CVE-2024-6387,scenarios
crowdsecurity/ssh-generic-test,enabled,0.2,Crowdsec Generic Test Scenario: SSH brute force trigger,scenarios
crowdsecurity/ssh-refused-conn,enabled,0.1,Detect sshd refused connections,scenarios
crowdsecurity/ssh-slow-bf,enabled,0.4,Detect slow ssh bruteforce,scenarios
crowdsecurity/ssh-time-based-bf,enabled,0.3,Detect time-based ssh bruteforce attempts that evade rate limiting (with false positive reduction),scenarios
crowdsecurity/thinkphp-cve-2018-20062,enabled,0.7,Detect ThinkPHP CVE-2018-20062 exploitation attempts,scenarios
crowdsecurity/vmware-cve-2022-22954,enabled,0.3,Detect Vmware CVE-2022-22954 exploitation attempts,scenarios
crowdsecurity/vmware-vcenter-vmsa-2021-0027,enabled,0.3,Detect VMSA-2021-0027 exploitation attempts,scenarios
LePresidente/authelia-bf,enabled,0.5,Detect authelia bruteforce,scenarios
ltsich/http-w00tw00t,enabled,0.3,detect w00tw00t,scenarios
crowdsecurity/bf_base,enabled,0.1,,contexts
crowdsecurity/http_base,enabled,0.3,,contexts
crowdsecurity/base-http-scenarios,enabled,1.4,http common : scanners detection,collections
crowdsecurity/http-cve,enabled,3.0,Detect CVE exploitation in http logs,collections
crowdsecurity/linux,enabled,0.4,core linux support : syslog+geoip+ssh,collections
crowdsecurity/sshd,enabled,0.9,sshd support : parser and brute-force detection,collections
crowdsecurity/traefik,enabled,0.2,traefik support: parser and generic http scenarios,collections
crowdsecurity/whitelist-good-actors,enabled,0.4,Good actors whitelists,collections
LePresidente/authelia,enabled,0.2,Authelia Support : parser and brute-force detection,collections

Acquisition config

Details
# On Linux:
$ cat /etc/crowdsec/acquis.yaml /etc/crowdsec/acquis.d/*
filenames:
  - /var/log/traefik/*.log
labels:
  type: traefik
---
filenames:
  - /var/log/authelia/*.log
labels:
  type: authelia
cat: can't open '/etc/crowdsec/acquis.d/*': No such file or directory

Config show

Details
$ cscli config show
Global:
   - Configuration Folder   : /etc/crowdsec
   - Data Folder            : /var/lib/crowdsec/data
   - Hub Folder             : /etc/crowdsec/hub
   - Notification Folder    : /etc/crowdsec/notifications
   - Simulation File        : /etc/crowdsec/simulation.yaml
   - Log Folder             : /var/log
   - Log level              : info
   - Log Media              : stdout
Crowdsec:
  - Acquisition File        : /etc/crowdsec/acquis.yaml
  - Parsers routines        : 1
cscli:
  - Output                  : human
  - Hub Branch              : 
API Client:
  - URL                     : http://0.0.0.0:8080/
  - Login                   : localhost
  - Credentials File        : /etc/crowdsec/local_api_credentials.yaml
Local API Server:
  - Listen URL              : 0.0.0.0:8080
  - Listen Socket           : 
  - Profile File            : /etc/crowdsec/profiles.yaml

  - Trusted IPs:
      - 127.0.0.1
      - ::1
  - Database:
      - Type                : sqlite
      - Path                : /var/lib/crowdsec/data/crowdsec.db
      - Flush age           : 168h0m0s
      - Flush size          : 5000

Prometheus metrics

Details
$ cscli metrics
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Acquisition Metrics                                                                                                           │
├─────────────────────────────────────┬────────────┬──────────────┬────────────────┬────────────────────────┬───────────────────┤
│ Source                              │ Lines read │ Lines parsed │ Lines unparsed │ Lines poured to bucket │ Lines whitelisted │
├─────────────────────────────────────┼────────────┼──────────────┼────────────────┼────────────────────────┼───────────────────┤
│ file:/var/log/authelia/authelia.log │ 357        │ 357          │ -              │ -                      │ 11                │
│ file:/var/log/traefik/access.log    │ 1.70k      │ 1.70k        │ -              │ 2.48k                  │ 236               │
╰─────────────────────────────────────┴────────────┴──────────────┴────────────────┴────────────────────────┴───────────────────╯
╭────────────────────────────────────────────────────╮
│ Local API Alerts                                   │
├────────────────────────────────────────────┬───────┤
│ Reason                                     │ Count │
├────────────────────────────────────────────┼───────┤
│ crowdsecurity/http-path-traversal-probing  │ 9     │
│ crowdsecurity/http-probing                 │ 89    │
│ crowdsecurity/thinkphp-cve-2018-20062      │ 3     │
│ LePresidente/http-generic-401-bf           │ 3     │
│ LePresidente/http-generic-403-bf           │ 1     │
│ crowdsecurity/CVE-2022-41082               │ 3     │
│ crowdsecurity/http-crawl-non_statics       │ 63    │
│ crowdsecurity/http-cve-probing             │ 10    │
│ crowdsecurity/http-sensitive-files         │ 147   │
│ crowdsecurity/http-technology-probing      │ 35    │
│ crowdsecurity/jira_cve-2021-26086          │ 1     │
│ crowdsecurity/CVE-2017-9841                │ 7     │
│ crowdsecurity/http-admin-interface-probing │ 13    │
╰────────────────────────────────────────────┴───────╯
╭────────────────────────────────────────────────────────────────────────╮
│ Local API Decisions                                                    │
├────────────────────────────────────────────┬──────────┬────────┬───────┤
│ Reason                                     │ Origin   │ Action │ Count │
├────────────────────────────────────────────┼──────────┼────────┼───────┤
│ http:bruteforce                            │ CAPI     │ ban    │ 434   │
│ http:crawl                                 │ CAPI     │ ban    │ 61    │
│ http:exploit                               │ CAPI     │ ban    │ 580   │
│ crowdsecurity/http-admin-interface-probing │ crowdsec │ ban    │ 1     │
│ crowdsecurity/http-path-traversal-probing  │ crowdsec │ ban    │ 2     │
│ http:scan                                  │ CAPI     │ ban    │ 22407 │
│ crowdsecurity/http-crawl-non_statics       │ crowdsec │ ban    │ 1     │
│ crowdsecurity/http-probing                 │ crowdsec │ ban    │ 1     │
│ crowdsecurity/http-sensitive-files         │ crowdsec │ ban    │ 1     │
╰────────────────────────────────────────────┴──────────┴────────┴───────╯
╭────────────────────────────────────╮
│ Local API Metrics                  │
├────────────────────┬────────┬──────┤
│ Route              │ Method │ Hits │
├────────────────────┼────────┼──────┤
│ /v1/alerts         │ GET    │ 9    │
│ /v1/alerts         │ POST   │ 5    │
│ /v1/decisions      │ GET    │ 220  │
│ /v1/heartbeat      │ GET    │ 591  │
│ /v1/usage-metrics  │ POST   │ 20   │
│ /v1/watchers/login │ POST   │ 14   │
╰────────────────────┴────────┴──────╯
╭────────────────────────────────────────────────────────────╮
│ Local API Bouncers Metrics                                 │
├────────────────────────────┬───────────────┬────────┬──────┤
│ Bouncer                    │ Route         │ Method │ Hits │
├────────────────────────────┼───────────────┼────────┼──────┤
│ bouncer-traefik@172.19.0.3 │ /v1/decisions │ GET    │ 220  │
╰────────────────────────────┴───────────────┴────────┴──────╯
╭────────────────────────────────────────────────────────────────╮
│ Local API Bouncers Decisions                                   │
├────────────────────────────┬───────────────┬───────────────────┤
│ Bouncer                    │ Empty answers │ Non-empty answers │
├────────────────────────────┼───────────────┼───────────────────┤
│ bouncer-traefik@172.19.0.3 │ 214           │ 6                 │
╰────────────────────────────┴───────────────┴───────────────────╯
╭───────────────────────────────────────────╮
│ Local API Machines Metrics                │
├───────────┬───────────────┬────────┬──────┤
│ Machine   │ Route         │ Method │ Hits │
├───────────┼───────────────┼────────┼──────┤
│ localhost │ /v1/alerts    │ GET    │ 8    │
│ localhost │ /v1/alerts    │ POST   │ 5    │
│ localhost │ /v1/heartbeat │ GET    │ 591  │
╰───────────┴───────────────┴────────┴──────╯
╭─────────────────────────────────────────────────────────────────────────────╮
│ Parser Metrics                                                              │
├─────────────────────────────────────────────────┬───────┬────────┬──────────┤
│ Parsers                                         │ Hits  │ Parsed │ Unparsed │
├─────────────────────────────────────────────────┼───────┼────────┼──────────┤
│ LePresidente/authelia-logs                      │ 357   │ 357    │ -        │
│ child-LePresidente/authelia-logs                │ 1.43k │ 714    │ 714      │
│ child-child-crowdsecurity/traefik-logs          │ 1.70k │ 1.70k  │ -        │
│ child-crowdsecurity/http-logs                   │ 5.10k │ 3.76k  │ 1.34k    │
│ child-crowdsecurity/traefik-logs                │ 1.70k │ 1.70k  │ -        │
│ crowdsecurity/cdn-whitelist                     │ 8     │ 8      │ -        │
│ crowdsecurity/dateparse-enrich                  │ 2.06k │ 2.06k  │ -        │
│ crowdsecurity/geoip-enrich                      │ 1.77k │ 1.77k  │ -        │
│ crowdsecurity/google-special-crawlers-whitelist │ 8     │ 8      │ -        │
│ crowdsecurity/http-logs                         │ 1.70k │ 1.70k  │ -        │
│ crowdsecurity/non-syslog                        │ 2.06k │ 2.06k  │ -        │
│ crowdsecurity/public-dns-allowlist              │ 2.06k │ 2.06k  │ -        │
│ crowdsecurity/rdns                              │ 8     │ 8      │ -        │
│ crowdsecurity/seo-bots-whitelist                │ 8     │ 8      │ -        │
│ crowdsecurity/traefik-logs                      │ 1.70k │ 1.70k  │ -        │
│ crowdsecurity/whitelists                        │ 2.06k │ 2.06k  │ -        │
╰─────────────────────────────────────────────────┴───────┴────────┴──────────╯
╭──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Scenario Metrics                                                                                         │
├────────────────────────────────────────────┬───────────────┬───────────┬──────────────┬────────┬─────────┤
│ Scenario                                   │ Current Count │ Overflows │ Instantiated │ Poured │ Expired │
├────────────────────────────────────────────┼───────────────┼───────────┼──────────────┼────────┼─────────┤
│ crowdsecurity/http-admin-interface-probing │ -             │ 4         │ 5            │ 14     │ 1       │
│ crowdsecurity/http-crawl-non_statics       │ -             │ 17        │ 103          │ 906    │ 86      │
│ crowdsecurity/http-path-traversal-probing  │ -             │ 14        │ 15           │ 58     │ 1       │
│ crowdsecurity/http-probing                 │ -             │ 108       │ 138          │ 1.24k  │ 30      │
│ crowdsecurity/http-sensitive-files         │ -             │ 50        │ 55           │ 258    │ 5       │
│ crowdsecurity/http-technology-probing      │ -             │ 3         │ 3            │ -      │ -       │
╰────────────────────────────────────────────┴───────────────┴───────────┴──────────────┴────────┴─────────╯
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Whitelist Metrics                                                                                         │
├─────────────────────────────────────────────────┬────────────────────────────────────┬──────┬─────────────┤
│ Whitelist                                       │ Reason                             │ Hits │ Whitelisted │
├─────────────────────────────────────────────────┼────────────────────────────────────┼──────┼─────────────┤
│ crowdsecurity/cdn-whitelist                     │ CDN provider                       │ 8    │ -           │
│ crowdsecurity/google-special-crawlers-whitelist │ Google special crawlers ip range   │ 8    │ -           │
│ crowdsecurity/public-dns-allowlist              │ public DNS server                  │ 2056 │ -           │
│ crowdsecurity/seo-bots-whitelist                │ good bots (search engine crawlers) │ 8    │ -           │
│ crowdsecurity/whitelists                        │ my ip ranges                       │ 2056 │ 247         │
╰─────────────────────────────────────────────────┴────────────────────────────────────┴──────┴─────────────╯

Related custom configs versions (if applicable) : notification plugins, custom scenarios, parsers etc.

Details

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions