Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/wp-2fa/includes/classes/Admin/Methods/class-backup-codes.php
+++ b/wp-2fa/includes/classes/Admin/Methods/class-backup-codes.php
@@ -312,7 +312,7 @@
$backup_codes = get_user_meta( $user->ID, self::BACKUP_CODES_META_KEY, true );
if ( is_array( $backup_codes ) && ! empty( $backup_codes ) ) {
foreach ( $backup_codes as $code_hashed ) {
- if ( wp_check_password( $code, $code_hashed, $user->ID ) ) {
+ if ( wp_check_password( $code, $code_hashed, $user->ID ) ) {
self::delete_code( $user, $code_hashed );
self::clear_login_attempts( $user );
@@ -342,7 +342,7 @@
$backup_codes = array_values( array_flip( $backup_codes ) );
// Update the backup code master list.
- update_user_meta( $user->ID, self::BACKUP_CODES_META_KEY, $backup_codes );
+ update_user_meta( $user->ID, self::BACKUP_CODES_META_KEY, $backup_codes );
}
/**
@@ -571,7 +571,7 @@
foreach ( $posted_codes as $key => $check_code ) {
$check_code = trim( explode( ':', $check_code )[1] );
- if ( ! wp_check_password( $check_code, $stored_codes[ $key ], $user->ID ) ) {
+ if ( ! wp_check_password( $check_code, $stored_codes[ $key ], $user->ID ) ) {
wp_die();
}
--- a/wp-2fa/includes/classes/Admin/SettingsPages/class-settings-page-email.php
+++ b/wp-2fa/includes/classes/Admin/SettingsPages/class-settings-page-email.php
@@ -17,6 +17,7 @@
use WP2FAAdminHelpersWP_Helper;
use WP2FAAdminControllersSettings;
use WP2FAUtilsSettings_Utils;
+use WP2FAAdminSettings_Page;
/**
* Email settings tab
@@ -112,7 +113,7 @@
<input type="radio" name="email_from_setting" id="use-defaults" value="use-defaults"
<?php checked( WP2FA::get_wp2fa_email_templates( 'email_from_setting' ), 'use-defaults' ); ?>
>
- <span><?php esc_html_e( 'Use the email address from the WordPress general settings.', 'wp-2fa' ); ?></span>
+ <span><?php esc_html_e( 'Use the email address ', 'wp-2fa' ) ?> <?php echo Settings_Page::get_default_email_address(); ?></span>
</label>
<br/>
<label for="use-custom-email">
--- a/wp-2fa/includes/classes/Admin/Views/class-wizard-steps.php
+++ b/wp-2fa/includes/classes/Admin/Views/class-wizard-steps.php
@@ -307,16 +307,24 @@
self::congratulations_step_plugin_wizard();
return;
}
+
+ $redirect = ( '' !== self::determine_redirect_url() ) ? self::determine_redirect_url() : '';
?>
- <div class="step-setting-wrapper active">
- <div class="mb-20">
- <?php echo wp_kses_post( WP2FA::get_wp2fa_white_label_setting( 'no_further_action', true ) ); ?>
- </div>
- <div class="wp2fa-setup-actions">
- <button class="modal__btn wp-2fa-button-secondary button" data-close-2fa-modal aria-label="Close this dialog window"><?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?></button>
- </div>
- </div>
+ <div class="step-setting-wrapper active">
+ <div class="mb-20">
+ <?php echo wp_kses_post( WP2FA::get_wp2fa_white_label_setting( 'no_further_action', true ) ); ?>
+ </div>
+ <div class="wp2fa-setup-actions">
+ <?php if ( '' !== trim( $redirect ) ) { ?>
+ <a href="<?php echo esc_url( $redirect ); ?>" class="button button-secondary wp-2fa-button-secondary close-first-time-wizard">
+ <?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?>
+ </a>
+ <?php } else { ?>
+ <button class="modal__btn wp-2fa-button-secondary button" data-close-2fa-modal aria-label="Close this dialog window"><?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?></button>
+ <?php } ?>
+ </div>
+ </div>
<?php
}
@@ -331,30 +339,30 @@
$redirect = ( '' !== self::determine_redirect_url() ) ? self::determine_redirect_url() : get_edit_profile_url( User_Helper::get_user_object()->ID );
$slide_title = ( User_Helper::is_excluded( User_Helper::get_user_object()->ID ) ) ? esc_html__( 'Congratulations.', 'wp-2fa' ) : esc_html__( 'Congratulations, you're almost there...', 'wp-2fa' );
?>
- <h3><?php echo esc_html( $slide_title ); ?></h3>
- <p><?php esc_html_e( 'Great job, the plugin and 2FA policies are now configured. You can always change the plugin settings and 2FA policies at a later stage from the WP 2FA entry in the WordPress menu.', 'wp-2fa' ); ?></p>
+ <h3><?php echo esc_html( $slide_title ); ?></h3>
+ <p><?php esc_html_e( 'Great job, the plugin and 2FA policies are now configured. You can always change the plugin settings and 2FA policies at a later stage from the WP 2FA entry in the WordPress menu.', 'wp-2fa' ); ?></p>
- <?php
- if ( User_Helper::is_excluded( User_Helper::get_user_object()->ID ) ) {
- ?>
- <div class="wp2fa-setup-actions">
- <a href="<?php echo esc_url( $redirect ); ?>" class="button button-secondary wp-2fa-button-secondary close-first-time-wizard">
- <?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?>
- </a>
- </div>
- <?php
- } else {
- ?>
- <p><?php esc_html_e( 'Now you need to configure 2FA for your own user account. You can do this now (recommended) or later.', 'wp-2fa' ); ?></p>
- <div class="wp2fa-setup-actions">
- <a href="<?php echo esc_url( Settings::get_setup_page_link() ); ?>" class="button button-primary wp-2fa-button-secondary">
- <?php esc_html_e( 'Configure 2FA now', 'wp-2fa' ); ?>
- </a>
- <a href="<?php echo esc_url( Settings::get_settings_page_link() ); ?>" class="button button-secondary wp-2fa-button-secondary close-first-time-wizard">
- <?php esc_html_e( 'Close wizard & configure 2FA later', 'wp-2fa' ); ?>
- </a>
- </div>
- <?php } ?>
+ <?php
+ if ( User_Helper::is_excluded( User_Helper::get_user_object()->ID ) ) {
+ ?>
+ <div class="wp2fa-setup-actions">
+ <a href="<?php echo esc_url( $redirect ); ?>" class="button button-secondary wp-2fa-button-secondary close-first-time-wizard">
+ <?php esc_html_e( 'Close wizard', 'wp-2fa' ); ?>
+ </a>
+ </div>
+ <?php
+ } else {
+ ?>
+ <p><?php esc_html_e( 'Now you need to configure 2FA for your own user account. You can do this now (recommended) or later.', 'wp-2fa' ); ?></p>
+ <div class="wp2fa-setup-actions">
+ <a href="<?php echo esc_url( Settings::get_setup_page_link() ); ?>" class="button button-primary wp-2fa-button-secondary">
+ <?php esc_html_e( 'Configure 2FA now', 'wp-2fa' ); ?>
+ </a>
+ <a href="<?php echo esc_url( Settings::get_settings_page_link() ); ?>" class="button button-secondary wp-2fa-button-secondary close-first-time-wizard">
+ <?php esc_html_e( 'Close wizard & configure 2FA later', 'wp-2fa' ); ?>
+ </a>
+ </div>
+ <?php } ?>
<?php
}
--- a/wp-2fa/includes/classes/Admin/class-settings-page.php
+++ b/wp-2fa/includes/classes/Admin/class-settings-page.php
@@ -410,7 +410,9 @@
if ( 'use-custom-email' === WP2FA::get_wp2fa_email_templates( 'email_from_setting' ) ) {
$headers .= 'From: ' . WP2FA::get_wp2fa_email_templates( 'custom_from_display_name' ) . ' <' . WP2FA::get_wp2fa_email_templates( 'custom_from_email_address' ) . '>' . "rn";
} else {
- $headers .= 'From: ' . get_bloginfo( 'name' ) . ' <' . get_bloginfo( 'admin_email' ) . '>' . "rn";
+
+ $headers .= 'From: wp2fa <' . self::get_default_email_address() . '>' . "rn";
+ // $headers .= 'From: ' . get_bloginfo( 'name' ) . ' <' . get_bloginfo( 'admin_email' ) . '>' . "rn";
}
// Fire our email.
@@ -418,6 +420,28 @@
}
/**
+ * Builds and returns the default email address used for the "from" email address when email is send
+ *
+ * @return string
+ *
+ * @since 2.6.4
+ */
+ public static function get_default_email_address(): string {
+ $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST );
+ $from_email = 'wp2fa@';
+
+ if ( null !== $sitename ) {
+ if ( str_starts_with( $sitename, 'www.' ) ) {
+ $sitename = substr( $sitename, 4 );
+ }
+
+ $from_email .= $sitename;
+ }
+
+ return $from_email;
+ }
+
+ /**
* Turns user roles data in any form and shape to an array of strings.
*
* @param mixed $value User role names (slugs) as raw value.
@@ -462,17 +486,12 @@
public static function check_email() {
$is_dismissed = (bool) Settings_Utils::get_option( 'dismiss_notice_mail_domain', false );
if ( ! $is_dismissed ) {
- $admin_email = get_option( 'admin_email' );
-
+ $admin_email = null;
if ( 'use-custom-email' === WP2FA::get_wp2fa_email_templates( 'email_from_setting' ) ) {
$admin_email = WP2FA::get_wp2fa_email_templates( 'custom_from_email_address' );
}
- $site_url = get_site_url();
-
- $email_domain = WP_Helper::extract_domain( $admin_email );
- $site_domain = WP_Helper::extract_domain( $site_url );
- if ( $email_domain !== $site_domain ) {
+ if ( '' === trim( (string) $admin_email ) ) {
$email_settings_url = esc_url(
add_query_arg(
array(
@@ -483,17 +502,17 @@
)
);
?>
- <div class="notice notice-error">
- <p><?php esc_html_e( 'By default, the plugin uses the Administrator's email address as configured in WordPress settings as the "from address" when sending emails with the 2FA code for users to log in. This email address is currently configured as: ', 'wp-2fa' ); ?><b><?php echo $admin_email; ?>.</b></p>
- <p>
- <a href="<?php echo esc_url( $email_settings_url ); ?>"><?php esc_html_e( 'Configure email address now', 'wp-2fa' ); ?></a>
- <a href="#" class="2fa-email-notice" style="margin-left:10px;">
- <?php esc_html_e( 'Use the Administrator's email address.', 'wp-2fa' ); ?>
- </a>
- </p>
-
- <?php wp_nonce_field( 'wp2fa_dismiss_notice_mail_domain', 'wp2fa_dismiss_notice_mail_domain', false ); ?>
- </div>
+ <div class="notice notice-error">
+ <p style="font-size: 2em;"><?php esc_html_e( 'By default, the plugin uses ', 'wp-2fa' ); ?> <b><?php echo self::get_default_email_address(); ?></b> <?php esc_html_e( 'as the "from address" when sending emails with the 2FA code for users to log in. Do you want to keep using this or change it?', 'wp-2fa' ); ?></p>
+ <p>
+ <a style="font-size: 1.7em;" href="<?php echo esc_url( $email_settings_url ); ?>"><?php esc_html_e( 'Change it', 'wp-2fa' ); ?></a>
+ <a style="margin-left:20px;font-size: 1.7em;" href="#" class="2fa-email-notice">
+ <?php esc_html_e( 'Keep using it', 'wp-2fa' ); ?>
+ </a>
+ </p>
+
+ <?php wp_nonce_field( 'wp2fa_dismiss_notice_mail_domain', 'wp2fa_dismiss_notice_mail_domain', false ); ?>
+ </div>
<?php
} else {
Settings_Utils::update_option( 'dismiss_notice_mail_domain', true );
--- a/wp-2fa/includes/classes/Authenticator/class-authentication.php
+++ b/wp-2fa/includes/classes/Authenticator/class-authentication.php
@@ -224,7 +224,7 @@
foreach ( $ticks as $offset ) {
$log_time = $time + $offset;
$calculdated = (string) self::calc_totp( $key, $log_time );
- if ( $calculdated === $authcode ) {
+ if ( hash_equals( $calculdated, $authcode ) ) {
return true;
}
}
@@ -359,7 +359,7 @@
* @param string|array $chars Valid auth code characters.
* @return string
*/
- public static function get_code( $length = 8, $chars = '1234567890' ) {
+ public static function get_code( $length = 6, $chars = '1234567890' ) {
$code = '';
if ( is_array( $chars ) ) {
$chars = implode( '', $chars );
--- a/wp-2fa/includes/classes/Authenticator/class-open-ssl.php
+++ b/wp-2fa/includes/classes/Authenticator/class-open-ssl.php
@@ -53,8 +53,6 @@
* @since 2.0.0
*/
public static function encrypt( string $text ): string {
- Debugging::log( 'Encrypting a text: ' . $text );
- Debugging::log( 'Will use the following salt: ' . wp_salt() );
if ( self::is_ssl_available() ) {
$iv = self::secure_random( self::BLOCK_BYTE_SIZE );
$key = openssl_digest( base64_decode( wp_salt() ), self::DIGEST_ALGORITHM, true ); //phpcs:ignore
@@ -68,7 +66,6 @@
$text = base64_encode( $iv . $text ); //phpcs:ignore
}
- Debugging::log( 'Encrypted text: ' . $text );
return $text;
}
--- a/wp-2fa/vendor/autoload.php
+++ b/wp-2fa/vendor/autoload.php
@@ -22,4 +22,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
-return ComposerAutoloaderInit3077::getLoader();
+return ComposerAutoloaderInit12205::getLoader();
--- a/wp-2fa/vendor/composer/autoload_real.php
+++ b/wp-2fa/vendor/composer/autoload_real.php
@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
-class ComposerAutoloaderInit3077
+class ComposerAutoloaderInit12205
{
private static $loader;
@@ -24,16 +24,16 @@
require __DIR__ . '/platform_check.php';
- spl_autoload_register(array('ComposerAutoloaderInit3077', 'loadClassLoader'), true, true);
+ spl_autoload_register(array('ComposerAutoloaderInit12205', 'loadClassLoader'), true, true);
self::$loader = $loader = new ComposerAutoloadClassLoader(dirname(__DIR__));
- spl_autoload_unregister(array('ComposerAutoloaderInit3077', 'loadClassLoader'));
+ spl_autoload_unregister(array('ComposerAutoloaderInit12205', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
- call_user_func(ComposerAutoloadComposerStaticInit3077::getInitializer($loader));
+ call_user_func(ComposerAutoloadComposerStaticInit12205::getInitializer($loader));
$loader->register(true);
- $filesToLoad = ComposerAutoloadComposerStaticInit3077::$files;
+ $filesToLoad = ComposerAutoloadComposerStaticInit12205::$files;
$requireFile = Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
--- a/wp-2fa/vendor/composer/autoload_static.php
+++ b/wp-2fa/vendor/composer/autoload_static.php
@@ -4,7 +4,7 @@
namespace ComposerAutoload;
-class ComposerStaticInit3077
+class ComposerStaticInit12205
{
public static $files = array (
'a9ed0d27b5a698798a89181429f162c5' => __DIR__ . '/..' . '/khanamiryan/qrcode-detector-decoder/lib/Common/customFunctions.php',
@@ -168,9 +168,9 @@
public static function getInitializer(ClassLoader $loader)
{
return Closure::bind(function () use ($loader) {
- $loader->prefixLengthsPsr4 = ComposerStaticInit3077::$prefixLengthsPsr4;
- $loader->prefixDirsPsr4 = ComposerStaticInit3077::$prefixDirsPsr4;
- $loader->classMap = ComposerStaticInit3077::$classMap;
+ $loader->prefixLengthsPsr4 = ComposerStaticInit12205::$prefixLengthsPsr4;
+ $loader->prefixDirsPsr4 = ComposerStaticInit12205::$prefixDirsPsr4;
+ $loader->classMap = ComposerStaticInit12205::$classMap;
}, null, ClassLoader::class);
}
--- a/wp-2fa/wp-2fa.php
+++ b/wp-2fa/wp-2fa.php
@@ -7,7 +7,7 @@
*
* @wordpress-plugin
* Plugin Name: WP 2FA - Two-factor authentication for WordPress
- * Version: 2.6.3
+ * Version: 2.6.4
* Plugin URI: https://melapress.com/
* Description: Easily add an additional layer of security to your WordPress login pages. Enable Two-Factor Authentication for you and all your website users with this easy to use plugin.
* Author: Melapress
@@ -54,7 +54,7 @@
// Useful global constants.
if ( ! defined( 'WP_2FA_VERSION' ) ) {
- define( 'WP_2FA_VERSION', '2.6.3' );
+ define( 'WP_2FA_VERSION', '2.6.4' );
define( 'WP_2FA_BASE', plugin_basename( __FILE__ ) );
define( 'WP_2FA_URL', plugin_dir_url( __FILE__ ) );
define( 'WP_2FA_PATH', WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . dirname( WP_2FA_BASE ) . DIRECTORY_SEPARATOR );