@@ -41,7 +41,7 @@ function may_disable_saml() {
4141 return false ;
4242}
4343
44- function get_domain () {
44+ function get_without () {
4545 $ protocols = array ( 'http:// ' , 'https:// ' , 'http://www. ' , 'https://www. ' , 'www. ' );
4646 return str_replace ($ protocols , '' , site_url ());
4747}
@@ -50,22 +50,24 @@ function redirect_to_relaystate_if_trusted($url) {
5050 $ trusted = false ;
5151 $ trustedDomainsOpt = get_option ('onelogin_saml_trusted_url_domains ' , "" );
5252 $ trustedDomains = explode (", " , trim ($ trustedDomainsOpt ));
53- $ trustedDomains [] = get_domain ( );
53+ $ trusted = ! empty ( $ trustedDomains ) && checkIsExternalURLAllowed ( $ url , $ trustedDomains );
5454
55- $ trusted = checkURLAllowed ($ url , $ trustedDomains );
55+ if (!$ trusted ) {
56+ $ url = wp_validate_redirect ($ url , home_url ());
57+ }
5658
5759 if ($ trusted ) {
5860 wp_redirect ($ url );
5961 } else {
60- wp_redirect (home_url () );
62+ wp_redirect ($ url );
6163 }
6264}
6365
64- function checkURLAllowed ($ url , $ trustedSites = [])
66+ function checkIsExternalURLAllowed ($ url , $ trustedSites = [])
6567{
66- // Allow Relative URL
68+ // If seems Relative URL, convert into absolute and validate it
6769 if ($ url [0 ] === '/ ' ) {
68- return true ;
70+ $ url = WP_Http:: make_absolute_url ( $ url , home_url ()) ;
6971 }
7072
7173 if (!wp_http_validate_url ($ url )) {
@@ -94,10 +96,14 @@ function checkURLAllowed($url, $trustedSites = [])
9496 ) {
9597 if (in_array ($ hostname .': ' .$ components ['port ' ], $ trustedSites , true )) {
9698 return true ;
99+ } else {
100+
97101 }
98102 }
99103
100- return in_array ($ hostname , $ trustedSites , true );
104+ if (in_array ($ hostname , $ trustedSites , true )) {
105+ return true ;
106+ }
101107}
102108
103109function saml_custom_login_footer () {
0 commit comments