Skip to content
Merged
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
11 changes: 7 additions & 4 deletions lib/web/app/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,15 @@ func (t *transport) rewriteRedirect(resp *http.Response) error {
// We want the rewrite to happen using our own public address.
if host == t.c.identity.RouteToApp.PublicAddr {
// drop scheme and host, leaving only the relative path.
// since the path can be an empty string, canonicalize it as "/".
u.Host = ""
u.Scheme = ""

// since the path can be an empty string, canonicalize it to "/".
if u.Path == "" {
resp.Header.Set("Location", "/")
} else {
resp.Header.Set("Location", u.Path)
u.Path = "/"
}

resp.Header.Set("Location", u.String())
}
return nil
}
Expand Down
26 changes: 26 additions & 0 deletions lib/web/app/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ func Test_transport_rewriteRedirect(t *testing.T) {
respLocation: "https://dumper.leaf.teleport.example.com:3080/admin/blah",
wantLocation: "/admin/blah",
},
{
name: "remote app, redirect to app public addr, preserve query params",
transportConfig: makeTransportConfig(
rootCluster,
&tlsca.Identity{RouteToApp: tlsca.RouteToApp{
ClusterName: leafCluster,
PublicAddr: "dumper.leaf.teleport.example.com",
}},
makeAppServer(leafCluster, "dumper")),
respStatusCode: 302,
respLocation: "https://dumper.leaf.teleport.example.com:3080/admin/blah?foo=bar&baz=bar",
wantLocation: "/admin/blah?foo=bar&baz=bar",
},
{
name: "canonicalize empty location to /",
transportConfig: makeTransportConfig(
Expand All @@ -151,6 +164,19 @@ func Test_transport_rewriteRedirect(t *testing.T) {
respLocation: "https://dumper.leaf.teleport.example.com:3080",
wantLocation: "/",
},
{
name: "canonicalize empty location to /, preserve query params",
transportConfig: makeTransportConfig(
rootCluster,
&tlsca.Identity{RouteToApp: tlsca.RouteToApp{
ClusterName: leafCluster,
PublicAddr: "dumper.leaf.teleport.example.com",
}},
makeAppServer(leafCluster, "dumper")),
respStatusCode: 302,
respLocation: "https://dumper.leaf.teleport.example.com:3080?foo=bar&baz=bar",
wantLocation: "/?foo=bar&baz=bar",
},
}

for _, tt := range tests {
Expand Down