Panic in EvalAlertContextRules when a context expression returns nil
メンテナーはふだん 4 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
panic は default 分岐の EvalAlertContextRules(pkg/alertcontext/alertcontext.go、214 行目付近)にあり、EventToContext と NewAlert から到達します。まずその分岐を読んでください。nil の output(または !r.IsValid())に対して IsZero() の前にガードし、IsNil() を nillable な kind に限定します。nil を返す式を使って pkg/alertcontext のテストにケースを追加し、panic する代わりにスキップされることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Go
- スター
- 15.1k
- フォーク
- 726
- 平均マージ
- 4日 23時間
- マージ済み PR(30日)
- 27
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
crowdsecurity/crowdsec のほかの issue
-
needs/kind needs/triage
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
crowdsecurity/crowdsec#4849 · コメント 2 件 ·
メンテナーはふだん 4 日以内に返信
-
kind/bug needs/triage os/linux
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
crowdsecurity/crowdsec#4836 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
victorialogs datasource passes the trailing newline of a message to the parsers (traefik-logs 1.6 fails on every line)対応中かも @IlayWolfson が 6 日前に担当しました。 オープンkind/bug needs/triage os/linux version/1.8.2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
crowdsecurity/crowdsec#4820 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
[email protected]オープンneeds/kind needs/triage
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
crowdsecurity/crowdsec#4842 · コメント 3 件 ·
メンテナーはふだん 4 日以内に返信
-
MySQL: idle pool connections die after wait_timeout, log shows broken pipe対応中かも @AdzerKI が 3 日前に担当しました。 オープンkind/bug needs/triage
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
crowdsecurity/crowdsec#4840 · コメント 3 件 ·
メンテナーはふだん 4 日以内に返信
crowdsecurity/crowdsec の issue をすべて見る
似ている issue
-
tld-snapshot
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
awslabs/ferret-scan#1064 ·
メンテナーはふだん 2 日以内に返信
-
enhancement
難易度 1/5 1時間未満 初心者へのやさしさ 62/100
DaoCloud/DaoCloud-docs#7839 ·
メンテナーはふだん 1 日以内に返信
-
Ignore entry for RUSTSEC-2026-0002 no longer matches anything (`lru` is no longer in `Cargo.lock`)オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
influxdata/influxdb#27767 ·
メンテナーはふだん 1 日以内に返信
-
Type: Enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
projectdiscovery/urlfinder#167 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
gojue/ecapture#1100 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信