Skip to content
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

[8.13](backport #38181) x-pack/filebeat/input/{cel,websocket}: prevent addition of regexp extension when no patterns are provided #38192

Merged
merged 1 commit into from
Mar 6, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ fields added to events containing the Beats version. {pull}37553[37553]
- Fix file handle leak when handling errors in filestream {pull}37973[37973]
- Fix a race condition that could crash Filebeat with a "negative WaitGroup counter" error {pull}38094[38094]
- Fix "failed processing S3 event for object key" error on aws-s3 input when key contains the "+" character {issue}38012[38012] {pull}38125[38125]
- Fix duplicated addition of regexp extension in CEL input. {pull}38181[38181]

*Heartbeat*

Expand Down
14 changes: 14 additions & 0 deletions x-pack/filebeat/input/cel/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"reflect"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"golang.org/x/oauth2/google"
Expand All @@ -38,6 +39,19 @@ func TestGetProviderIsCanonical(t *testing.T) {
}
}

func TestRegexpConfig(t *testing.T) {
cfg := config{
Interval: time.Minute,
Program: `{}`,
Resource: &ResourceConfig{URL: &urlConfig{URL: &url.URL{}}},
Regexps: map[string]string{"regex_cve": `[Cc][Vv][Ee]-[0-9]{4}-[0-9]{4,7}`},
}
err := cfg.Validate()
if err != nil {
t.Errorf("failed to validate config with regexps: %v", err)
}
}

func TestIsEnabled(t *testing.T) {
type enabler interface {
isEnabled() bool
Expand Down
1 change: 0 additions & 1 deletion x-pack/filebeat/input/cel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@
lib.Debug(debug(log, trace)),
lib.File(mimetypes),
lib.MIME(mimetypes),
lib.Regexp(patterns),
lib.Limit(limitPolicies),
lib.Globals(map[string]interface{}{
"useragent": userAgent,
Expand Down Expand Up @@ -1157,7 +1156,7 @@
// walkMap walks to all ends of the provided path in m and applies fn to the
// final element of each walk. Nested arrays are not handled.
func walkMap(m mapstr.M, path string, fn func(parent mapstr.M, key string)) {
key, rest, more := strings.Cut(path, ".")

Check failure on line 1159 in x-pack/filebeat/input/cel/input.go

View workflow job for this annotation

GitHub Actions / lint (darwin)

rest declared and not used (typecheck)
v, ok := m[key]
if !ok {
return
Expand Down
4 changes: 3 additions & 1 deletion x-pack/filebeat/input/websocket/cel.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ func newProgram(ctx context.Context, src, root string, patterns map[string]*rege
lib.Try(),
lib.Debug(debug(log)),
lib.MIME(mimetypes),
lib.Regexp(patterns),
lib.Globals(map[string]interface{}{
"useragent": userAgent,
}),
}
if len(patterns) != 0 {
opts = append(opts, lib.Regexp(patterns))
}

env, err := cel.NewEnv(opts...)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions x-pack/filebeat/input/websocket/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package websocket

import (
"fmt"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -119,3 +120,15 @@ func TestConfig(t *testing.T) {
})
}
}

func TestRegexpConfig(t *testing.T) {
cfg := config{
Program: `{}`,
URL: &urlConfig{URL: &url.URL{Scheme: "ws"}},
Regexps: map[string]string{"regex_cve": `[Cc][Vv][Ee]-[0-9]{4}-[0-9]{4,7}`},
}
err := cfg.Validate()
if err != nil {
t.Errorf("failed to validate config with regexps: %v", err)
}
}
Loading