Plugin Directory

Changeset 3438917


Ignore:
Timestamp:
01/13/2026 06:30:54 PM (5 weeks ago)
Author:
MacSteini
Message:

Updated

Location:
wp-browser-update/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-browser-update/trunk/WP-BrowserUpdate.php

    r3329961 r3438917  
    44Plugin URI: https://wpbu.steinbrecher.co/
    55Description: 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
     6Version: 5.1.1
    77Author: Marco Steinbrecher
    88Author URI: https://profiles.wordpress.org/macsteini
     
    3030curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    3131curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MyBrowserVersionBot/1.0)');
     32curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     33curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     34
    3235$data = curl_exec($ch);
     36if ($data === false) {
     37curl_close($ch);
     38return '';
     39}
     40
    3341curl_close($ch);
    3442return $data;
     
    4149libxml_use_internal_errors(true);
    4250$dom = new DOMDocument();
    43 $dom->loadHTML($html);
     51$dom->loadHTML($html, LIBXML_NONET);
    4452libxml_clear_errors();
    4553
     
    6573}
    6674
     75function wpbu_normalize_version_for_buorg($v) {
     76$v = trim((string)$v);
     77
     78if ($v==='') return 0;
     79if (preg_match('/^-?\d+$/', $v)) return (int)$v;
     80if (preg_match('/^\d+(?:\.\d+)+$/', $v)) return (int) explode('.', $v)[0];
     81if (preg_match('/^-?\d+/', $v, $m)) return (int)$m[0];
     82
     83return 0;
     84}
     85
    6786function 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);
     102for ($i = 0; $i < 8; $i++) {
     103if ($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
     128echo "<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";
    82129}
    83130
     
    85132if (!current_user_can('manage_options')) wp_die(__('You do not have sufficient permissions to access this page.'));
    86133
    87 if (isset($_POST['wpbu_submit']) and wp_verify_nonce($_POST['form_nonce'], 'test-nonce')) {
     134if (isset($_POST['wpbu_submit']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['form_nonce'] ?? '')), 'test-nonce')) {
    88135foreach (['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]);
     136if (!isset($_POST[$field])) continue;
     137$_POST[$field] = trim((string) wp_unslash($_POST[$field]));
     138$_POST[$field] = preg_replace('/(?!^-)[^0-9.]/', '', $_POST[$field]);
     139if (!preg_match('/^-?\d+(\.\d+)*$/', $_POST[$field])) {
     140$_POST[$field] = '0';
     141}
    90142}
    91143
    92144$fields_to_sanitize = ['wpbu_reminder', 'wpbu_testing', 'wpbu_newwindow', 'wpbu_style', 'wpbu_secis', 'wpbu_unsup', 'wpbu_mobile', 'wpbu_shift'];
    93145foreach ($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']);
     146if (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'] ?? ''));
    98150
    99151$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'];
    100152
    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'))];
    102154
    103155update_option('wp_browserupdate_browsers', implode(' ', $browsers));
    104156update_option('wp_browserupdate_js', implode(' ', $js_settings));
    105 update_option('wp_browserupdate_css_buorg', sanitize_textarea_field($_POST['wpbu_css_buorg'] ?? ''));
     157update_option('wp_browserupdate_css_buorg', $css);
    106158
    107159echo '<div class="updated"><p><strong>'.esc_html__('Settings saved.', 'wp-browser-update').'</strong></p></div>';
     
    109161
    110162$wpbu_vars = explode(' ', get_option('wp_browserupdate_browsers', '0 0 0 0 0'));
     163$wpbu_vars = array_pad($wpbu_vars, 5, '0');
    111164
    112165$browsers = [
     
    140193'selected' => $wpbu_vars[3],
    141194'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+)+/',
    145198],
    146199
     
    186239}
    187240
    188 ###
    189 ###
    190 ###
    191 
    192241echo '<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>';
    193242
     
    200249$version = wpbu_getversion_cached($browser['url'], $browser['xpath'], $regex);
    201250}
    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
     257if ($selected_raw === '0') $output .= ' <small>'.esc_html__('Detection: show all outdated versions (default)', 'wp-browser-update').'</small>';
     258elseif ($normalized < 0) $output .= ' <small>'.sprintf(esc_html__('Detection: latest − %d major versions', 'wp-browser-update'), abs($normalized)).'</small>';
     259else $output .= ' <small>'.sprintf(esc_html__('Detection uses major version: %s', 'wp-browser-update'), esc_html($normalized)).'</small>';
     260
     261if ($version) $output .= ' <small> — '.esc_html__('Latest version', 'wp-browser-update').': '.esc_html($version).'</small>';
    204262$output .= '</td></tr>';
    205263}
     
    208266
    209267$wpbu_defaults = ['12', 'false', 'true', 'top', 'true', 'true', 'true', 'true'];
     268
    210269$wpbu_js = explode(' ', get_option('wp_browserupdate_js', implode(' ', $wpbu_defaults)));
     270$wpbu_js = array_pad($wpbu_js, 8, null);
     271
     272for ($i = 0; $i < 8; $i++) {
     273if ($wpbu_js[$i] === null || $wpbu_js[$i] === '') $wpbu_js[$i] = $wpbu_defaults[$i];
     274}
    211275
    212276$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  
    66Requires at least: 4.6
    77Requires PHP: 7.4
    8 Stable tag: 5.1
     8Stable tag: 5.1.1
    99License: GPLv3 or later
    1010License URI: https://gnu.org/licenses/gpl
     
    6262
    6363== 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
    6467= 5.1 =
    6568* Added:
Note: See TracChangeset for help on using the changeset viewer.