Skip to content

Commit 6b9d8b7

Browse files
committed
v2.2.3
1 parent 5daa30e commit 6b9d8b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3694
-507
lines changed

assets/admin/js/secupress-modules.js

+3
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,9 @@ function secupressDisplayAjaxSuccess( $button, text, ajaxID ) {
16241624
// Regenerate keys button ====================
16251625
(function($, d, w, undefined) {
16261626
$( '#secupress-regen-keys' ).on( 'click', function(e) {
1627+
if ( $(this).attr('href') == '#' ) {
1628+
return false;
1629+
}
16271630
var _this = this;
16281631
e.preventDefault();
16291632
swal2( $.extend( {}, SecuPress.swal2Defaults, SecuPress.swal2ConfirmDefaults, {

defines.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22
defined( 'ABSPATH' ) or die( 'Something went wrong.' );
33

4-
define( 'SECUPRESS_VERSION' , '2.2' );
4+
define( 'SECUPRESS_VERSION' , '2.2.3' );
55
define( 'SECUPRESS_MAJOR_VERSION' , '2.2' );
66
define( 'SECUPRESS_PATH' , realpath( dirname( SECUPRESS_FILE ) ) . DIRECTORY_SEPARATOR );
77
define( 'SECUPRESS_INC_PATH' , SECUPRESS_PATH . 'free' . DIRECTORY_SEPARATOR );
8-
! defined( 'SECUPRESS_API' ) ?
9-
define( 'SECUPRESS_API' , 'ab4f63f9ac65152575886860dde480a1' ) : false;

free/admin/ajax-post-callbacks.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ function secupress_regen_hash_key_admin_post_cb() {
879879
$options['hash_key'] = secupress_generate_key( 64 );
880880
secupress_update_options( $options );
881881

882-
secupress_auto_login( 'Admin_User' );
882+
secupress_auto_login( 'Salt_Keys' );
883883
}
884884

885885
add_action( 'admin_post_secupress_accept_notification', 'secupress_accept_notification_admin_post_cb' );

free/admin/functions/admin.php

-20
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,3 @@ function secupress_print_pro_advantages() {
288288
</div>
289289
<?php
290290
}
291-
292-
/**
293-
* Redirect the user on a specific URL to be autologged-in
294-
*
295-
* @since 2.0
296-
* @author Julio Potier
297-
*
298-
* @param (string) $module The SecuPress module to be redirected
299-
**/
300-
function secupress_auto_login( $module ) {
301-
$current_user = wp_get_current_user();
302-
if ( ! $current_user ) {
303-
return;
304-
}
305-
$token = md5( time() . $module );
306-
secupress_set_site_transient( 'secupress_auto_login_' . $token, array( $current_user->user_login, $module ), MINUTE_IN_SECONDS );
307-
308-
wp_safe_redirect( esc_url_raw( add_query_arg( 'secupress_auto_login_token', $token ) ) );
309-
die();
310-
}

free/admin/settings.php

-25
Original file line numberDiff line numberDiff line change
@@ -980,31 +980,6 @@ function secupress_scanners_template() {
980980
}
981981

982982

983-
/**
984-
* Get a scan or fix status, formatted with icon and human readable text.
985-
*
986-
* @since 1.0
987-
*
988-
* @param (string) $status The status code.
989-
*
990-
* @return (string) Formatted status.
991-
*/
992-
function secupress_status( $status ) {
993-
switch ( $status ) :
994-
case 'bad':
995-
return __( 'Bad', 'secupress' );
996-
case 'good':
997-
return __( 'Good', 'secupress' );
998-
case 'warning':
999-
return __( 'Warning', 'secupress' );
1000-
case 'cantfix':
1001-
return __( 'Error', 'secupress' );
1002-
default:
1003-
return __( 'New', 'secupress' );
1004-
endswitch;
1005-
}
1006-
1007-
1008983
/**
1009984
* Print a box with title.
1010985
*

free/admin/upgrader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ function secupress_new_upgrade( $secupress_version, $actual_version ) {
207207
if ( version_compare( $actual_version, '2.0', '<' ) ) {
208208
// Cannot use secupress_is_submodule_active() here because these are not modules yet (< 2.0...)
209209
if ( defined( 'SECUPRESS_SALT_KEYS_ACTIVE' ) ) {
210-
secupress_set_site_transient( 'secupress-add-salt-muplugin', array( 'ID' => $current_user->ID, 'username' => $current_user->user_login ) );
210+
secupress_set_site_transient( 'secupress-add-salt-muplugin', array( 'ID' => $current_user->ID ) );
211211
}
212212
if ( defined( 'COOKIEHASH' ) && COOKIEHASH !== md5( get_site_option( 'siteurl' ) ) ) {
213213
secupress_set_site_transient( 'secupress-add-cookiehash-muplugin', array( 'ID' => $current_user->ID, 'username' => $current_user->user_login ) );

free/classes/scanners/class-secupress-scan-bad-usernames.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function init() {
4242
$this->more = __( 'Some usernames are known to be used for malicious usage, or created by bots.', 'secupress' );
4343
$this->more_fix = sprintf(
4444
__( 'Activate the option %1$s in the %2$s module.', 'secupress' ),
45-
'<em>' . __( 'Forbid usernames', 'secupress' ) . '</em>',
45+
'<em>' . __( 'Forbid Usernames', 'secupress' ) . '</em>',
4646
'<a href="' . esc_url( secupress_admin_url( 'modules', 'users-login' ) ) . '#row-blacklist-logins_activated">' . __( 'Users & Login', 'secupress' ) . '</a>'
4747
);
4848
}

free/classes/scanners/class-secupress-scan-db-prefix.php

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class SecuPress_Scan_DB_Prefix extends SecuPress_Scan implements SecuPress_Scan_
2929
*/
3030
protected static $_instance;
3131

32+
/**
33+
* Tells if a scanner is fixable by SecuPress. The value "pro" means it's fixable only with the version PRO.
34+
*
35+
* @var (bool|string)
36+
*/
37+
protected $fixable = 'pro';
3238

3339
/** Init and messages. ====================================================================== */
3440

free/classes/scanners/class-secupress-scan-salt-keys.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ public function scan() {
129129
204 => [],
130130
205 => [],
131131
];
132-
133-
preg_match_all( '/' . implode( '|', $keys ) . '/', $wp_config_content, $matches );
132+
$pattern = "'" . implode( "'|'", $keys ) . "'|";
133+
$pattern .= '"' . implode( '"|"', $keys ) . '"';
134+
preg_match_all( '/' . $pattern . '/', $wp_config_content, $matches );
134135

135136
if ( ! empty( $matches[0] ) ) {
136137
// Hardcoded.

free/classes/settings/class-secupress-settings.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -632,8 +632,7 @@ protected function field( $args ) {
632632

633633
case 'wpeditor' :
634634
case 'textarea' :
635-
636-
$value = esc_textarea( html_entity_decode( implode( "\n" , (array) $value ), ENT_QUOTES ) );
635+
$value = esc_textarea( html_entity_decode( implode( "\n", (array) explode( ',', $value ) ), ENT_QUOTES ) );
637636
$attributes .= empty( $args['attributes']['cols'] ) ? ' cols="50"' : '';
638637
$attributes .= empty( $args['attributes']['rows'] ) ? ' rows="5"' : '';
639638

free/common.php

+84-49
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ function secupress_check_ban_ips_maybe_send_unban_email( $ip ) {
158158
}
159159

160160
// Send message.
161-
$url = esc_url_raw( wp_nonce_url( home_url( '?action=secupress_self-unban-ip' ), 'secupress_self-unban-ip-' . $ip ) );
162-
$message = '<p>' . sprintf(
161+
$url = str_replace( '&amp;', '&', esc_url_raw( wp_nonce_url( home_url( '?action=secupress_self-unban-ip' ), 'secupress_self-unban-ip-' . $ip ) ) );
162+
$message = sprintf(
163163
/** Translators: %s is a "unlock yourself" link. */
164164
__( 'You got yourself locked out?
165165
@@ -168,8 +168,8 @@ function secupress_check_ban_ips_maybe_send_unban_email( $ip ) {
168168
Regards,
169169
All at ###SITENAME###
170170
###SITEURL###', 'secupress' ),
171-
'<a href="' . $url . '">' . __( 'unlock yourself', 'secupress' ) . '</a> (' . $url . ')'
172-
) . '</p>';
171+
__( 'unlock yourself', 'secupress' ) . ' ( ' . $url . ' )'
172+
);
173173

174174
$subject = sprintf( __( 'Unban yourself from %s', 'secupress' ), home_url() );
175175
/**
@@ -511,7 +511,6 @@ function secupress_add_cookiehash_muplugin() {
511511
secupress_auto_login( 'WP_Config' );
512512
}
513513

514-
515514
add_action( 'plugins_loaded', 'secupress_add_salt_muplugin', 50 );
516515
/**
517516
* Will create a mu plugin to early set the salt keys.
@@ -535,7 +534,7 @@ function secupress_add_salt_muplugin() {
535534
return;
536535
}
537536

538-
if ( ! is_array( $data ) || ! isset( $data['ID'], $data['username'] ) ) {
537+
if ( ! is_array( $data ) || ! isset( $data['ID'] ) ) {
539538
secupress_delete_site_transient( 'secupress-add-salt-muplugin' );
540539
return;
541540
}
@@ -546,15 +545,8 @@ function secupress_add_salt_muplugin() {
546545

547546
secupress_delete_site_transient( 'secupress-add-salt-muplugin' );
548547

549-
// Make sure we find the `wp-config.php` file.
550-
$wpconfig_filepath = secupress_is_wpconfig_writable();
551-
552-
if ( ! $wpconfig_filepath ) {
553-
return;
554-
}
555-
556548
// Create the MU plugin.
557-
if ( ! defined( 'SECUPRESS_SALT_KEYS_MODULE_ACTIVE' ) ) {
549+
if ( ! defined( 'SECUPRESS_SALT_KEYS_MODULE_EXISTS' ) ) {
558550
$alicia_keys = file_get_contents( SECUPRESS_INC_PATH . 'data/salt-keys.phps' );
559551
$args = array(
560552
'{{PLUGIN_NAME}}' => SECUPRESS_PLUGIN_NAME,
@@ -571,48 +563,45 @@ function secupress_add_salt_muplugin() {
571563
}
572564
}
573565

574-
/**
575-
* Remove old secret keys from the `wp-config.php` file and add a comment.
576-
* We have to make sure the comment is added, only once, only if one or more keys are found, even if some secret keys are missing, and do not create useless empty lines.
577-
*/
578-
$wp_filesystem = secupress_get_filesystem();
579-
$wpconfig_content = $wp_filesystem->get_contents( $wpconfig_filepath );
580-
$keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
581-
$comment_added = false;
582-
$comment = '/** If you want to add secret keys back in wp-config.php, get new ones at https://api.wordpress.org/secret-key/1.1/salt, then delete this file. */';
583-
$placeholder = '/** SecuPress salt placeholder. */';
584-
585-
foreach ( $keys as $i => $constant ) {
586-
$pattern = '@define\s*\(\s*([\'"])' . $constant . '\1.*@';
587-
588-
if ( preg_match( $pattern, $wpconfig_content, $matches ) ) {
589-
$replace = $comment_added ? $placeholder : $comment;
590-
$wpconfig_content = str_replace( $matches[0], $replace, $wpconfig_content );
591-
$comment_added = true;
592-
}
593-
}
594-
595-
if ( $comment_added ) {
596-
$wpconfig_content = str_replace( $placeholder . "\n", '', $wpconfig_content );
597-
598-
$wp_filesystem->put_contents( $wpconfig_filepath, $wpconfig_content, FS_CHMOD_FILE );
599-
}
600-
566+
$keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
601567
// Remove old secret keys from the database.
602568
foreach ( $keys as $constant ) {
603569
delete_site_option( $constant );
604570
}
605571

606-
// Destroy the user session.
607-
wp_clear_auth_cookie();
608-
if ( function_exists( 'wp_destroy_current_session' ) ) { // WP 4.0 min.
609-
wp_destroy_current_session();
610-
}
572+
// Make sure we find the `wp-config.php` file.
573+
$wpconfig_filepath = secupress_is_wpconfig_writable();
574+
575+
576+
if ( $wpconfig_filepath ) {
577+
/**
578+
* Remove old secret keys from the `wp-config.php` file and add a comment.
579+
* We have to make sure the comment is added, only once, only if one or more keys are found, even if some secret keys are missing, and do not create useless empty lines.
580+
*/
581+
$wp_filesystem = secupress_get_filesystem();
582+
$wpconfig_content = $wp_filesystem->get_contents( $wpconfig_filepath );
583+
$comment_added = false;
584+
$comment = '/** If you want to add secret keys back in wp-config.php, get new ones at https://api.wordpress.org/secret-key/1.1/salt, then delete this file. */';
585+
$placeholder = '/** SecuPress salt placeholder. */';
586+
587+
foreach ( $keys as $i => $constant ) {
588+
$pattern = '@define\s*\(\s*([\'"])' . $constant . '\1.*@';
589+
590+
if ( preg_match( $pattern, $wpconfig_content, $matches ) ) {
591+
$replace = $comment_added ? $placeholder : $comment;
592+
$wpconfig_content = str_replace( $matches[0], $replace, $wpconfig_content );
593+
$comment_added = true;
594+
}
595+
}
611596

612-
$token = md5( time() );
613-
secupress_set_site_transient( 'secupress_auto_login_' . $token, array( $data['username'], 'Salt_Keys' ), MINUTE_IN_SECONDS );
597+
if ( $comment_added ) {
598+
$wpconfig_content = str_replace( $placeholder . "\n", '', $wpconfig_content );
614599

615-
wp_safe_redirect( esc_url_raw( add_query_arg( 'secupress_auto_login_token', $token, secupress_get_current_url( 'raw' ) ) ) );
600+
$wp_filesystem->put_contents( $wpconfig_filepath, $wpconfig_content, FS_CHMOD_FILE );
601+
}
602+
}
603+
604+
secupress_auto_login( 'Salt_Keys' );
616605
die();
617606
}
618607

@@ -743,3 +732,49 @@ function secupress_get_php_versions() {
743732
if ( is_admin() ) {
744733
add_action( 'user_register', array( 'SecuPress_Admin_Pointers', 'dismiss_pointers_for_new_users' ) );
745734
}
735+
736+
737+
/**
738+
* Redirect the user on a specific URL to be autologged-in
739+
*
740+
* @since 2.0
741+
* @author Julio Potier
742+
*
743+
* @param (string) $module The SecuPress module to be redirected
744+
* @param (WP_User|int) $user The user to be logged in
745+
**/
746+
function secupress_auto_login( $module, $user = null ) {
747+
if( is_int( $user ) ) {
748+
$user = new WP_User( $user );
749+
}
750+
if ( is_a( $user, 'WP_User' ) ) {
751+
$current_user = $user;
752+
} else {
753+
$current_user = wp_get_current_user();
754+
}
755+
if ( ! $current_user ) {
756+
return;
757+
}
758+
$token = md5( time() . $module );
759+
secupress_set_site_transient( 'secupress_auto_login_' . $token, array( $current_user->user_login, $module ), MINUTE_IN_SECONDS );
760+
761+
wp_safe_redirect( esc_url_raw( add_query_arg( 'secupress_auto_login_token', $token ) ) );
762+
die();
763+
}
764+
765+
add_filter( 'authenticate', 'secupress_authenticate_cookie', 0 );
766+
function secupress_authenticate_cookie( $user ) {
767+
$data = secupress_get_site_transient( 'secupress-auto-login' );
768+
769+
if ( ! $data ) {
770+
return $user;
771+
}
772+
773+
secupress_delete_site_transient( 'secupress-auto-login' );
774+
775+
if ( ! is_array( $data ) || ! isset( $data['ID'] ) ) {
776+
return $user;
777+
}
778+
779+
secupress_auto_login( 'Salt_Keys', $user );
780+
}

free/data/salt-keys.phps

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111

1212
defined( 'ABSPATH' ) or die( 'Something went wrong.' );
1313

14-
define( 'SECUPRESS_SALT_KEYS_MODULE_ACTIVE', true );
15-
16-
1714
if ( ! get_site_option( 'secupress_active_submodule_wp-config-constant-saltkeys' ) ) {
1815
return;
1916
}
2017

18+
define( 'SECUPRESS_SALT_KEYS_MODULE_ACTIVE', true );
19+
2120
global $blog_id;
2221

2322
$hash_1 = '{{HASH1}}';

free/functions/3rdparty.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function secupress_3rd_compat__unikname_connect( $activated ) {
3939
// https://plugins.svn.wordpress.org/two-factor-authentication/trunk/two-factor-login.php .
4040
add_filter( 'secupress.scan.SecuPress_Scan_Easy_Login.activated', 'secupress_3rd_compat__two_factor_authentication' );
4141
function secupress_3rd_compat__two_factor_authentication( $activated ) {
42-
if ( ! $activated && defined( 'SIMBA_TFA_PLUGIN_DIR' ) ) {
42+
if ( ! $activated && defined( 'SIMBA_TFA_TEXT_DOMAIN' ) ) {
4343
return 'Two Factor Authentication';
4444
}
4545
return $activated;

free/functions/common.php

+21-1
Original file line numberDiff line numberDiff line change
@@ -1648,4 +1648,24 @@ function secupress_time_limit( $seconds ) {
16481648
return true;
16491649
}
16501650
return false;
1651-
}
1651+
}
1652+
1653+
1654+
/**
1655+
* Get a scan or fix status, formatted with icon and human readable text.
1656+
*
1657+
* @since 1.0
1658+
*
1659+
* @param (string) $status The status code.
1660+
* @return (string) Formatted status.
1661+
*/
1662+
function secupress_status( $status ) {
1663+
$statuses = [];
1664+
$statuses['bad'] = __( 'Bad', 'secupress' );
1665+
$statuses['good'] = __( 'Good', 'secupress' );
1666+
$statuses['warning'] = __( 'Warning', 'secupress' );
1667+
$statuses['cantfix'] = __( 'Error', 'secupress' );
1668+
1669+
return isset( $statuses[ $status ] ) ? $statuses[ $status ] : __( 'New', 'secupress' );
1670+
}
1671+

0 commit comments

Comments
 (0)