Changeset 12223 for sites/trunk/common/includes/wporg-sso/wp-plugin.php
- Timestamp:
- 11/08/2022 03:52:54 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/common/includes/wporg-sso/wp-plugin.php
r12222 r12223 258 258 add_filter( 'register_url', array( $this, 'register_url' ), 20 ); 259 259 260 // Maybe do a Remote SSO login 261 $this->_maybe_perform_remote_login(); 262 260 263 if ( preg_match( '!/wp-signup\.php$!', $_SERVER['REQUEST_URI'] ) ) { 261 264 // Note: wp-signup.php is not a physical file, and so it's matched on it's request uri. … … 273 276 // Allow logout on non-dotorg hosts. 274 277 if ( isset( $_GET['action'] ) && empty( $_POST ) && 'logout' == $_GET['action'] ) { 275 if ( ! preg_match( '!wordpress\.org$!', $ _SERVER['HTTP_HOST']) ) {278 if ( ! preg_match( '!wordpress\.org$!', $this->host ) ) { 276 279 return; 277 280 } 278 }279 280 // Remote SSO login?281 if ( isset( $_GET['action'] ) && 'remote-login' === $_GET['action'] && ! empty( $_GET['sso_token'] ) ) {282 $this->_maybe_perform_remote_login();283 281 } 284 282 … … 479 477 $redirect = wp_get_referer(); 480 478 if ( 481 str_starts_with( $redirect, wp_login_url() ) &&482 !str_contains( $redirect, '/wp-admin/' )479 str_starts_with( $redirect, wp_login_url() ) || 480 str_contains( $redirect, '/wp-admin/' ) 483 481 ) { 484 482 $redirect = home_url('/'); … … 524 522 */ 525 523 protected function _maybe_perform_remote_login() { 524 if ( empty( $_GET['sso_token'] ) ) { 525 return; 526 } 527 526 528 $remote_token = wp_unslash( $_GET['sso_token'] ); 527 529 if ( ! is_string( $remote_token ) || 3 !== substr_count( $remote_token, '|' ) ) { … … 552 554 if ( isset( $_GET['redirect_to'] ) ) { 553 555 $this->_safe_redirect( wp_unslash( $_GET['redirect_to'] ) ); 556 557 } elseif ( ! str_contains( $this->script, '/wp-login.php' ) ) { 558 // SSO login, no redirect_url, and on a not-a-login page. Remove sso arg and redirect to self. 559 $this->_safe_redirect( remove_query_arg( 'sso_token' ) ); 560 554 561 } else { 555 562 $this->_safe_redirect( home_url( '/' ) ); 563 556 564 } 565 exit; 566 } else { 567 // Invalid auth, remove the query var. 568 $this->_safe_redirect( remove_query_arg( 'sso_token' ) ); 557 569 exit; 558 570 } … … 589 601 $sso_token = $user->ID . '|' . $hash . '|' . $valid_until . '|' . $remember_me; 590 602 591 $redirect = add_query_arg( 592 array( 593 'action' => 'remote-login', 594 'sso_token' => urlencode( $sso_token ), 595 'redirect_to' => urlencode( $redirect ), 596 ), 597 'https://' . $redirect_host . '/wp-login.php' // Assume that wp-login exists and is accessible 598 ); 603 $redirect = add_query_arg( 'sso_token', urlencode( $sso_token ), $redirect ); 599 604 } 600 605
Note: See TracChangeset
for help on using the changeset viewer.