fix(plugins): add regex length limit (#7802)

This commit is contained in:
Ville Vesilehto
2026-01-05 19:48:48 +02:00
committed by GitHub
parent adba778626
commit b723bd94d4
15 changed files with 117 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package rewrite
import (
"strings"
"testing"
"github.com/coredns/coredns/plugin/test"
@@ -70,3 +71,14 @@ func TestRCodeRewrite(t *testing.T) {
t.Fatalf("RCode rewrite did not apply changes, request=%#v, err=%v", request.Req, err)
}
}
func TestNewRCodeRuleLargeRegex(t *testing.T) {
largeRegex := strings.Repeat("a", maxRegexpLen+1)
_, err := newRCodeRule("stop", "regex", largeRegex, "SERVFAIL", "NXDOMAIN")
if err == nil {
t.Fatal("Expected error for large regex, got nil")
}
if !strings.Contains(err.Error(), "too long") {
t.Errorf("Expected 'too long' error, got: %v", err)
}
}