File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,15 @@ func (app *OAuth2Application) TableName() string {
132132
133133// ContainsRedirectURI checks if redirectURI is allowed for app
134134func (app * OAuth2Application ) ContainsRedirectURI (redirectURI string ) bool {
135+ contains := func (s string ) bool {
136+ s = strings .TrimSuffix (strings .ToLower (s ), "/" )
137+ for _ , u := range app .RedirectURIs {
138+ if strings .TrimSuffix (strings .ToLower (u ), "/" ) == s {
139+ return true
140+ }
141+ }
142+ return false
143+ }
135144 if ! app .ConfidentialClient {
136145 uri , err := url .Parse (redirectURI )
137146 // ignore port for http loopback uris following https://datatracker.ietf.org/doc/html/rfc8252#section-7.3
@@ -140,13 +149,13 @@ func (app *OAuth2Application) ContainsRedirectURI(redirectURI string) bool {
140149 if ip != nil && ip .IsLoopback () {
141150 // strip port
142151 uri .Host = uri .Hostname ()
143- if util . SliceContainsString ( app . RedirectURIs , uri .String (), true ) {
152+ if contains ( uri .String ()) {
144153 return true
145154 }
146155 }
147156 }
148157 }
149- return util . SliceContainsString ( app . RedirectURIs , redirectURI , true )
158+ return contains ( redirectURI )
150159}
151160
152161// Base32 characters, but lowercased.
Original file line number Diff line number Diff line change @@ -63,6 +63,18 @@ func TestOAuth2Application_ContainsRedirectURI_WithPort(t *testing.T) {
6363 assert .False (t , app .ContainsRedirectURI (":" ))
6464}
6565
66+ func TestOAuth2Application_ContainsRedirect_Slash (t * testing.T ) {
67+ app := & auth_model.OAuth2Application {RedirectURIs : []string {"http://127.0.0.1" }}
68+ assert .True (t , app .ContainsRedirectURI ("http://127.0.0.1" ))
69+ assert .True (t , app .ContainsRedirectURI ("http://127.0.0.1/" ))
70+ assert .False (t , app .ContainsRedirectURI ("http://127.0.0.1/other" ))
71+
72+ app = & auth_model.OAuth2Application {RedirectURIs : []string {"http://127.0.0.1/" }}
73+ assert .True (t , app .ContainsRedirectURI ("http://127.0.0.1" ))
74+ assert .True (t , app .ContainsRedirectURI ("http://127.0.0.1/" ))
75+ assert .False (t , app .ContainsRedirectURI ("http://127.0.0.1/other" ))
76+ }
77+
6678func TestOAuth2Application_ValidateClientSecret (t * testing.T ) {
6779 assert .NoError (t , unittest .PrepareTestDatabase ())
6880 app := unittest .AssertExistsAndLoadBean (t , & auth_model.OAuth2Application {ID : 1 })
You can’t perform that action at this time.
0 commit comments