Changeset 3438917
- Timestamp:
- 01/13/2026 06:30:54 PM (5 weeks ago)
- Location:
- wp-browser-update/trunk
- Files:
-
- 2 edited
-
WP-BrowserUpdate.php (modified) (10 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-browser-update/trunk/WP-BrowserUpdate.php
r3329961 r3438917 4 4 Plugin URI: https://wpbu.steinbrecher.co/ 5 5 Description: This plugin notifies website visitors to update their outdated browser in a non-intrusive way. Visit <a href="https://browserupdate.org/" title="browserupdate.org" target="_blank">browserupdate.org</a> for more information… 6 Version: 5.1 6 Version: 5.1.1 7 7 Author: Marco Steinbrecher 8 8 Author URI: https://profiles.wordpress.org/macsteini … … 30 30 curl_setopt($ch, CURLOPT_TIMEOUT, 10); 31 31 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MyBrowserVersionBot/1.0)'); 32 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 33 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 34 32 35 $data = curl_exec($ch); 36 if ($data === false) { 37 curl_close($ch); 38 return ''; 39 } 40 33 41 curl_close($ch); 34 42 return $data; … … 41 49 libxml_use_internal_errors(true); 42 50 $dom = new DOMDocument(); 43 $dom->loadHTML($html );51 $dom->loadHTML($html, LIBXML_NONET); 44 52 libxml_clear_errors(); 45 53 … … 65 73 } 66 74 75 function wpbu_normalize_version_for_buorg($v) { 76 $v = trim((string)$v); 77 78 if ($v==='') return 0; 79 if (preg_match('/^-?\d+$/', $v)) return (int)$v; 80 if (preg_match('/^\d+(?:\.\d+)+$/', $v)) return (int) explode('.', $v)[0]; 81 if (preg_match('/^-?\d+/', $v, $m)) return (int)$m[0]; 82 83 return 0; 84 } 85 67 86 function wpbu() { 68 $wpbu_vars = explode(' ', get_option('wp_browserupdate_browsers', '0 0 0 0 0')); 69 $wpbu_js = explode(' ', get_option('wp_browserupdate_js', '12 false true top true true true true')); 70 $browser = 'e:'.$wpbu_vars[0].',f:'.$wpbu_vars[1].',o:'.$wpbu_vars[2].',s:'.$wpbu_vars[3].(!isset($wpbu_vars[4])?'':',c:'.$wpbu_vars[4]); 71 echo '<script> 72 var $buoop = {required:{e:'.$wpbu_vars[0].',f:'.$wpbu_vars[1].',o:'.$wpbu_vars[2].',s:'.$wpbu_vars[3].(!isset($wpbu_vars[4])?'':',c:'.$wpbu_vars[4]).'},test:'.($wpbu_js[1] ?? '').',newwindow:'.($wpbu_js[2] ?? '').',style:"'.($wpbu_js[3] ?? '').'",insecure:'.($wpbu_js[4] ?? '').',unsupported:'.($wpbu_js[5] ?? '').',mobile:'.($wpbu_js[6] ?? '').',shift_page_down:'.($wpbu_js[7] ?? '').',api:2025.07}; 73 74 function $buo_f(){ 75 var e = document.createElement("script"); 76 e.src = "//browser-update.org/update.min.js"; 77 document.body.appendChild(e); 78 }; 79 try {document.addEventListener("DOMContentLoaded", $buo_f, false)} 80 catch(e){window.attachEvent("onload", $buo_f)} 81 </script>'; 87 $raw = explode(' ', get_option('wp_browserupdate_browsers', '0 0 0 0 0')); 88 $raw = array_pad($raw, 5, '0'); 89 90 $required = [ 91 'e' => wpbu_normalize_version_for_buorg($raw[0]), 92 'f' => wpbu_normalize_version_for_buorg($raw[1]), 93 'o' => wpbu_normalize_version_for_buorg($raw[2]), 94 's' => wpbu_normalize_version_for_buorg($raw[3]), 95 'c' => wpbu_normalize_version_for_buorg($raw[4]), 96 ]; 97 98 $defaults = ['12', 'false', 'true', 'top', 'true', 'true', 'true', 'true']; 99 $js = explode(' ', get_option('wp_browserupdate_js', implode(' ', $defaults))); 100 101 $js = array_pad($js, 8, null); 102 for ($i = 0; $i < 8; $i++) { 103 if ($js[$i] === null || $js[$i] === '') $js[$i] = $defaults[$i]; 104 } 105 106 $reminder = (int)$js[0]; 107 $test = ($js[1] ?? 'false') === 'true'; 108 $newwindow = ($js[2] ?? 'true') === 'true'; 109 $style = in_array(($js[3] ?? 'top'), ['top', 'bottom', 'corner'], true) ? $js[3] : 'top'; 110 $insecure = ($js[4] ?? 'true') === 'true'; 111 $unsupported = ($js[5] ?? 'true') === 'true'; 112 $mobile = ($js[6] ?? 'true') === 'true'; 113 $shift = ($js[7] ?? 'true') === 'true'; 114 115 $buoop = [ 116 'required' => $required, 117 'reminder' => $reminder, 118 'test' => $test, 119 'newwindow' => $newwindow, 120 'style' => $style, 121 'insecure' => $insecure, 122 'unsupported' => $unsupported, 123 'mobile' => $mobile, 124 'shift_page_down' => $shift, 125 'api' => 2026.01, 126 ]; 127 128 echo "<script>\nvar \$buoop = " . wp_json_encode($buoop, JSON_UNESCAPED_SLASHES) . ";\nfunction \$buo_f(){var e=document.createElement('script');e.src='//browser-update.org/update.min.js';document.body.appendChild(e);}\ntry{document.addEventListener('DOMContentLoaded', \$buo_f,false)}catch(e){window.attachEvent('onload', \$buo_f)}\n</script>\n"; 82 129 } 83 130 … … 85 132 if (!current_user_can('manage_options')) wp_die(__('You do not have sufficient permissions to access this page.')); 86 133 87 if (isset($_POST['wpbu_submit']) and wp_verify_nonce($_POST['form_nonce'], 'test-nonce')) {134 if (isset($_POST['wpbu_submit']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['form_nonce'] ?? '')), 'test-nonce')) { 88 135 foreach (['wpbu_msie', 'wpbu_firefox', 'wpbu_opera', 'wpbu_safari', 'wpbu_google'] as $field) { 89 if (isset($_POST[$field])) $_POST[$field] = preg_replace('/[^0-9.\-]/', '', $_POST[$field]); 136 if (!isset($_POST[$field])) continue; 137 $_POST[$field] = trim((string) wp_unslash($_POST[$field])); 138 $_POST[$field] = preg_replace('/(?!^-)[^0-9.]/', '', $_POST[$field]); 139 if (!preg_match('/^-?\d+(\.\d+)*$/', $_POST[$field])) { 140 $_POST[$field] = '0'; 141 } 90 142 } 91 143 92 144 $fields_to_sanitize = ['wpbu_reminder', 'wpbu_testing', 'wpbu_newwindow', 'wpbu_style', 'wpbu_secis', 'wpbu_unsup', 'wpbu_mobile', 'wpbu_shift']; 93 145 foreach ($fields_to_sanitize as $field) { 94 if (isset($_POST[$field])) $_POST[$field] = sanitize_text_field( $_POST[$field]);95 } 96 97 $ _POST['wpbu_css_buorg'] = sanitize_textarea_field($_POST['wpbu_css_buorg']);146 if (isset($_POST[$field])) $_POST[$field] = sanitize_text_field(wp_unslash($_POST[$field])); 147 } 148 149 $css = sanitize_textarea_field(wp_unslash($_POST['wpbu_css_buorg'] ?? '')); 98 150 99 151 $browsers = ['msie' => $_POST['wpbu_msie'] ?? '0', 'firefox'=> $_POST['wpbu_firefox'] ?? '0', 'opera'=> $_POST['wpbu_opera'] ?? '0', 'safari' => $_POST['wpbu_safari'] ?? '0', 'google' => $_POST['wpbu_google'] ?? '0']; 100 152 101 $js_settings = [(int) ($_POST['wpbu_reminder'] ?? 12), sanitize_text_field( $_POST['wpbu_testing'] ?? 'false'), sanitize_text_field($_POST['wpbu_newwindow'] ?? 'false'), sanitize_text_field($_POST['wpbu_style'] ?? 'top'), sanitize_text_field($_POST['wpbu_secis'] ?? 'false'), sanitize_text_field($_POST['wpbu_unsup'] ?? 'false'), sanitize_text_field($_POST['wpbu_mobile'] ?? 'false'), sanitize_text_field($_POST['wpbu_shift'] ?? 'false')];153 $js_settings = [(int) ($_POST['wpbu_reminder'] ?? 12), sanitize_text_field(wp_unslash($_POST['wpbu_testing'] ?? 'false')), sanitize_text_field(wp_unslash($_POST['wpbu_newwindow'] ?? 'false')), sanitize_text_field(wp_unslash($_POST['wpbu_style'] ?? 'top')), sanitize_text_field(wp_unslash($_POST['wpbu_secis'] ?? 'false')), sanitize_text_field(wp_unslash($_POST['wpbu_unsup'] ?? 'false')), sanitize_text_field(wp_unslash($_POST['wpbu_mobile'] ?? 'false')), sanitize_text_field(wp_unslash($_POST['wpbu_shift'] ?? 'false'))]; 102 154 103 155 update_option('wp_browserupdate_browsers', implode(' ', $browsers)); 104 156 update_option('wp_browserupdate_js', implode(' ', $js_settings)); 105 update_option('wp_browserupdate_css_buorg', sanitize_textarea_field($_POST['wpbu_css_buorg'] ?? ''));157 update_option('wp_browserupdate_css_buorg', $css); 106 158 107 159 echo '<div class="updated"><p><strong>'.esc_html__('Settings saved.', 'wp-browser-update').'</strong></p></div>'; … … 109 161 110 162 $wpbu_vars = explode(' ', get_option('wp_browserupdate_browsers', '0 0 0 0 0')); 163 $wpbu_vars = array_pad($wpbu_vars, 5, '0'); 111 164 112 165 $browsers = [ … … 140 193 'selected' => $wpbu_vars[3], 141 194 'download' => 'https://support.apple.com/102665', 142 'url' => 'https://en.wikipedia.org/wiki/Safari_(web_browser)',143 'xpath' => "//table[contains(@class,'infobox')]//tr[th//a[text()='Stable release(s)']]/following-sibling::tr[1]//table[contains(@class, 'infobox-subbox')]//tr[th[text()='macOS']]/td",144 'regex' => '/\d+(\.\d+)+/',195 'url'=> 'https://support.apple.com/en-us/100100', 196 'xpath'=> "(//a[starts-with(normalize-space(.), 'Safari ')])[1]", 197 'regex'=> '/\d+(?:\.\d+)+/', 145 198 ], 146 199 … … 186 239 } 187 240 188 ###189 ###190 ###191 192 241 echo '<div class="wrap"><form action="'.esc_url($_SERVER['REQUEST_URI']).'" method="post"><input type="hidden" name="form_nonce" value="'.esc_attr(wp_create_nonce('test-nonce')).'" /><h1>WP BrowserUpdate</h1><h2>'.esc_html__('Outdated Browser Versions', 'wp-browser-update').'</h2><p>'.esc_html__('Select the browser versions you consider outdated (including all earlier versions). If left unchanged, WP BrowserUpdate will use the default settings.', 'wp-browser-update').'</p><p>'.esc_html__('If you set the browser version to 0, a notification will be shown for every outdated browser version.', 'wp-browser-update').'</p>'; 193 242 … … 200 249 $version = wpbu_getversion_cached($browser['url'], $browser['xpath'], $regex); 201 250 } 202 $output .= '<tr><th scope="row"><label for="wpbu_'.esc_attr($key).'"><a href="'.$browser['download'].'" target="_blank">'.esc_html($browser['name']).'</a></label></th><td><input type="text" pattern="^[0-9.]+$" name="wpbu_'.esc_attr($key).'" id="wpbu_'.esc_attr($key).'" value="'.esc_attr($browser['selected']).'" title="'.__('Only numbers and dots are allowed', 'wp-browser-update').'" size="12" />'; 203 if ($version) $output .= ' <small>'.esc_html__('Latest version', 'wp-browser-update').': '.esc_html($version).'</small>'; 251 252 $selected_raw = trim((string)($browser['selected'] ?? '0')); 253 $normalized = wpbu_normalize_version_for_buorg($selected_raw); 254 255 $output .= '<tr><th scope="row"><label for="wpbu_'.esc_attr($key).'"><a href="'.$browser['download'].'" target="_blank">'.esc_html($browser['name']).'</a></label></th><td><input type="text" pattern="^-?[0-9]+(\.[0-9]+)*$" name="wpbu_'.esc_attr($key).'" id="wpbu_'.esc_attr($key).'" value="'.esc_attr($browser['selected']).'" title="'.__('Only numbers, dots and an optional leading minus are allowed', 'wp-browser-update').'" size="12" />'; 256 257 if ($selected_raw === '0') $output .= ' <small>'.esc_html__('Detection: show all outdated versions (default)', 'wp-browser-update').'</small>'; 258 elseif ($normalized < 0) $output .= ' <small>'.sprintf(esc_html__('Detection: latest − %d major versions', 'wp-browser-update'), abs($normalized)).'</small>'; 259 else $output .= ' <small>'.sprintf(esc_html__('Detection uses major version: %s', 'wp-browser-update'), esc_html($normalized)).'</small>'; 260 261 if ($version) $output .= ' <small> — '.esc_html__('Latest version', 'wp-browser-update').': '.esc_html($version).'</small>'; 204 262 $output .= '</td></tr>'; 205 263 } … … 208 266 209 267 $wpbu_defaults = ['12', 'false', 'true', 'top', 'true', 'true', 'true', 'true']; 268 210 269 $wpbu_js = explode(' ', get_option('wp_browserupdate_js', implode(' ', $wpbu_defaults))); 270 $wpbu_js = array_pad($wpbu_js, 8, null); 271 272 for ($i = 0; $i < 8; $i++) { 273 if ($wpbu_js[$i] === null || $wpbu_js[$i] === '') $wpbu_js[$i] = $wpbu_defaults[$i]; 274 } 211 275 212 276 $wpbu_keys = ['wpbu_reminder', 'wpbu_testing', 'wpbu_newwindow', 'wpbu_style', 'wpbu_secis', 'wpbu_unsup', 'wpbu_mobile', 'wpbu_shift']; -
wp-browser-update/trunk/readme.txt
r3406187 r3438917 6 6 Requires at least: 4.6 7 7 Requires PHP: 7.4 8 Stable tag: 5.1 8 Stable tag: 5.1.1 9 9 License: GPLv3 or later 10 10 License URI: https://gnu.org/licenses/gpl … … 62 62 63 63 == Changelog == 64 = 5.1.1 = 65 * Fixed: Prevented a frontend "Uncaught Error" caused by invalid/unexpected browser version strings by hardening version parsing and normalisation. Thanks to @danyloliptuha for pointing out. 66 64 67 = 5.1 = 65 68 * Added:
Note: See TracChangeset
for help on using the changeset viewer.