From 17142359e0a5dfb5746fae078175c6c42467c789 Mon Sep 17 00:00:00 2001 From: Immanuel Tikhonov <122638311+immanuwell@users.noreply.github.com> Date: Sun, 24 May 2026 16:58:11 +0400 Subject: [PATCH] fix: reject unknown chaos block options (#8121) --- plugin/chaos/setup.go | 35 ++++++++++++++++++++--------------- plugin/chaos/setup_test.go | 5 +++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/plugin/chaos/setup.go b/plugin/chaos/setup.go index ce0eb7a68..782847a56 100644 --- a/plugin/chaos/setup.go +++ b/plugin/chaos/setup.go @@ -32,25 +32,30 @@ func parse(c *caddy.Controller) (string, []string, error) { if c.Next() { args := c.RemainingArgs() + authors := Owners if len(args) == 0 { - return trim(chaosVersion), Owners, nil - } - if len(args) == 1 { - return trim(args[0]), Owners, nil + version = trim(chaosVersion) + } else if len(args) == 1 { + version = trim(args[0]) + } else { + version = args[0] + authorSet := make(map[string]struct{}) + for _, a := range args[1:] { + authorSet[a] = struct{}{} + } + list := make([]string, 0, len(authorSet)) + for k := range authorSet { + k = trim(k) // limit size to 255 chars + list = append(list, k) + } + sort.Strings(list) + authors = list } - version = args[0] - authors := make(map[string]struct{}) - for _, a := range args[1:] { - authors[a] = struct{}{} + if c.NextBlock() { + return "", nil, c.Errf("unknown property '%s'", c.Val()) } - list := []string{} - for k := range authors { - k = trim(k) // limit size to 255 chars - list = append(list, k) - } - sort.Strings(list) - return version, list, nil + return version, authors, nil } return version, Owners, nil diff --git a/plugin/chaos/setup_test.go b/plugin/chaos/setup_test.go index 2c45d86d8..e3adf255b 100644 --- a/plugin/chaos/setup_test.go +++ b/plugin/chaos/setup_test.go @@ -22,6 +22,11 @@ func TestSetupChaos(t *testing.T) { { `chaos v3 "Miek Gieben"`, false, "v3", "Miek Gieben", "", }, + { + `chaos v2 { + unknown + }`, true, "", "", "unknown property", + }, } for i, test := range tests {