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
5 changes: 4 additions & 1 deletion authorize_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ func isMatchingAsLoopback(requested *url.URL, registeredURI string) bool {
return false
}

// Check if address is either an IPv4 loopback or an IPv6 loopback.
// Check if address is either an IPv4 loopback, an IPv6 loopback, or localhost.
func isLoopbackAddress(hostname string) bool {
if hostname == "localhost" {
return true
}
return net.ParseIP(hostname).IsLoopback()
}

Expand Down
22 changes: 22 additions & 0 deletions authorize_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,28 @@ func TestDoesClientWhiteListRedirect(t *testing.T) {
isError: false,
expected: "https://google.com/?foo=bar%20foo+baz",
},
{
client: &fosite.DefaultClient{RedirectURIs: []string{"http://localhost/callback"}},
url: "http://localhost:9999/callback",
expected: "http://localhost:9999/callback",
isError: false,
},
{
client: &fosite.DefaultClient{RedirectURIs: []string{"http://localhost/callback"}},
url: "http://localhost/callback",
expected: "http://localhost/callback",
isError: false,
},
{
client: &fosite.DefaultClient{RedirectURIs: []string{"http://127.0.0.1/callback"}},
url: "http://localhost:9999/callback",
isError: true,
},
{
client: &fosite.DefaultClient{RedirectURIs: []string{"http://localhost/callback"}},
url: "http://127.0.0.1:9999/callback",
isError: true,
},
} {
redir, err := fosite.MatchRedirectURIWithClientRedirectURIs(c.url, c.client)
assert.Equal(t, c.isError, err != nil, "%d: %+v", k, c)
Expand Down