-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oauth2: Allow whitelisting insecure redirect URLs (#1354)
This patch enables developers to whitelist insecure redirect URLs while using flag `--dangerous-force-http`. Closes #1021 Signed-off-by: aeneasr <[email protected]>
- Loading branch information
Showing
13 changed files
with
101 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package x | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/ory/fosite" | ||
) | ||
|
||
type redirectConfiguration interface { | ||
InsecureRedirects() []string | ||
} | ||
|
||
func IsRedirectURISecure(rc redirectConfiguration) func(redirectURI *url.URL) bool { | ||
return func(redirectURI *url.URL) bool { | ||
if fosite.IsRedirectURISecure(redirectURI) { | ||
return true | ||
} | ||
|
||
for _, allowed := range rc.InsecureRedirects() { | ||
if redirectURI.String() == allowed { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package x | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type mockrc struct{} | ||
|
||
func (m *mockrc) InsecureRedirects() []string { | ||
return []string{ | ||
"http://foo.com/bar", | ||
"http://baz.com/bar", | ||
} | ||
} | ||
|
||
func TestIsRedirectURISecure(t *testing.T) { | ||
for d, c := range []struct { | ||
u string | ||
err bool | ||
}{ | ||
{u: "http://google.com", err: true}, | ||
{u: "https://google.com", err: false}, | ||
{u: "http://localhost", err: false}, | ||
{u: "http://test.localhost", err: false}, | ||
{u: "wta://auth", err: false}, | ||
{u: "http://foo.com/bar", err: false}, | ||
{u: "http://baz.com/bar", err: false}, | ||
} { | ||
uu, err := url.Parse(c.u) | ||
require.NoError(t, err) | ||
assert.Equal(t, !c.err, IsRedirectURISecure(new(mockrc))(uu), "case %d", d) | ||
} | ||
} |