Skip to content

Commit

Permalink
Ensure BuildRedirectURL enforces non-empty path
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronhurt committed Mar 16, 2018
1 parent 71d2972 commit 9b23390
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion proxy/http_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestRedirect(t *testing.T) {
{req: "/", wantCode: 301, wantLoc: "http://a.com/"},
{req: "/aaa/bbb", wantCode: 301, wantLoc: "http://a.com/aaa/bbb"},
{req: "/foo", wantCode: 301, wantLoc: "http://a.com/abc"},
{req: "/bar", wantCode: 302, wantLoc: "http://b.com"},
{req: "/bar", wantCode: 302, wantLoc: "http://b.com/"},
{req: "/bar/aaa", wantCode: 302, wantLoc: "http://b.com/aaa"},
}

Expand Down
20 changes: 15 additions & 5 deletions route/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,10 @@ func TestNormalizeHost(t *testing.T) {
// for more information on the issue and purpose of this test
func TestTableLookupIssue448(t *testing.T) {
s := `
route add mock-0 foo.com:80/ https://foo.com/ opts "redirect=301"
route add mock-2 aaa.com:80/ http://bbb.com/ opts "redirect=301"
route add mock-3 ccc.com:443/bar https://ccc.com/baz opts "redirect=301"
route add mock-4 / http://foo.com/
route add mock foo.com:80/ https://foo.com/ opts "redirect=301"
route add mock aaa.com:80/ http://bbb.com/ opts "redirect=301"
route add mock ccc.com:443/bar https://ccc.com/baz opts "redirect=301"
route add mock / http://foo.com/
`

tbl, err := NewTable(s)
Expand All @@ -517,7 +517,17 @@ func TestTableLookupIssue448(t *testing.T) {
Header: http.Header{"X-Forwarded-Proto": {"http"}},
},
dst: "https://foo.com/",
// upstream http request to same https host and path should follow redirect
// upstream http request to same host and path should follow redirect
},
{
req: &http.Request{
Host: "foo.com",
URL: mustParse("/"),
Header: http.Header{"X-Forwarded-Proto": {"https"}},
TLS: &tls.ConnectionState{},
},
dst: "http://foo.com/",
// upstream https request to same host and path should NOT follow redirect"
},
{
req: &http.Request{
Expand Down
3 changes: 3 additions & 0 deletions route/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ func (t *Target) BuildRedirectURL(requestURL *url.URL) {
t.RedirectURL.RawQuery = requestURL.RawQuery
}
}
if t.RedirectURL.Path == "" {
t.RedirectURL.Path = "/"
}
}

0 comments on commit 9b23390

Please sign in to comment.