diff --git a/.changeset/wild-squids-lick.md b/.changeset/wild-squids-lick.md new file mode 100644 index 00000000..b9efe035 --- /dev/null +++ b/.changeset/wild-squids-lick.md @@ -0,0 +1,5 @@ +--- +"wptelegram-login": patch +--- + +Fixed the messed up query params passed by Telegram Mini Apps diff --git a/plugins/wptelegram-login/src/includes/AssetManager.php b/plugins/wptelegram-login/src/includes/AssetManager.php index 945b81b9..3f82c34e 100644 --- a/plugins/wptelegram-login/src/includes/AssetManager.php +++ b/plugins/wptelegram-login/src/includes/AssetManager.php @@ -240,11 +240,13 @@ public function get_inline_script_data( string $for ) { $confirm_login = (bool) $query_params['confirm_login']; $is_user_logged_in = is_user_logged_in(); $login_auth_url = add_query_arg( - [ - 'action' => 'wptelegram_login', - 'source' => 'WebAppData', - 'redirect_to' => $redirect_to, - ], + array_filter( + [ + 'action' => 'wptelegram_login', + 'source' => 'WebAppData', + 'redirect_to' => $redirect_to, + ] + ), site_url() ); @@ -437,11 +439,17 @@ public function login_enqueue_scripts() { */ private function get_webapp_login_params() { - // Using $_SERVER['QUERY_STRING'] to avoid a bug in Telegram Mini Apps which pass HTML encoded query string. + // Using $_SERVER['QUERY_STRING'] to avoid a bug in Telegram Mini Apps which pass HTML/URL encoded query string ¯\_(ツ)_/¯. + $query_string = ! empty( $_SERVER['QUERY_STRING'] ) - ? html_entity_decode( sanitize_text_field( wp_unslash( $_SERVER['QUERY_STRING'] ) ) ) + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- We are sanitizing the input below. + ? wp_unslash( $_SERVER['QUERY_STRING'] ) : ''; + $query_string = sanitize_text_field( + str_replace( [ '&%3B', '&' ], '&', $query_string ) + ); + return wp_parse_args( $query_string, [