- Timestamp:
- 05/29/2020 03:14:48 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/common/includes/wporg-sso/class-wporg-sso.php
r7695 r9941 2 2 if ( ! class_exists( 'WPOrg_SSO' ) ) { 3 3 /** 4 * Single Sign-On (SSO) handling for WordPress/bbPress instances under *.wordpress.org.4 * Single Sign-On (SSO) handling for WordPress/bbPress instances on wordpress.org. 5 5 * 6 6 * @author stephdau … … 10 10 11 11 const SUPPORT_EMAIL = 'forum-password-resets@wordpress.org'; 12 13 const VALID_HOSTS = [ 14 'wordpress.org', 15 'bbpress.org', 16 'buddypress.org', 17 'wordcamp.org' 18 ]; 12 19 13 20 public $sso_host_url; … … 76 83 } 77 84 85 if ( ! preg_match( '!wordpress\.org$!', $this->host ) ) { 86 $login_url = add_query_arg( 'from', $this->host, $login_url ); 87 } 88 78 89 return $login_url; 79 90 … … 117 128 // We didn't get a redirect_to, but we got a referrer, use that if a valid target. 118 129 $redirect_to_referrer = $_SERVER['HTTP_REFERER']; 119 if ( $this->_is_valid_targeted_domain( $redirect_to_referrer ) ) {130 if ( $this->_is_valid_targeted_domain( $redirect_to_referrer ) && self::SSO_HOST != parse_url( $redirect_to_referrer, PHP_URL_HOST ) ) { 120 131 $redirect_to = $redirect_to_referrer; 121 132 } 122 } else {133 } elseif ( self::SSO_HOST !== $this->host ) { 123 134 // Otherwise, attempt to guess the parent dir of where they came from and validate that. 124 135 $redirect_to_source_parent = preg_replace( '/\/[^\/]+\.php\??.*$/', '/', "https://{$this->host}{$_SERVER['REQUEST_URI']}" ); … … 132 143 133 144 /** 134 * Tests if the passed host/domain, or URL, is part of the WordPress.org domain.145 * Tests if the passed host/domain, or URL, is part of the WordPress.org network. 135 146 * 136 * @param unknown $ stringA domain, hostname, or URL147 * @param unknown $host A domain, hostname, or URL 137 148 * @return boolean True is ok, false if not 138 149 */ 139 protected function _is_valid_targeted_domain( $ string) {140 if ( empty( $ string ) || ! is_string( $string) ) {141 $string = '';150 protected function _is_valid_targeted_domain( $host ) { 151 if ( empty( $host ) || ! is_string( $host ) || ! strstr( $host, '.' ) ) { 152 return false; 142 153 } 143 154 144 if ( strstr( $string , '/' ) ) { 145 $url = parse_url( $string ); 146 $host = ( ! empty( $url['host'] ) ) ? $url['host'] : ''; 147 } else { 148 $host = $string; 155 if ( strstr( $host, '/' ) ) { 156 $host = parse_url( $host, PHP_URL_HOST ); 149 157 } 150 158 151 if ( ! empty( $host ) && strstr( $host , '.') ) {152 return ( preg_match( '/^(.+\.)?wordpress\.org$/', $host ) ) ? true : false;159 if ( in_array( $host, self::VALID_HOSTS, true ) ) { 160 return true; 153 161 } 154 162 155 return false; 163 // If not a top-level domain, shrink it down and try again. 164 $top_level_host = implode( '.', array_slice( explode( '.', $host ), -2 ) ); 165 166 return in_array( $top_level_host, self::VALID_HOSTS, true ); 156 167 } 157 168
Note: See TracChangeset
for help on using the changeset viewer.