Fix: Remove regex pattern length restriction (#2087)
In this PR I removed the regex pattern length restriction because from multi value variables this length can be easly reached, also if the regex is going to be too long it will be caught in the timeout. Fixes #2086
This commit is contained in:
5
.changeset/soft-kids-watch.md
Normal file
5
.changeset/soft-kids-watch.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'grafana-zabbix': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix: Remove regex pattern length restriction
|
||||||
@@ -155,11 +155,6 @@ func parseFilter(filter string) (*regexp2.Regexp, error) {
|
|||||||
return nil, backend.DownstreamErrorf("error parsing regexp: potentially dangerous regex pattern detected")
|
return nil, backend.DownstreamErrorf("error parsing regexp: potentially dangerous regex pattern detected")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Security: Limit regex pattern length
|
|
||||||
if len(regexPattern) > 1000 {
|
|
||||||
return nil, backend.DownstreamErrorf("error parsing regexp: pattern too long (max 1000 characters)")
|
|
||||||
}
|
|
||||||
|
|
||||||
pattern := ""
|
pattern := ""
|
||||||
if matches[2] != "" {
|
if matches[2] != "" {
|
||||||
if flagRE.MatchString(matches[2]) {
|
if flagRE.MatchString(matches[2]) {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package zabbix
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/dlclark/regexp2"
|
"github.com/dlclark/regexp2"
|
||||||
@@ -124,13 +123,6 @@ func TestParseFilter(t *testing.T) {
|
|||||||
expectNoError: false,
|
expectNoError: false,
|
||||||
expectedError: "error parsing regexp: potentially dangerous regex pattern detected",
|
expectedError: "error parsing regexp: potentially dangerous regex pattern detected",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "Pattern too long",
|
|
||||||
filter: "/" + strings.Repeat("a", 1001) + "/",
|
|
||||||
want: nil,
|
|
||||||
expectNoError: false,
|
|
||||||
expectedError: "error parsing regexp: pattern too long (max 1000 characters)",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "Safe complex regex",
|
name: "Safe complex regex",
|
||||||
filter: "/^[a-zA-Z0-9_-]+\\.[a-zA-Z]{2,}$/",
|
filter: "/^[a-zA-Z0-9_-]+\\.[a-zA-Z]{2,}$/",
|
||||||
|
|||||||
Reference in New Issue
Block a user