@marcel91200 / caddy Mirror · read-only / commits / f2ce81cc
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

fastcgi: Support multiple path splitters (close #1564)

Matthew Holt committed Mar 22, 2020 at 07:48 UTC f2ce81cc8b5adcd453566d292ac0b0b47fc64e99
2 files changed +15 -9
modules/caddyhttp/reverseproxy/fastcgi/caddyfile.go
+3 -3
@@ -51,10 +51,10 @@ func (t *Transport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
51 t.Root = d.Val()
52
53 case "split":
54 - if !d.NextArg() {
54 + t.SplitPath = d.RemainingArgs()
55 + if len(t.SplitPath) == 0 {
56 return d.ArgErr()
57 }
57 - t.SplitPath = d.Val()
58
59 case "env":
60 args := d.RemainingArgs()
@@ -173,7 +173,7 @@ func parsePHPFastCGI(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error
173 }
174
175 // set up the transport for FastCGI, and specifically PHP
176 - fcgiTransport := Transport{SplitPath: ".php"}
176 + fcgiTransport := Transport{SplitPath: []string{".php"}}
177
178 // create the reverse proxy handler which uses our FastCGI transport
179 rpHandler := &reverseproxy.Handler{
modules/caddyhttp/reverseproxy/fastcgi/fastcgi.go
+12 -6
@@ -47,10 +47,11 @@ type Transport struct {
47 // with the value of SplitPath. The first piece will be assumed as the
48 // actual resource (CGI script) name, and the second piece will be set to
49 // PATH_INFO for the CGI script to use.
50 + //
51 // Future enhancements should be careful to avoid CVE-2019-11043,
52 // which can be mitigated with use of a try_files-like behavior
52 - // that 404's if the fastcgi path info is not found.
53 - SplitPath string `json:"split_path,omitempty"`
53 + // that 404s if the fastcgi path info is not found.
54 + SplitPath []string `json:"split_path,omitempty"`
55
56 // Extra environment variables.
57 EnvVars map[string]string `json:"env,omitempty"`
@@ -168,7 +169,7 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
169
170 // Split path in preparation for env variables.
171 // Previous canSplit checks ensure this can never be -1.
171 - // TODO: I haven't brought over canSplit; make sure this doesn't break
172 + // TODO: I haven't brought over canSplit from v1; make sure this doesn't break
173 splitPos := t.splitPos(fpath)
174
175 // Request has the extension; path was split successfully
@@ -284,14 +285,19 @@ func (t Transport) buildEnv(r *http.Request) (map[string]string, error) {
285 // splitPos returns the index where path should
286 // be split based on t.SplitPath.
287 func (t Transport) splitPos(path string) int {
287 - // TODO:
288 + // TODO: from v1...
289 // if httpserver.CaseSensitivePath {
290 // return strings.Index(path, r.SplitPath)
291 // }
291 - return strings.Index(strings.ToLower(path), strings.ToLower(t.SplitPath))
292 + lowerPath := strings.ToLower(path)
293 + for _, split := range t.SplitPath {
294 + if idx := strings.Index(lowerPath, strings.ToLower(split)); idx > -1 {
295 + return idx
296 + }
297 + }
298 + return -1
299 }
300
294 -// TODO:
301 // Map of supported protocols to Apache ssl_mod format
302 // Note that these are slightly different from SupportedProtocols in caddytls/config.go
303 var tlsProtocolStrings = map[uint16]string{