Changeset 3259459
- Timestamp:
- 03/20/2025 10:56:13 PM (13 months ago)
- Location:
- bitspecter-suite/trunk/includes
- Files:
-
- 3 edited
-
Branding/BitspecterSuiteBranding.php (modified) (1 diff)
-
Hardening/BitspecterSuiteHardening.php (modified) (6 diffs)
-
Optimization/BitspecterSuiteOptimization.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bitspecter-suite/trunk/includes/Branding/BitspecterSuiteBranding.php
r3229325 r3259459 10 10 public function __construct() 11 11 { 12 // Hooks13 12 $this->init_hooks(); 14 13 } -
bitspecter-suite/trunk/includes/Hardening/BitspecterSuiteHardening.php
r3229325 r3259459 24 24 add_action('init', [$this, 'removeUnnecessaryFeatures']); 25 25 add_action('init', [$this, 'removeUnnecessaryWpHeadItems']); 26 add_action('init', [$this, 'disableRestApi']);27 26 add_action('init', [$this, 'disableFileEditor']); 28 27 add_action('init', [$this, 'blockXmlRpcRequests']); … … 30 29 add_action('init', [$this, 'blockAuthorScan']); 31 30 31 add_filter('rest_endpoints', [$this, 'disableUserEndpoints']); 32 32 33 // Header and error handling 33 34 add_action('send_headers', [$this, 'addSecurityHeaders']); 34 add_action('wp_login_failed', [$this, 'blockBruteForce']);35 35 add_filter('login_errors', [$this, 'hideLoginErrors']); 36 37 // REST API modifications38 add_filter('rest_endpoints', [$this, 'disableUserEndpoints']);39 add_filter('rest_authentication_errors', [$this, 'disableRestApiForGuests']);40 41 // File upload restrictions42 add_filter('upload_mimes', [$this, 'addCustomMimeTypes']);43 add_filter('upload_mimes', [$this, 'restrictFileUploads']);44 36 } 45 37 … … 89 81 } 90 82 91 public function disableRestApi(): void92 {93 add_filter('rest_enabled', '__return_false');94 add_filter('rest_jsonp_enabled', '__return_false');95 }96 97 83 public function disableUserEndpoints($endpoints): array 98 84 { … … 106 92 define('DISALLOW_FILE_EDIT', true); 107 93 } 108 }109 110 public function restrictFileUploads($mimes): array111 {112 $restricted_mimes = ['exe' => 'application/x-msdownload', 'php' => 'text/x-php', 'js' => 'application/javascript', 'html' => 'text/html'];113 foreach ($restricted_mimes as $ext => $mime) {114 unset($mimes[$ext]);115 }116 return $mimes;117 }118 119 public function addCustomMimeTypes($mimes): array120 {121 $mimes['svg'] = 'image/svg+xml';122 return $mimes;123 94 } 124 95 … … 147 118 } 148 119 149 public function blockBruteForce($username): void150 {151 $ip = isset($_SERVER['REMOTE_ADDR']) ? sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR'])) : '';152 $failedAttemptsKey = 'bitspecter_suite_login_failed_'.$ip;153 154 $failedAttempts = get_transient($failedAttemptsKey) ?: 0;155 $failedAttempts++;156 157 set_transient($failedAttemptsKey, $failedAttempts, 3600);158 159 if ($failedAttempts >= 5) {160 wp_die(esc_html__('You have been temporarily blocked due to too many login attempts. Try again later.', 'bitspecter-suite'));161 }162 }163 120 164 121 public function enforceHttps(): void … … 186 143 } 187 144 } 188 189 public function disableRestApiForGuests($access): mixed190 {191 if (! is_user_logged_in()) {192 return new \WP_Error('rest_forbidden', esc_html__('REST API access is restricted to logged-in users.', 'bitspecter-suite'), ['status' => 403]);193 }194 return $access;195 }196 145 } -
bitspecter-suite/trunk/includes/Optimization/BitspecterSuiteOptimization.php
r3229325 r3259459 23 23 public function removeUnnecessaryFeatures(): void 24 24 { 25 // Odebrání z WP hlavičky26 25 remove_action('wp_head', 'wp_generator'); 27 26 remove_action('wp_head', 'wp_resource_hints', 2); … … 31 30 remove_action('wp_head', 'wp_shortlink_wp_head'); 32 31 33 // Zakázání embeddingu34 32 remove_action('wp_head', 'wp_oembed_add_discovery_links'); 35 33 remove_action('wp_head', 'wp_oembed_add_host_js'); 36 34 add_filter('embed_oembed_discover', '__return_false'); 37 35 38 // Odebrání RSS feedů, pokud nejsou potřeba39 36 remove_action('wp_head', 'feed_links', 2); 40 37 remove_action('wp_head', 'feed_links_extra', 3); 41 38 } 42 39 43 /** 44 * Optimalizace načítání skriptů a stylů 45 */ 40 46 41 public function optimizeScriptsAndStyles(): void 47 42 { 48 // Zakázání block library CSS pro starší verze WordPressu49 43 if (! is_admin()) { 50 44 wp_dequeue_style('wp-block-library'); 51 45 wp_dequeue_style('wp-block-library-theme'); 52 wp_dequeue_style('wc-block-style'); // WooCommerce block CSS46 wp_dequeue_style('wc-block-style'); 53 47 } 54 48 } … … 57 51 * Zakázání načítání emoji 58 52 */ 59 public function disableEmojis() 53 public function disableEmojis(): void 60 54 { 61 55 remove_action('wp_head', 'print_emoji_detection_script', 7);
Note: See TracChangeset
for help on using the changeset viewer.