summaryrefslogtreecommitdiff
path: root/caddyconfig/caddyfile/importargs.go
diff options
context:
space:
mode:
authorWeidiDeng <weidi_deng@icloud.com>2023-08-05 00:44:38 +0800
committerGitHub <noreply@github.com>2023-08-04 10:44:38 -0600
commit9f34383c02f1691e54280285a6499893fcbbb4c7 (patch)
treebf87ea45cb4e66dae2b5689f4a72231351dd888a /caddyconfig/caddyfile/importargs.go
parentb07b198764de738f3b473f416422eaf0619c654d (diff)
caddyfile: check that matched key is not a substring of the replacement key (#5685)
Diffstat (limited to 'caddyconfig/caddyfile/importargs.go')
-rw-r--r--caddyconfig/caddyfile/importargs.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/caddyconfig/caddyfile/importargs.go b/caddyconfig/caddyfile/importargs.go
index c6dcd85..54d648e 100644
--- a/caddyconfig/caddyfile/importargs.go
+++ b/caddyconfig/caddyfile/importargs.go
@@ -93,6 +93,11 @@ func makeArgsReplacer(args []string) *caddy.Replacer {
// TODO: Remove the deprecated {args.*} placeholder
// support at some point in the future
if matches := argsRegexpIndexDeprecated.FindStringSubmatch(key); len(matches) > 0 {
+ // What's matched may be a substring of the key
+ if matches[0] != key {
+ return nil, false
+ }
+
value, err := strconv.Atoi(matches[1])
if err != nil {
caddy.Log().Named("caddyfile").Warn(
@@ -111,6 +116,11 @@ func makeArgsReplacer(args []string) *caddy.Replacer {
// Handle args[*] form
if matches := argsRegexpIndex.FindStringSubmatch(key); len(matches) > 0 {
+ // What's matched may be a substring of the key
+ if matches[0] != key {
+ return nil, false
+ }
+
if strings.Contains(matches[1], ":") {
caddy.Log().Named("caddyfile").Warn(
"Variadic placeholder {args[" + matches[1] + "]} must be a token on its own")