Skip to content

Commit

Permalink
Only parse query_string if it exists (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod authored Jun 21, 2024
1 parent deacab2 commit 6b2ba54
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lib/sso-provider/discourse-sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,20 @@ public function sync_sso_record( $user_login, $user ) {
$bypass_sync = apply_filters( 'wpdc_bypass_sync_sso', false, $user->ID, $user );

if ( ! $bypass_sync ) {
// Make sure the login hasn't been initiated by clicking on a SSO login link.
$query_string = wp_parse_url( wp_get_referer(), PHP_URL_QUERY );
$query_params = array();
parse_str( $query_string, $query_params );
$sso_referer = ! empty( $query_params['redirect_to'] ) && preg_match( '/^\/\?sso/', $query_params['redirect_to'] );
if ( ! $sso_referer ) {
$params = $this->get_sso_params( $user );

$this->sync_sso( $params, $user->ID );
}
// Make sure the login hasn't been initiated by clicking on a SSO login link.
$query_string = wp_parse_url( wp_get_referer(), PHP_URL_QUERY );
$query_params = array();
$sso_referer = null;

if ( ! empty( $query_string ) ) {
parse_str( $query_string, $query_params );
$sso_referer = ! empty( $query_params['redirect_to'] ) && preg_match( '/^\/\?sso/', $query_params['redirect_to'] );
}

if ( ! $sso_referer ) {
$params = $this->get_sso_params( $user );
$this->sync_sso( $params, $user->ID );
}
}

return null;
Expand Down Expand Up @@ -257,11 +261,11 @@ protected function handle_error( $type, $args = array() ) {
return new \WP_Error( $type, isset( $args['message'] ) ? $args['message'] : 'SSO error' );
}

/**
* Handle redirects
*
* @param string $url Url to redirect to.
*/
/**
* Handle redirects
*
* @param string $url Url to redirect to.
*/
public function redirect_to( $url ) {
wp_safe_redirect( esc_url_raw( $url ) );
exit;
Expand Down

0 comments on commit 6b2ba54

Please sign in to comment.