Skip to content

Commit c1d6c92

Browse files
committed
Merge branch 'master' of ssh://github.com/mholt/caddy
2 parents 118f666 + e9641c5 commit c1d6c92

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

caddyhttp/proxy/upstream.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,17 @@ func (u *staticUpstream) Select(r *http.Request) *UpstreamHost {
665665

666666
func (u *staticUpstream) AllowedPath(requestPath string) bool {
667667
for _, ignoredSubPath := range u.IgnoredSubPaths {
668-
if httpserver.Path(path.Clean(requestPath)).Matches(path.Join(u.From(), ignoredSubPath)) {
668+
p := path.Clean(requestPath)
669+
e := path.Join(u.From(), ignoredSubPath)
670+
// Re-add a trailing slashes if the original
671+
// paths had one and the cleaned paths don't
672+
if strings.HasSuffix(requestPath, "/") && !strings.HasSuffix(p, "/") {
673+
p = p + "/"
674+
}
675+
if strings.HasSuffix(ignoredSubPath, "/") && !strings.HasSuffix(e, "/") {
676+
e = e + "/"
677+
}
678+
if httpserver.Path(p).Matches(e) {
669679
return false
670680
}
671681
}

caddyhttp/proxy/upstream_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestRegisterPolicy(t *testing.T) {
136136
func TestAllowedPaths(t *testing.T) {
137137
upstream := &staticUpstream{
138138
from: "/proxy",
139-
IgnoredSubPaths: []string{"/download", "/static"},
139+
IgnoredSubPaths: []string{"/download", "/static", "/trailingslash/"},
140140
}
141141
tests := []struct {
142142
url string
@@ -153,6 +153,8 @@ func TestAllowedPaths(t *testing.T) {
153153
{"/proxy//static", false},
154154
{"/proxy//static//download", false},
155155
{"/proxy//download", false},
156+
{"/proxy/trailingslash", true},
157+
{"/proxy/trailingslash/", false},
156158
}
157159

158160
for i, test := range tests {

0 commit comments

Comments
 (0)