From b5ec4622993655d69ee68f3b833a69179a830f3f Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 9 Aug 2017 10:36:54 -0600 Subject: [PATCH] internal: Allow use for only X-Accel-Redir (closes #1020) (allow no arguments of paths to protect) --- caddyhttp/internalsrv/internal.go | 2 -- caddyhttp/internalsrv/setup.go | 8 +++++--- caddyhttp/internalsrv/setup_test.go | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/caddyhttp/internalsrv/internal.go b/caddyhttp/internalsrv/internal.go index c228aa70b..e698ca372 100644 --- a/caddyhttp/internalsrv/internal.go +++ b/caddyhttp/internalsrv/internal.go @@ -32,7 +32,6 @@ func isInternalRedirect(w http.ResponseWriter) bool { // ServeHTTP implements the httpserver.Handler interface. func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { - // Internal location requested? -> Not found. for _, prefix := range i.Paths { if httpserver.Path(r.URL.Path).Matches(prefix) { @@ -50,7 +49,6 @@ func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) // "down the chain" r.URL.Path = iw.Header().Get(redirectHeader) iw.ClearHeader() - status, err = i.Next.ServeHTTP(iw, r) } diff --git a/caddyhttp/internalsrv/setup.go b/caddyhttp/internalsrv/setup.go index f2f4a68c6..990fafafd 100644 --- a/caddyhttp/internalsrv/setup.go +++ b/caddyhttp/internalsrv/setup.go @@ -30,10 +30,12 @@ func internalParse(c *caddy.Controller) ([]string, error) { var paths []string for c.Next() { - if !c.NextArg() { - return paths, c.ArgErr() + if c.NextArg() { + paths = append(paths, c.Val()) + } + if c.NextArg() { + return nil, c.ArgErr() } - paths = append(paths, c.Val()) } return paths, nil diff --git a/caddyhttp/internalsrv/setup_test.go b/caddyhttp/internalsrv/setup_test.go index b7758772f..7c2b71e8d 100644 --- a/caddyhttp/internalsrv/setup_test.go +++ b/caddyhttp/internalsrv/setup_test.go @@ -41,10 +41,14 @@ func TestInternalParse(t *testing.T) { shouldErr bool expectedInternalPaths []string }{ + {`internal`, false, []string{}}, + {`internal /internal`, false, []string{"/internal"}}, {`internal /internal1 internal /internal2`, false, []string{"/internal1", "/internal2"}}, + + {`internal /internal1 /internal2`, true, nil}, } for i, test := range tests { actualInternalPaths, err := internalParse(caddy.NewTestController("http", test.inputInternalPaths))