From 91df2ccd567d7220095f1bc41229634dd3f21892 Mon Sep 17 00:00:00 2001 From: Tigah <88289044+TBX3D@users.noreply.github.com> Date: Wed, 22 Jul 2026 12:55:32 -0700 Subject: [PATCH] fix(modules): guard regex extractor against negative group index (#346) a module with a negative extractor group indexed matches[e.Group] past the lower bound, panicking the executor goroutine and crashing the whole scan. the existing bound only checked the upper end; check e.Group >= 0 too so an invalid group is skipped like an out-of-range one. --- internal/modules/executor.go | 2 +- internal/modules/matchers_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/modules/executor.go b/internal/modules/executor.go index 8e606b2..e77c3d0 100644 --- a/internal/modules/executor.go +++ b/internal/modules/executor.go @@ -508,7 +508,7 @@ func runExtractors(extractors []Extractor, resp *http.Response, body string) map continue } matches := re.FindStringSubmatch(part) - if len(matches) > e.Group { + if e.Group >= 0 && len(matches) > e.Group { result[e.Name] = matches[e.Group] break } diff --git a/internal/modules/matchers_test.go b/internal/modules/matchers_test.go index 46edf60..5217d3f 100644 --- a/internal/modules/matchers_test.go +++ b/internal/modules/matchers_test.go @@ -338,6 +338,14 @@ func TestRunExtractors(t *testing.T) { }, wantNil: true, }, + { + // a negative group must be skipped, not panic on matches[-1]. + name: "negative group is skipped", + extractors: []Extractor{ + {Type: "regex", Name: "session", Part: "body", Regex: []string{`"session":"([^"]+)"`}, Group: -1}, + }, + wantNil: true, + }, { name: "invalid pattern is skipped, no capture", extractors: []Extractor{