Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func ConfigureBackendURL(r *http.Request, rl *rule.Rule) error {
forwardURL.Host = backendHost
forwardURL.Path = path.Join(backendPath, proxyPath)

// path.Join removes trailing slash
if forwardURL.Path != "/" && strings.HasSuffix(proxyPath, "/") {
forwardURL.Path += "/"
}

if rl.Upstream.StripPath != "" {
forwardURL.Path = strings.Replace(forwardURL.Path, "/"+strings.Trim(rl.Upstream.StripPath, "/"), "", 1)
}
Expand Down
7 changes: 7 additions & 0 deletions proxy/request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"net/http"
"path"
"strings"

"github.com/ory/herodot"
"github.com/ory/x/errorsx"
Expand Down Expand Up @@ -333,7 +334,13 @@ func (d *requestHandler) InitializeAuthnSession(r *http.Request, rl *rule.Rule)
}

if r.URL.Path != "" {
hasSlash := strings.HasSuffix(r.URL.Path, "/")
r.URL.Path = path.Clean(r.URL.Path)

// path.Clean removes trailing slash
if r.URL.Path != "/" && hasSlash {
r.URL.Path += "/"
}
}

values, err := rl.ExtractRegexGroups(d.c.AccessRuleMatchingStrategy(), r.URL)
Expand Down
6 changes: 6 additions & 0 deletions rule/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,13 @@ func (r *Rule) IsMatching(strategy configuration.MatchingStrategy, method string
}

if u.Path != "" {
hasSlash := strings.HasSuffix(u.Path, "/")
u.Path = path.Clean(u.Path)

// path.Clean removes trailing slash
if u.Path != "/" && hasSlash {
u.Path += "/"
}
}
matchAgainst := fmt.Sprintf("%s://%s%s", u.Scheme, u.Host, u.Path)
return r.matchingEngine.IsMatching(r.Match.GetURL(), matchAgainst)
Expand Down
Loading