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
13 changes: 11 additions & 2 deletions server/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ func validateRedirectURI(client storage.Client, redirectURI string) bool {
return true
}
}

if client.Public && isRedirectURILocalhost(redirectURI) {
return true
}

// For non-public clients or when RedirectURIs is set, we allow only explicitly named RedirectURIs.
// Otherwise, we check below for special URIs used for desktop or mobile apps.
if !client.Public || len(client.RedirectURIs) > 0 {
Expand All @@ -630,8 +635,12 @@ func validateRedirectURI(client storage.Client, redirectURI string) bool {
return true
}

// verify that the host is of form "http://localhost:(port)(path)", "http://localhost(path)" or numeric form like
// "http://127.0.0.1:(port)(path)"
return isRedirectURILocalhost(redirectURI)
}

// verify that the host is of form "http://localhost:(port)(path)", "http://localhost(path)" or numeric form like
// "http://127.0.0.1:(port)(path)"
func isRedirectURILocalhost(redirectURI string) bool {
u, err := url.Parse(redirectURI)
if err != nil {
return false
Expand Down
13 changes: 10 additions & 3 deletions server/oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ func TestValidRedirectURI(t *testing.T) {
redirectURI: "http://foo.com/bar/baz",
wantValid: false,
},
{
client: storage.Client{
RedirectURIs: []string{"http://foo.com/bar"},
},
redirectURI: "http://localhost:991/bar",
wantValid: false,
},
// These special desktop + device + localhost URIs are allowed by default.
{
client: storage.Client{
Expand Down Expand Up @@ -510,23 +517,23 @@ func TestValidRedirectURI(t *testing.T) {
RedirectURIs: []string{"http://foo.com/bar"},
},
redirectURI: "http://localhost:8080/",
wantValid: false,
wantValid: true,
},
{
client: storage.Client{
Public: true,
RedirectURIs: []string{"http://foo.com/bar"},
},
redirectURI: "http://localhost:991/bar",
wantValid: false,
wantValid: true,
},
{
client: storage.Client{
Public: true,
RedirectURIs: []string{"http://foo.com/bar"},
},
redirectURI: "http://localhost",
wantValid: false,
wantValid: true,
},
// These special desktop + device + localhost URIs can still be specified explicitly.
{
Expand Down
Loading