Skip to content

Commit

Permalink
Fixing redirect_uri parsing and validation logic for double escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanthan committed Sep 25, 2020
1 parent 4ef10b4 commit 94ab1a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions authorize_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ import (
func GetRedirectURIFromRequestValues(values url.Values) (string, error) {
// rfc6749 3.1. Authorization Endpoint
// The endpoint URI MAY include an "application/x-www-form-urlencoded" formatted (per Appendix B) query component
redirectURI, err := url.Parse(values.Get("redirect_uri"))
rawRedirectURI := values.Get("redirect_uri")
redirectURI, err := url.Parse(rawRedirectURI)
if err != nil {
return "", errors.WithStack(ErrInvalidRequest.WithHint(`The "redirect_uri" parameter is malformed or missing.`).WithCause(err).WithDebug(err.Error()))
} else if rawRedirectURI != "" && (redirectURI.Scheme == "" || redirectURI.Host == "") {
return "", errors.WithStack(ErrInvalidRequest.WithHint(`The "redirect_uri" parameter with malformed http scheme or host.`))
}
rawQuery, err := url.QueryUnescape(redirectURI.RawQuery)

if err != nil {
return "", errors.WithStack(ErrInvalidRequest.WithHint(`The "redirect_uri" parameter is malformed`).WithDebug(err.Error()))
}
redirectURI.RawQuery = rawQuery
return redirectURI.String(), nil
}

Expand Down
2 changes: 1 addition & 1 deletion authorize_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestGetRedirectURI(t *testing.T) {
}{
{in: "", isError: false, expected: ""},
{in: "https://google.com/", isError: false, expected: "https://google.com/"},
{in: "https://google.com/?foo=bar%20foo+baz", isError: false, expected: "https://google.com/?foo=bar foo baz"},
{in: "https//google.com/foo=bar foo baz", isError: true, expected: "https://google.com/?foo=bar foo baz"},
} {
values := url.Values{}
values.Set("redirect_uri", c.in)
Expand Down

0 comments on commit 94ab1a2

Please sign in to comment.