From add13abe8e6b3d09deeae000fe9eff21913001c4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 18 Mar 2026 09:41:53 +0100 Subject: [PATCH] cli-plugins/hooks: limit maximum number of lines / messages Signed-off-by: Sebastiaan van Stijn --- cli-plugins/hooks/template.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli-plugins/hooks/template.go b/cli-plugins/hooks/template.go index 0652296001df..eca5ce4f7227 100644 --- a/cli-plugins/hooks/template.go +++ b/cli-plugins/hooks/template.go @@ -13,6 +13,8 @@ import ( "github.com/spf13/cobra" ) +const maxMessages = 10 + func ParseTemplate(hookTemplate string, cmd *cobra.Command) ([]string, error) { out := hookTemplate if strings.Contains(hookTemplate, "{{") { @@ -38,7 +40,10 @@ func ParseTemplate(hookTemplate string, cmd *cobra.Command) ([]string, error) { } out = b.String() } - return strings.Split(out, "\n"), nil + if n := strings.Count(out, "\n"); n > maxMessages { + return nil, fmt.Errorf("hook template contains too many messages (%d): maximum is %d", n, maxMessages) + } + return strings.SplitN(out, "\n", maxMessages), nil } var ErrHookTemplateParse = errors.New("failed to parse hook template")