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

@@ -9,6 +9,10 @@ import (
"github.com/coredns/coredns/plugin"
)
// maxRegexpLen is a hard limit on the length of a regex pattern to prevent
// OOM during regex compilation with malicious input.
const maxRegexpLen = 10000
func init() { plugin.Register("errors", setup) }
func setup(c *caddy.Controller) error {
@@ -78,6 +82,9 @@ func parseConsolidate(c *caddy.Controller) (*pattern, error) {
if err != nil {
return nil, c.Err(err.Error())
}
if len(args[1]) > maxRegexpLen {
return nil, c.Errf("regex pattern too long: %d > %d", len(args[1]), maxRegexpLen)
}
re, err := regexp.Compile(args[1])
if err != nil {
return nil, c.Err(err.Error())