Panic in EvalAlertContextRules when a context expression returns nil
Maintainer thường phản hồi trong vòng 4 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
Hướng nghiên cứu
Panic nằm trong nhánh default của EvalAlertContextRules trong pkg/alertcontext/alertcontext.go (khoảng dòng 214), được đến từ EventToContext và NewAlert. Hãy đọc nhánh đó trước: bảo vệ trước một output nil (hoặc !r.IsValid()) trước IsZero(), và giới hạn IsNil() cho các kind nillable. Thêm một case vào các test của pkg/alertcontext với một biểu thức trả về nil và xác nhận rằng nó bị bỏ qua thay vì panic.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happened
crowdsec crashes with a panic when an alert context expression evaluates to nil:
error: reflect: call of reflect.Value.IsZero on zero Value
reflect.Value.IsZero({0x0?, 0x0?, ...})
reflect/value.go:1746
github.com/crowdsecurity/crowdsec/pkg/alertcontext.EvalAlertContextRules(...)
github.com/crowdsecurity/crowdsec/pkg/alertcontext/alertcontext.go:214
github.com/crowdsecurity/crowdsec/pkg/alertcontext.EventToContext(...)
github.com/crowdsecurity/crowdsec/pkg/alertcontext/alertcontext.go:257
github.com/crowdsecurity/crowdsec/pkg/leakybucket.NewAlert(...)
github.com/crowdsecurity/crowdsec/pkg/leakybucket/overflows.go:371
The whole agent goes down, so every bucket overflow that hits the expression kills crowdsec. With systemd restarting it, this ends in a crash loop, and bouncers can no longer reach the LAPI.
How to reproduce
Add a context file such as /etc/crowdsec/contexts/example.yaml:
context:
example:
- "get(evt.Unmarshaled.caddy.resp_headers, 'X-Example') != nil ? evt.Unmarshaled.caddy.resp_headers['X-Example'][0] : nil"
Trigger any scenario overflow for an event where the header is missing.
Cause
In pkg/alertcontext/alertcontext.go the default branch does:
r := reflect.ValueOf(output)
if r.IsZero() || r.IsNil() {
continue
}
For output == nil, reflect.ValueOf returns the zero reflect.Value, and IsZero() panics on it. The IsNil() check shows that nil was meant to be skipped. The same code is still on master.
Suggested fix
Check output == nil (or !r.IsValid()) before calling IsZero(), for example:
default:
if output == nil {
continue
}
r := reflect.ValueOf(output)
if r.IsZero() {
continue
}
Note that r.IsNil() can also panic for kinds that are not nillable (e.g. structs, bools), so it should probably be guarded by a kind check as well.
Workaround
Return '' instead of nil in the expression. Empty strings are skipped in the string branch.
Environment
- crowdsec v1.8.2 (Debian package,
v1.8.2-debian-pragmatic-amd64), also seen with v1.8.1 - Ubuntu 26.04, amd64
- Ngôn ngữ chính
- Go
- Star
- 15.1k
- Fork
- 726
- Merge trung bình
- 4 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 27
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của crowdsecurity/crowdsec
-
needs/kind needs/triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
crowdsecurity/crowdsec#4849 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
kind/bug needs/triage os/linux
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
crowdsecurity/crowdsec#4836 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
victorialogs datasource passes the trailing newline of a message to the parsers (traefik-logs 1.6 fails on every line)Có thể đã có người làm @IlayWolfson đã nhận 6 ngày trước. Đang mởkind/bug needs/triage os/linux version/1.8.2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
crowdsecurity/crowdsec#4820 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
[email protected]Đang mởneeds/kind needs/triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
crowdsecurity/crowdsec#4842 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
MySQL: idle pool connections die after wait_timeout, log shows broken pipeCó thể đã có người làm @AdzerKI đã nhận 3 ngày trước. Đang mởkind/bug needs/triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
crowdsecurity/crowdsec#4840 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
Tất cả issue của crowdsecurity/crowdsec
Issue tương tự
-
tld-snapshot
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
awslabs/ferret-scan#1064 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
【文档错误】创建镜像空间步骤中的截图标注与文字描述不一致Đang mởenhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
DaoCloud/DaoCloud-docs#7839 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Ignore entry for RUSTSEC-2026-0002 no longer matches anything (`lru` is no longer in `Cargo.lock`)Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
influxdata/influxdb#27767 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Support AlienVault OTX API keysĐang mởType: Enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
projectdiscovery/urlfinder#167 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
gojue/ecapture#1100 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày