Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/login-with-phone-number/inc/admin-functions.php
+++ b/login-with-phone-number/inc/admin-functions.php
@@ -39,13 +39,13 @@
plugins_url('/styles/lwp-admin.css',
dirname(__FILE__)),
array(),
- '1.8.61','all');
+ '1.8.71','all');
wp_enqueue_style('idehweb-lwp-admin-select2-style',
plugins_url('/styles/select2.min.css',
dirname(__FILE__)),
array(),
- '1.8.61','all');
+ '1.8.71','all');
}
function admin_footer()
@@ -812,6 +812,18 @@
<p class="description">' . esc_html__('enter length of activation code', 'login-with-phone-number') . '</p>';
}
+
+ function setting_idehweb_otp_max_attempts()
+ {
+ $options = get_option('idehweb_lwp_settings');
+
+ if (!isset($options['idehweb_otp_max_attempts'])) $options['idehweb_otp_max_attempts'] = '5';
+
+ echo '<input type="number" min="1" max="20" name="idehweb_lwp_settings[idehweb_otp_max_attempts]" class="regular-text" value="' . esc_attr($options['idehweb_otp_max_attempts']) . '" />
+ <p class="description">' . esc_html__('max wrong OTP attempts before the code is invalidated and user must request a new one', 'login-with-phone-number') . '</p>';
+
+ }
+
function setting_idehweb_login_message()
{
$options = get_option('idehweb_lwp_settings');
@@ -1169,6 +1181,7 @@
add_settings_field('idehweb_password_login', __('Enable password login', 'login-with-phone-number'), array(&$this, 'setting_idehweb_password_login'), 'idehweb-lwp', 'idehweb-lwp', ['label_for' => '', 'class' => 'ilwplabel lwp-tab-form-settings']);
add_settings_field('idehweb_redirect_url', __('Enter redirect url', 'login-with-phone-number'), array(&$this, 'setting_idehweb_url_redirect'), 'idehweb-lwp', 'idehweb-lwp', ['label_for' => '', 'class' => 'ilwplabel lwp-tab-general-settings']);
add_settings_field('idehweb_length_of_activation_code', __('Enter length of activation code', 'login-with-phone-number'), array(&$this, 'setting_idehweb_length_of_activation_code'), 'idehweb-lwp', 'idehweb-lwp', ['label_for' => '', 'class' => 'ilwplabel lwp-tab-general-settings']);
+ add_settings_field('idehweb_otp_max_attempts', __('Max OTP attempts', 'login-with-phone-number'), array(&$this, 'setting_idehweb_otp_max_attempts'), 'idehweb-lwp', 'idehweb-lwp', ['label_for' => '', 'class' => 'ilwplabel lwp-tab-general-settings']);
add_settings_field('idehweb_login_message', __('Enter login message', 'login-with-phone-number'), array(&$this, 'setting_idehweb_login_message'), 'idehweb-lwp', 'idehweb-lwp', ['label_for' => '', 'class' => 'ilwplabel lwp-tab-general-settings']);
add_settings_field('idehweb_use_phone_number_for_username', __('use phone number for username', 'login-with-phone-number'), array(&$this, 'idehweb_use_phone_number_for_username'), 'idehweb-lwp', 'idehweb-lwp', ['label_for' => '', 'class' => 'ilwplabel lwp-tab-general-settings']);
add_settings_field('idehweb_default_username', __('Default username', 'login-with-phone-number'), array(&$this, 'setting_default_username'), 'idehweb-lwp', 'idehweb-lwp', ['label_for' => '', 'class' => 'ilwplabel related_to_upnfu lwp-tab-general-settings']);
--- a/login-with-phone-number/inc/ajax-handlers.php
+++ b/login-with-phone-number/inc/ajax-handlers.php
@@ -783,13 +783,28 @@
}
} else {
+ $lwp_options = get_option('idehweb_lwp_settings');
+ $max_attempts = isset($lwp_options['idehweb_otp_max_attempts']) ? (int) $lwp_options['idehweb_otp_max_attempts'] : 5;
+ if ($max_attempts < 1) $max_attempts = 5;
+ $attempts = (int) get_user_meta($username_exists, 'lwp_otp_attempts', true);
+
+ if ($attempts >= $max_attempts) {
+ wp_send_json([
+ 'success' => false,
+ 'locked' => true,
+ 'message' => __('Too many wrong attempts. Please request a new code and try again.', 'login-with-phone-number')
+ ]);
+ }
+
if (empty($activation_code)) {
wp_send_json([
'success' => false,
'message' => __('activation_code is empty!', 'login-with-phone-number')
]);
}
+
if ($activation_code == $secod) {
+ update_user_meta($username_exists, 'lwp_otp_attempts', 0);
// First get the user details
$user = get_user_by('ID', $username_exists);
@@ -840,6 +855,11 @@
} else {
+ $attempts++;
+ update_user_meta($username_exists, 'lwp_otp_attempts', $attempts);
+ if ($attempts >= $max_attempts) {
+ update_user_meta($username_exists, 'activation_code', '');
+ }
wp_send_json([
'success' => false,
'phone_number' => $phone_number,
@@ -895,7 +915,23 @@
}
$secod = sanitize_text_field(wp_unslash($_GET['secod']));
+
+ $lwp_options = get_option('idehweb_lwp_settings');
+ $max_attempts = isset($lwp_options['idehweb_otp_max_attempts']) ? (int) $lwp_options['idehweb_otp_max_attempts'] : 5;
+ if ($max_attempts < 1) $max_attempts = 5;
+ $attempts = (int) get_user_meta($current_user->ID, 'lwp_otp_attempts', true);
+
+ if ($attempts >= $max_attempts) {
+ update_user_meta($current_user->ID, 'activation_code', '');
+ update_user_meta($current_user->ID, 'lwp_otp_attempts', 0);
+ wp_send_json([
+ 'success' => false,
+ 'message' => __('Too many attempts. Please request a new code.', 'login-with-phone-number')
+ ]);
+ }
+
if ($activation_code == $secod) {
+ update_user_meta($current_user->ID, 'lwp_otp_attempts', 0);
//remove this email from other user
$this->remove_email_from_all_users($temporary_email);
@@ -915,6 +951,11 @@
} else {
+ $attempts++;
+ update_user_meta($current_user->ID, 'lwp_otp_attempts', $attempts);
+ if ($attempts >= $max_attempts) {
+ update_user_meta($current_user->ID, 'activation_code', '');
+ }
wp_send_json([
'success' => false,
'email' => $email,
--- a/login-with-phone-number/inc/frontend-functions.php
+++ b/login-with-phone-number/inc/frontend-functions.php
@@ -137,21 +137,21 @@
);
wp_enqueue_style('idehweb-lwp', plugins_url('/styles/login-with-phonenumber.css', dirname(__FILE__)),
- array(), '1.8.61', 'all');
+ array(), '1.8.71', 'all');
- wp_enqueue_script('idehweb-lwp-validate-script', plugins_url('/scripts/jquery.validate.js', dirname(__FILE__)), array('jquery'), '1.8.61', true);
+ wp_enqueue_script('idehweb-lwp-validate-script', plugins_url('/scripts/jquery.validate.js', dirname(__FILE__)), array('jquery'), '1.8.71', true);
- wp_enqueue_script('idehweb-lwp', plugins_url('/scripts/login-with-phonenumber.js', dirname(__FILE__)), array('jquery'), '1.8.61', true);
+ wp_enqueue_script('idehweb-lwp', plugins_url('/scripts/login-with-phonenumber.js', dirname(__FILE__)), array('jquery'), '1.8.71', true);
if ($options['idehweb_use_custom_gateway'] == '1' && in_array('firebase', $options['idehweb_default_gateways'])) {
- wp_enqueue_script('lwp-google-recaptcha', 'https://www.google.com/recaptcha/api.js', array(), '1.8.61', true);
- wp_enqueue_script('lwp-firebase', 'https://www.gstatic.com/firebasejs/7.21.0/firebase-app.js', array(), '1.8.61', true);
- wp_enqueue_script('lwp-firebase-auth', 'https://www.gstatic.com/firebasejs/7.21.0/firebase-auth.js', array(), '1.8.61', true);
+ wp_enqueue_script('lwp-google-recaptcha', 'https://www.google.com/recaptcha/api.js', array(), '1.8.71', true);
+ wp_enqueue_script('lwp-firebase', 'https://www.gstatic.com/firebasejs/7.21.0/firebase-app.js', array(), '1.8.71', true);
+ wp_enqueue_script('lwp-firebase-auth', 'https://www.gstatic.com/firebasejs/7.21.0/firebase-auth.js', array(), '1.8.71', true);
- wp_enqueue_script('lwp-firebase-sender', plugins_url('/scripts/firebase-sender.js', dirname(__FILE__)), array('jquery'), '1.8.61', true);
+ wp_enqueue_script('lwp-firebase-sender', plugins_url('/scripts/firebase-sender.js', dirname(__FILE__)), array('jquery'), '1.8.71', true);
$localize['firebase_api'] = $options['idehweb_firebase_api'];
}
@@ -186,13 +186,13 @@
wp_enqueue_style('lwp-intltelinput-style', plugins_url('/styles/intlTelInput.min.css', dirname(__FILE__)),
array(),
- '1.8.61',
+ '1.8.71',
'all');
wp_add_inline_style('lwp-intltelinput-style', '.iti { width: 100%; }#lwp_username{font-size: 20px;}');
//
wp_enqueue_script('lwp-intltelinput-script',
plugins_url('/scripts/intlTelInput.min.js', dirname(__FILE__)),
- array(), '1.8.61', true);
+ array(), '1.8.71', true);
// Inline initialization
wp_add_inline_script(
'lwp-intltelinput-script',
--- a/login-with-phone-number/inc/helper-functions.php
+++ b/login-with-phone-number/inc/helper-functions.php
@@ -504,6 +504,7 @@
update_user_meta($user_id, 'activation_code', $six_digit_random_number);
update_user_meta($user_id, 'activation_code_timestamp', time());
+ update_user_meta($user_id, 'lwp_otp_attempts', 0);
if ($send_email) {
$wp_mail = wp_mail($contact, __('Activation code', 'login-with-phone-number'), __('your activation code: ', 'login-with-phone-number') . $six_digit_random_number);
return $wp_mail;
--- a/login-with-phone-number/login-with-phonenumber.php
+++ b/login-with-phone-number/login-with-phonenumber.php
@@ -3,7 +3,7 @@
Plugin Name: OTP Login With Phone Number, OTP Verification
Plugin URI: https://idehweb.com/product/login-with-phone-number-in-wordpress/
Description: Passwordless OTP login for WordPress. Login or register with phone number via SMS or Firebase. Compatible with WooCommerce. GDPR-compliant.
-Version: 1.8.70
+Version: 1.8.71
Author: Hamid Alinia - idehweb
Author URI: https://idehweb.com/
Text Domain: login-with-phone-number