Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 00:30 UTC
caddyhttp: Trim dot/space only on Windows (fix #5613)
Follow-up to #2917. Path matcher needs to trim dots and spaces but only on Windows.
Matthew Holt committed
Jul 8, 2023 at 13:42 UTC
66114cb155f2a975ecdc9f3d2d89a9df1142791a
2 files changed
+9
-8
modules/caddyhttp/matchers.go
+4
-1
@@ -25,6 +25,7 @@ import (
25
"path"
26
"reflect"
27
"regexp"
28
+ "runtime"
29
"sort"
30
"strconv"
31
"strings"
@@ -395,7 +396,9 @@ func (m MatchPath) Match(r *http.Request) bool {
396
// security risk (cry) if PHP files end up being served
397
// as static files, exposing the source code, instead of
398
// being matched by *.php to be treated as PHP scripts.
398
- reqPath = strings.TrimRight(reqPath, ". ")
399
+ if runtime.GOOS == "windows" { // issue #5613
400
+ reqPath = strings.TrimRight(reqPath, ". ")
401
+ }
402
403
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
404
modules/caddyhttp/matchers_test.go
+5
-7
@@ -21,6 +21,7 @@ import (
21
"net/http/httptest"
22
"net/url"
23
"os"
24
+ "runtime"
25
"testing"
26
27
"github.com/caddyserver/caddy/v2"
@@ -253,11 +254,6 @@ func TestPathMatcher(t *testing.T) {
254
input: "/FOOOO",
255
expect: true,
256
},
256
- {
257
- match: MatchPath{"*.php"},
258
- input: "/foo/index.php. .",
259
- expect: true,
260
- },
257
{
258
match: MatchPath{"/foo/bar.txt"},
259
input: "/foo/BAR.txt",
@@ -435,8 +431,10 @@ func TestPathMatcher(t *testing.T) {
431
432
func TestPathMatcherWindows(t *testing.T) {
433
// only Windows has this bug where it will ignore
438
- // trailing dots and spaces in a filename, but we
439
- // test for it on all platforms to be more consistent
434
+ // trailing dots and spaces in a filename
435
+ if runtime.GOOS != "windows" {
436
+ return
437
+ }
438
439
req := &http.Request{URL: &url.URL{Path: "/index.php . . .."}}
440
repl := caddy.NewReplacer()