From b31dc03b5b1a2d1ed5eec6ae3befb12d63e0fd95 Mon Sep 17 00:00:00 2001 From: Manuel Dalla Lana Date: Sat, 18 Jul 2020 15:48:36 +0200 Subject: [PATCH] Add resolve symlink feature in php_fastcgi --- modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go | 12 ++++++++++++ modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go index 03b7226cf9a6..356954660826 100644 --- a/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go +++ b/modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go @@ -39,6 +39,7 @@ func init() { // root // split // env +// resolverootsymlink // } // func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { @@ -67,6 +68,9 @@ func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { } t.EnvVars[args[0]] = args[1] + case "resolverootsymlink": + t.ResolveRootSymlink = true + default: return d.Errf("unrecognized subdirective %s", d.Val()) } @@ -196,6 +200,14 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error return nil, dispenser.ArgErr() } indexFile = args[0] + + case "resolverootsymlink": + args := dispenser.RemainingArgs() + dispenser.Delete() + for range args { + dispenser.Delete() + } + fcgiTransport.ResolveRootSymlink = true } } } diff --git a/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go b/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go index 8c0317245ab0..850d06131ee7 100644 --- a/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go +++ b/modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go @@ -54,6 +54,9 @@ type Transport struct { // that 404s if the fastcgi path info is not found. SplitPath []string `json:"split_path,omitempty"` + // Resolve symlink in root path + ResolveRootSymlink bool `json:"resolve_root_symlink,omitempty"` + // Extra environment variables. EnvVars map[string]string `json:"env,omitempty"` @@ -179,6 +182,13 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) { return nil, err } + if t.ResolveRootSymlink { + root, err = filepath.EvalSymlinks(root) + if err != nil { + return nil, err + } + } + fpath := r.URL.Path // split "actual path" from "path info" if configured