mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-20 22:52:58 -05:00
proxy: Re-add pre-existing trailing slashes in AllowedPath (#2151)
* proxy.AllowedPath: Re-append trailing slashes to excepted path comparisons * Substitute HasSuffix for manual check; check slash was actually removed
This commit is contained in:
parent
495656f72b
commit
e9641c5c7e
2 changed files with 14 additions and 2 deletions
|
@ -665,7 +665,17 @@ func (u *staticUpstream) Select(r *http.Request) *UpstreamHost {
|
||||||
|
|
||||||
func (u *staticUpstream) AllowedPath(requestPath string) bool {
|
func (u *staticUpstream) AllowedPath(requestPath string) bool {
|
||||||
for _, ignoredSubPath := range u.IgnoredSubPaths {
|
for _, ignoredSubPath := range u.IgnoredSubPaths {
|
||||||
if httpserver.Path(path.Clean(requestPath)).Matches(path.Join(u.From(), ignoredSubPath)) {
|
p := path.Clean(requestPath)
|
||||||
|
e := path.Join(u.From(), ignoredSubPath)
|
||||||
|
// Re-add a trailing slashes if the original
|
||||||
|
// paths had one and the cleaned paths don't
|
||||||
|
if strings.HasSuffix(requestPath, "/") && !strings.HasSuffix(p, "/") {
|
||||||
|
p = p + "/"
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(ignoredSubPath, "/") && !strings.HasSuffix(e, "/") {
|
||||||
|
e = e + "/"
|
||||||
|
}
|
||||||
|
if httpserver.Path(p).Matches(e) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ func TestRegisterPolicy(t *testing.T) {
|
||||||
func TestAllowedPaths(t *testing.T) {
|
func TestAllowedPaths(t *testing.T) {
|
||||||
upstream := &staticUpstream{
|
upstream := &staticUpstream{
|
||||||
from: "/proxy",
|
from: "/proxy",
|
||||||
IgnoredSubPaths: []string{"/download", "/static"},
|
IgnoredSubPaths: []string{"/download", "/static", "/trailingslash/"},
|
||||||
}
|
}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
url string
|
url string
|
||||||
|
@ -153,6 +153,8 @@ func TestAllowedPaths(t *testing.T) {
|
||||||
{"/proxy//static", false},
|
{"/proxy//static", false},
|
||||||
{"/proxy//static//download", false},
|
{"/proxy//static//download", false},
|
||||||
{"/proxy//download", false},
|
{"/proxy//download", false},
|
||||||
|
{"/proxy/trailingslash", true},
|
||||||
|
{"/proxy/trailingslash/", false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
|
|
Loading…
Add table
Reference in a new issue