fix: reject invalid any and local config (#8133)

Signed-off-by: immanuwell <pchpr.00@list.ru>
This commit is contained in:
Immanuel Tikhonov
2026-06-01 02:41:27 +04:00
committed by GitHub
parent ce0e5a6f39
commit 4c07a287da
4 changed files with 64 additions and 0 deletions

View File

@@ -9,6 +9,14 @@ import (
func init() { plugin.Register("any", setup) }
func setup(c *caddy.Controller) error {
c.Next() // 'any'
if c.NextArg() {
return plugin.Error("any", c.ArgErr())
}
if c.NextBlock() {
return plugin.Error("any", c.Errf("unknown property '%s'", c.Val()))
}
a := Any{}
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {

View File

@@ -19,3 +19,17 @@ func TestSetup(t *testing.T) {
t.Error("Expected plugin to be added to config")
}
}
func TestSetupRejectsArgs(t *testing.T) {
c := caddy.NewTestController("dns", `any example.org`)
if err := setup(c); err == nil {
t.Fatal("expected error for unexpected argument, got nil")
}
}
func TestSetupRejectsBlockOptions(t *testing.T) {
c := caddy.NewTestController("dns", `any { foo }`)
if err := setup(c); err == nil {
t.Fatal("expected error for unexpected block option, got nil")
}
}