PluginProbe
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… / 3.0.0
Vigilant – 100% Free Security Suite: Firewall, 2FA, Login, Headers, Scanner… v3.0.0
3.0.0 2.11.12 2.11.11 2.11.10 2.11.9 2.11.7 2.11.8 2.11.6 2.11.5 2.11.4 2.11.3 2.11.1 2.11.2 2.11.0 2.10.5 2.10.4 2.10.3 2.10.2 2.10.1 2.10.0 2.9.9 2.9.8 2.9.6 2.9.7 2.9.5 All 88 releases
← All changes | admin/class-admin-ajax.php +156 -110 2.10.13.0.0 View file →
@@ -22,95 +22,18 @@
22 22 * AJAX: Apply preset
23 23 */
24 24 // ajax_apply_preset() is defined in class-admin.php directly (not in this trait)
25 25
26 - /**
27 - * AJAX: Clear lockouts
26 + /*
27 + * ajax_clear_lockouts(), ajax_clear_logs(), ajax_run_scan() and
28 + * ajax_test_headers() live in class-admin.php. Until 2.11.8 this trait
29 + * carried older copies of the four, and PHP runs the method of the class,
30 + * so the copies never ran: a fix written into one of them would have looked
31 + * applied and changed nothing. Removed after the audit of the admin surface
32 + * for 2.11.8 found them.
28 33 */
29 - public function ajax_clear_lockouts() {
30 - check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
31 34
32 - if ( ! current_user_can( 'manage_options' ) ) {
33 - wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
34 - }
35 -
36 - $ip = isset( $_POST['ip'] ) ? sanitize_text_field( wp_unslash( $_POST['ip'] ) ) : '';
37 -
38 - if ( ! empty( $ip ) ) {
39 - // Clear specific IP
40 - $result = $this->database->clear_lockout( $ip );
41 - } else {
42 - // Clear all
43 - $result = $this->database->clear_all_lockouts();
44 - }
45 -
46 - if ( $result ) {
47 - wp_send_json_success( __( 'Lockouts cleared.', 'vigilante' ) );
48 - } else {
49 - wp_send_json_error( __( 'Failed to clear lockouts.', 'vigilante' ) );
50 - }
51 - }
52 -
53 35 /**
54 - * AJAX: Clear logs
55 - */
56 - public function ajax_clear_logs() {
57 - check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
58 -
59 - if ( ! current_user_can( 'manage_options' ) ) {
60 - wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
61 - }
62 -
63 - $result = $this->activity_log->clear_all_logs();
64 -
65 - if ( $result ) {
66 - wp_send_json_success( __( 'Logs cleared.', 'vigilante' ) );
67 - } else {
68 - wp_send_json_error( __( 'Failed to clear logs.', 'vigilante' ) );
69 - }
70 - }
71 -
72 - /**
73 - * AJAX: Run file integrity scan
74 - */
75 - public function ajax_run_scan() {
76 - check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
77 -
78 - if ( ! current_user_can( 'manage_options' ) ) {
79 - wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
80 - }
81 -
82 - try {
83 - if ( ! class_exists( 'Vigilante_File_Integrity' ) ) {
84 - require_once VIGILANTE_PLUGIN_DIR . 'includes/class-file-integrity.php';
85 - }
86 -
87 - if ( ! $this->settings ) {
88 - wp_send_json_error( 'Settings not initialized' );
89 - }
90 -
91 - $activity_log = isset( $this->activity_log ) ? $this->activity_log : null;
92 - $database = isset( $this->database ) ? $this->database : null;
93 -
94 - $file_integrity = new Vigilante_File_Integrity( $this->settings, $database, $activity_log );
95 - $results = $file_integrity->run_scan();
96 -
97 - // Save results for display
98 - update_option( 'vigilante_last_integrity_scan', time() );
99 - update_option( 'vigilante_last_integrity_results', $results );
100 -
101 - wp_send_json_success( array(
102 - 'message' => __( 'Scan completed.', 'vigilante' ),
103 - 'results' => $results,
104 - ) );
105 - } catch ( Exception $e ) {
106 - wp_send_json_error( 'Exception: ' . $e->getMessage() );
107 - } catch ( Error $e ) {
108 - wp_send_json_error( 'PHP Error: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() );
109 - }
110 - }
111 -
112 - /**
113 36 * AJAX: Approve a critical config file modification
114 37 *
115 38 * Updates the baseline hash for a single critical file (wp-config.php
116 39 * or .htaccess), accepting the current content as legitimate.
@@ -117,9 +40,23 @@
117 40 */
118 41 public function ajax_approve_critical_file() {
119 42 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
120 43
121 - if ( ! current_user_can( 'manage_options' ) ) {
44 + // Both approvable files, wp-config.php and the root .htaccess, belong
45 + // to the whole network, and since 2.11.3 so does the baseline that
46 + // records them. Approving a change to them is a network action, so on
47 + // a network it takes a network administrator: manage_options is held
48 + // by the administrator of every subsite.
49 + // Written with both calls in plain sight, following the recipe in
50 + // native-aeo-pack/trunk/includes/class-robots-txt.php:650, so the
51 + // surface inventory can read the capability. With the name in a
52 + // variable it can only say "check by hand", and an alert that says
53 + // that forever is an alert nobody reads.
54 + $allowed = is_multisite()
55 + ? current_user_can( 'manage_network_options' )
56 + : current_user_can( 'manage_options' );
57 +
58 + if ( ! $allowed ) {
122 59 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
123 60 }
124 61
125 62 // The request carries an opaque key instead of the file name: hosting
@@ -243,8 +180,17 @@
243 180 $log->is_ip_whitelisted = ( '' !== $ip_val && in_array( $ip_val, $ip_whitelist, true ) );
244 181 $log->is_ip_blacklisted = ( '' !== $ip_val && in_array( $ip_val, $ip_blacklist, true ) );
245 182 $log->is_ua_whitelisted = ( '' !== $ua_val && in_array( $ua_val, $ua_whitelist, true ) );
246 183 $log->is_ua_blacklisted = ( '' !== $ua_val && in_array( $ua_val, $ua_blacklist, true ) );
184 + $log->request_uri = Vigilante_Activity_Log::extract_request_uri( $log->extra_data ?? '' );
185 + // Same explanation as the first page load: without this, an entry
186 + // reached by filtering or paginating would open a popup with less
187 + // in it than the same entry opened from the first page.
188 + $log->self_guidance = Vigilante_Self_Integrity_Guidance::for_log_event(
189 + (string) ( $log->event_action ?? '' ),
190 + $log->extra_data ?? '',
191 + (string) ( $log->severity ?? 'info' )
192 + );
247 193 }
248 194
249 195 wp_send_json_success( array(
250 196 'logs' => $logs,
@@ -325,8 +271,18 @@
325 271 $removed_from_opposite = true;
326 272 }
327 273 }
328 274
275 + // On the main site of a network the whitelists also build the .htaccess
276 + // rules every site shares, so a user without network rights cannot put
277 + // an entry in them or take one out (2.11.6).
278 + $locked = Vigilante_Settings::get_locked_file_settings();
279 + $locked_firewall = ( isset( $locked['firewall'] ) && is_array( $locked['firewall'] ) ) ? $locked['firewall'] : array();
280 +
281 + if ( in_array( $option_key, $locked_firewall, true ) || ( $removed_from_opposite && in_array( $opposite_key, $locked_firewall, true ) ) ) {
282 + wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
283 + }
284 +
329 285 wp_cache_delete( Vigilante_Settings::OPTION_NAME, 'options' );
330 286 update_option( Vigilante_Settings::OPTION_NAME, $all_options );
331 287 $this->settings->clear_cache();
332 288
@@ -375,24 +331,8 @@
375 331 wp_send_json_success( $message );
376 332 }
377 333
378 334 /**
379 - * AJAX: Test security headers
380 - */
381 - public function ajax_test_headers() {
382 - check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
383 -
384 - if ( ! current_user_can( 'manage_options' ) ) {
385 - wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
386 - }
387 -
388 - $security_headers = new Vigilante_Security_Headers( $this->settings );
389 - $results = $security_headers->test_headers();
390 -
391 - wp_send_json_success( $results );
392 - }
393 -
394 - /**
395 335 * Sanitize activity log data
396 336 *
397 337 * @param array $data Data to sanitize.
398 338 * @return array
@@ -627,21 +567,45 @@
627 567 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
628 568 require_once VIGILANTE_INCLUDES_DIR . 'class-two-factor-totp.php';
629 569 }
630 570
631 - $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
632 - $count = 0;
571 + $totp = new Vigilante_Two_Factor_TOTP( $this->settings, $this->database, $this->activity_log );
572 + $count = 0;
573 + $skipped = 0;
633 574
634 575 foreach ( $user_ids as $uid ) {
635 - if ( $uid > 0 ) {
636 - $totp->reset_user_totp( $uid );
637 - $count++;
576 + if ( $uid < 1 ) {
577 + continue;
638 578 }
579 +
580 + // Same gate as the rest of the TOTP handlers: resetting somebody's
581 + // second factor is editing their account, so ask for edit_user
582 + // rather than for manage_options, which on a network is per site.
583 + if ( ! current_user_can( 'edit_user', $uid ) ) {
584 + $skipped++;
585 + continue;
586 + }
587 +
588 + $totp->reset_user_totp( $uid );
589 + $count++;
639 590 }
640 591
592 + $message = sprintf(
593 + /* translators: %d: Number of users reset */
594 + _n( 'TOTP reset for %d user.', 'TOTP reset for %d users.', $count, 'vigilante' ),
595 + $count
596 + );
597 +
598 + if ( $skipped > 0 ) {
599 + $message .= ' ' . sprintf(
600 + /* translators: %d: Number of users skipped because the current user cannot edit them */
601 + __( '%d skipped: you cannot edit those users.', 'vigilante' ),
602 + $skipped
603 + );
604 + }
605 +
641 606 wp_send_json_success( array(
642 - /* translators: %d: Number of users reset */
643 - 'message' => sprintf( _n( 'TOTP reset for %d user.', 'TOTP reset for %d users.', $count, 'vigilante' ), $count ),
607 + 'message' => $message,
644 608 'count' => $count,
645 609 ) );
646 610 }
647 611
@@ -661,10 +625,11 @@
661 625 if ( 0 === $user_id ) {
662 626 wp_send_json_error( __( 'Invalid user.', 'vigilante' ) );
663 627 }
664 628
665 - // Permission check: own profile or admin
666 - if ( get_current_user_id() !== $user_id && ! current_user_can( 'manage_options' ) ) {
629 + // Permission check: own profile, or a user this one may actually edit.
630 + // manage_options is held by every subsite administrator on a network.
631 + if ( get_current_user_id() !== $user_id && ! current_user_can( 'edit_user', $user_id ) ) {
667 632 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
668 633 }
669 634
670 635 if ( ! class_exists( 'Vigilante_Two_Factor_TOTP' ) ) {
@@ -879,8 +844,16 @@
879 844 $results['failed']
880 845 );
881 846 }
882 847
848 + if ( ! empty( $results['skipped'] ) ) {
849 + $message .= ' ' . sprintf(
850 + /* translators: %d: Number of users skipped because the current user cannot edit them */
851 + __( '%d skipped: you cannot edit those users.', 'vigilante' ),
852 + $results['skipped']
853 + );
854 + }
855 +
883 856 wp_send_json_success( array(
884 857 'message' => $message,
885 858 'results' => $results,
886 859 'resetting_self' => $resetting_self,
@@ -941,8 +914,16 @@
941 914 $results['failed']
942 915 );
943 916 }
944 917
918 + if ( ! empty( $results['skipped'] ) ) {
919 + $message .= ' ' . sprintf(
920 + /* translators: %d: Number of users skipped because the current user cannot edit them */
921 + __( '%d skipped: you cannot edit those users.', 'vigilante' ),
922 + $results['skipped']
923 + );
924 + }
925 +
945 926 wp_send_json_success( array(
946 927 'message' => $message,
947 928 'results' => $results,
948 929 'resetting_self' => $include_self,
@@ -1035,8 +1016,16 @@
1035 1016 $results['failed']
1036 1017 );
1037 1018 }
1038 1019
1020 + if ( ! empty( $results['skipped'] ) ) {
1021 + $message .= ' ' . sprintf(
1022 + /* translators: %d: Number of users skipped because the current user cannot edit them */
1023 + __( '%d skipped: you cannot edit those users.', 'vigilante' ),
1024 + $results['skipped']
1025 + );
1026 + }
1027 +
1039 1028 // Check if current user was included via role membership.
1040 1029 $resetting_self = false;
1041 1030 if ( $include_self ) {
1042 1031 $current_user = wp_get_current_user();
@@ -1065,8 +1054,29 @@
1065 1054 if ( ! $user_id ) {
1066 1055 wp_send_json_error( __( 'Invalid user ID.', 'vigilante' ) );
1067 1056 }
1068 1057
1058 + /*
1059 + * Permission over that account, which on a network only a network
1060 + * administrator has (wp-includes/capabilities.php:75). Same rule the other
1061 + * account tools got in 2.10.3, kept here in 2.11.8.
1062 + *
1063 + * The reason written here until 2.11.10 was that the pending flag is one
1064 + * user meta shared by the whole network, and that stopped being true in
1065 + * this very release: the flag is per site now and approving clears only
1066 + * this site's. The check stays all the same, and deliberately. Approving
1067 + * is what lets somebody into a network whose session cookie is valid on
1068 + * every site of it, and the queue is shown to a site administrator so they
1069 + * can see who is waiting, with the button locked and explained, which is
1070 + * how it has behaved since 2.11.8 and what matriz-red-limpieza-2114.sh
1071 + * checks. Loosening it is a decision about who may let people into a
1072 + * network, not a tidy-up, so it belongs with the rest of the network
1073 + * permissions work in 3.1.0 and not in a security release.
1074 + */
1075 + if ( ! current_user_can( 'edit_user', $user_id ) ) {
1076 + wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
1077 + }
1078 +
1069 1079 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
1070 1080 $result = $user_security->approve_user( $user_id, get_current_user_id() );
1071 1081
1072 1082 if ( $result ) {
@@ -1099,8 +1109,14 @@
1099 1109 if ( ! $user_id ) {
1100 1110 wp_send_json_error( __( 'Invalid user ID.', 'vigilante' ) );
1101 1111 }
1102 1112
1113 + // See ajax_approve_user(): the account and its pending flag belong to the
1114 + // whole network (2.11.8).
1115 + if ( ! current_user_can( 'edit_user', $user_id ) ) {
1116 + wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
1117 + }
1118 +
1103 1119 $user = get_userdata( $user_id );
1104 1120 $username = $user ? $user->user_login : $user_id;
1105 1121
1106 1122 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
@@ -1139,8 +1155,14 @@
1139 1155 if ( ! $user ) {
1140 1156 wp_send_json_error( __( 'User not found.', 'vigilante' ) );
1141 1157 }
1142 1158
1159 + // Sessions carry IP, User-Agent and login time. manage_options alone is
1160 + // not enough on a network, where it is held per subsite.
1161 + if ( ! current_user_can( 'edit_user', $user_id ) ) {
1162 + wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
1163 + }
1164 +
1143 1165 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
1144 1166 $sessions = $user_security->get_user_sessions( $user_id );
1145 1167
1146 1168 wp_send_json_success( array(
@@ -1169,8 +1191,12 @@
1169 1191 if ( ! $user_id || ! $token_hash ) {
1170 1192 wp_send_json_error( __( 'Invalid parameters.', 'vigilante' ) );
1171 1193 }
1172 1194
1195 + if ( ! current_user_can( 'edit_user', $user_id ) ) {
1196 + wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
1197 + }
1198 +
1173 1199 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
1174 1200 $result = $user_security->revoke_session( $user_id, $token_hash );
1175 1201
1176 1202 if ( $result ) {
@@ -1198,8 +1224,12 @@
1198 1224 if ( ! $user_id ) {
1199 1225 wp_send_json_error( __( 'Invalid user ID.', 'vigilante' ) );
1200 1226 }
1201 1227
1228 + if ( ! current_user_can( 'edit_user', $user_id ) ) {
1229 + wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
1230 + }
1231 +
1202 1232 $user_security = new Vigilante_User_Security( $this->settings, $this->activity_log );
1203 1233 $count = $user_security->revoke_all_sessions( $user_id, $include_current );
1204 1234
1205 1235 wp_send_json_success( array(
@@ -1297,8 +1327,16 @@
1297 1327 if ( ! current_user_can( 'manage_options' ) ) {
1298 1328 wp_send_json_error( __( 'Permission denied.', 'vigilante' ) );
1299 1329 }
1300 1330
1331 + // The dump is taken with $wpdb->prefix, which on the main site of a
1332 + // network matches every subsite table plus the global user tables, and
1333 + // the options it carries include the stored copy of wp-config.php. Same
1334 + // gate the rest of the network-shared operations use.
1335 + if ( ! Vigilante_Settings::can_write_shared_files() ) {
1336 + wp_send_json_error( Vigilante_Settings::get_shared_files_notice() );
1337 + }
1338 +
1301 1339 $backup = new Vigilante_Database_Backup();
1302 1340 $tables = $backup->get_tables();
1303 1341
1304 1342 wp_send_json_success( $tables );
@@ -1313,8 +1351,16 @@
1313 1351 check_ajax_referer( 'vigilante_admin_nonce', 'nonce' );
1314 1352
1315 1353 if ( ! current_user_can( 'manage_options' ) ) {
1316 1354 wp_die( esc_html__( 'Permission denied.', 'vigilante' ), 403 );
1355 + }
1356 +
1357 + // The dump is taken with $wpdb->prefix, which on the main site of a
1358 + // network matches every subsite table plus the global user tables, and
1359 + // the options it carries include the stored copy of wp-config.php. Same
1360 + // gate the rest of the network-shared operations use.
1361 + if ( ! Vigilante_Settings::can_write_shared_files() ) {
1362 + wp_die( esc_html( Vigilante_Settings::get_shared_files_notice() ), 403 );
1317 1363 }
1318 1364
1319 1365 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
1320 1366 $tables_raw = isset( $_POST['tables'] ) ? wp_unslash( $_POST['tables'] ) : '';