Skip to content

Commit

Permalink
fix: ignore query string when using X-Forwarded-Uri (ory#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
pingiun authored Nov 8, 2022
1 parent ae9a754 commit 6fa3978
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (h *DecisionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, next
r.URL.Scheme = x.OrDefaultString(r.Header.Get(xForwardedProto),
x.IfThenElseString(r.TLS != nil, "https", "http"))
r.URL.Host = x.OrDefaultString(r.Header.Get(xForwardedHost), r.Host)
r.URL.Path = x.OrDefaultString(r.Header.Get(xForwardedUri), r.URL.Path[len(DecisionPath):])
r.URL.Path = x.OrDefaultString(strings.SplitN(r.Header.Get(xForwardedUri), "?", 2)[0], r.URL.Path[len(DecisionPath):])

h.decisions(w, r)
} else {
Expand Down
11 changes: 11 additions & 0 deletions api/decision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,17 @@ func TestDecisionAPIHeaderUsage(t *testing.T) {
req.Header.Add("X-Forwarded-Uri", "/bar")
},
},
{
name: "argument from the headers doesn't get url encoded",
expectedUrl: &url.URL{Scheme: "https", Host: "test.dev", Path: "/bar"},
expectedMethod: "POST",
transform: func(req *http.Request) {
req.Header.Add("X-Forwarded-Method", "POST")
req.Header.Add("X-Forwarded-Proto", "https")
req.Header.Add("X-Forwarded-Host", "test.dev")
req.Header.Add("X-Forwarded-Uri", "/bar?this=is&a=test")
},
},
{
name: "only scheme is taken from the headers",
expectedUrl: &url.URL{Scheme: "https", Host: defaultUrl.Host, Path: defaultUrl.Path},
Expand Down

0 comments on commit 6fa3978

Please sign in to comment.