Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/newsletters-lite/models/fields_list.php
+++ b/newsletters-lite/models/fields_list.php
@@ -200,26 +200,15 @@
{
global $wpdb, $Field;
- //$list_id = (empty($list_id)) ? 'all' : $list_id;
-
- if (!empty($list_id) && is_array($list_id)) {
- $listidquery = "(";
- $l = 1;
-
- foreach ($list_id as $likey => $lival) {
- $listidquery .= $wpdb -> prefix . $this -> table . ".list_id = '" . $lival . "'";
-
- if ($l < count($list_id)) {
- $listidquery .= " OR ";
- }
-
- $l++;
+ $listidquery = '';
+ if ($list_id !== 'all' && $list_id !== null && $list_id !== false && $list_id !== '') {
+ $ids = $this -> normalize_mailinglist_ids($list_id);
+ if ($ids === false) {
+ return false;
}
-
- $listidquery .= ") OR";
- } else {
- if (is_numeric($list_id)) {
- $listidquery = $wpdb -> prefix . $this -> table . ".list_id = '" . $list_id . "' OR";
+ if (!empty($ids)) {
+ $placeholders = implode(', ', array_fill(0, count($ids), '%d'));
+ $listidquery = $wpdb -> prepare($wpdb -> prefix . $this -> table . ".list_id IN (" . $placeholders . ") OR", $ids);
}
}
--- a/newsletters-lite/models/mailinglist.php
+++ b/newsletters-lite/models/mailinglist.php
@@ -254,21 +254,15 @@
$privatecond = ($privatelists == true) ? "WHERE 1 = 1" : "WHERE `privatelist` = 'N'";
- if (!empty($ids) && is_array($ids)) {
- $p = 1;
- $privatecond .= " AND (";
-
- foreach ($ids as $id) {
- $privatecond .= "id = '" . $id . "'";
- if ($p < count($ids)) {
- $privatecond .= " OR ";
- }
- $p++;
+ // No restriction is intentional only when no list IDs were supplied.
+ if ($ids !== null && $ids !== false && $ids !== '' && $ids !== array()) {
+ $ids = $this -> normalize_mailinglist_ids($ids);
+ if ($ids === false || empty($ids)) {
+ return false;
}
-
- $privatecond .= ")";
+ $placeholders = implode(', ', array_fill(0, count($ids), '%d'));
+ $privatecond .= $wpdb -> prepare(" AND id IN (" . $placeholders . ")", $ids);
}
-
$query = "SELECT `id`, `title`, `paid`, `price`, `interval` FROM `" . $wpdb -> prefix . $this -> table_name . "` " . $privatecond . " ORDER BY `title` ASC";
$query_hash = md5($query);
--- a/newsletters-lite/views/default/subscribe.php
+++ b/newsletters-lite/views/default/subscribe.php
@@ -549,7 +549,7 @@
<?php if (is_user_logged_in()) : ?>
<?php $current_user = wp_get_current_user(); ?>
<?php global $wpdb; ?>
- <?php if ($wpdb -> get_row("SELECT * FROM " . $wpdb -> prefix . $Subscriber -> table . " WHERE `email` = '" . $current_user -> user_email . "' AND `user_id` = '" . $current_user -> ID . "'")) : ?>
+ <?php if ($wpdb -> get_row($wpdb -> prepare("SELECT * FROM `" . $wpdb -> prefix . $Subscriber -> table . "` WHERE `email` = %s AND `user_id` = %d", $current_user -> user_email, $current_user -> ID))) : ?>
<div class="alert alert-success">
<i class="fa fa-check"></i> <?php echo esc_html(sprintf(__('You are already subscribed with email address %s. Go to the %s page to manage your subscription.', 'wp-mailinglist'), '<strong>' . esc_html($current_user -> user_email) . '</strong>', '<a href="' . esc_url_raw($this -> get_managementpost(true)) . '">' . __('manage subscriptions', 'wp-mailinglist') . '</a>')); ?>
</div>
--- a/newsletters-lite/views/default/widget.php
+++ b/newsletters-lite/views/default/widget.php
@@ -9,9 +9,9 @@
<?php if (is_user_logged_in()) : ?>
<?php $current_user = wp_get_current_user(); ?>
<?php global $wpdb; ?>
- <?php if ($wpdb -> get_row("SELECT * FROM " . $wpdb -> prefix . $Subscriber -> table . " WHERE `email` = '" . $current_user -> user_email . "' AND `user_id` = '" . $current_user -> ID . "'")) : ?>
+ <?php if ($wpdb -> get_row($wpdb -> prepare("SELECT * FROM `" . $wpdb -> prefix . $Subscriber -> table . "` WHERE `email` = %s AND `user_id` = %d", $current_user -> user_email, $current_user -> ID))) : ?>
<div class="ui-state-highlight ui-corner-all">
- <p><i class="fa-solid fa-check"></i> <?php echo sprintf(__('You are already subscribed with email address %s. Go to the %s page to manage your subscription.', 'wp-mailinglist'), '<strong>' . $current_user -> user_email . '</strong>', '<a href="' . $this -> get_managementpost(true) . '">' . __('manage subscriptions', 'wp-mailinglist') . '</a>'); ?></p>
+ <p><i class="fa-solid fa-check"></i> <?php echo sprintf(__('You are already subscribed with email address %s. Go to the %s page to manage your subscription.', 'wp-mailinglist'), '<strong>' . esc_html($current_user -> user_email) . '</strong>', '<a href="' . $this -> get_managementpost(true) . '">' . __('manage subscriptions', 'wp-mailinglist') . '</a>'); ?></p>
</div>
<?php endif; ?>
<?php endif; ?>
--- a/newsletters-lite/views/default2/functions.php
+++ b/newsletters-lite/views/default2/functions.php
@@ -143,18 +143,11 @@
ob_start();
- $field_value = false;
- if (!empty($Subscriber -> data[$field -> slug])) {
- $field_value = maybe_unserialize($Subscriber -> data[$field -> slug]);
- }
-
+ $field_value = isset($Subscriber -> data[$field -> slug]) ? $Subscriber -> data[$field -> slug] : false;
+ $date_timestamp = $this -> date_field_timestamp($field_value);
$currentDate = "";
- if (!empty($field_value) && $field_value != "0000-00-00") {
- if (is_array($field_value)) {
- $currentDate = date_i18n(get_option('date_format'), strtotime($field_value['d'] . '/' . $field_value['m'] . '/' . $field_value['y']));
- } else {
- $currentDate = date_i18n(get_option('date_format'), strtotime($field_value));
- }
+ if ($date_timestamp !== false) {
+ $currentDate = date_i18n(get_option('date_format'), $date_timestamp);
}
if (!empty($currentDate)) {
--- a/newsletters-lite/views/default2/subscribe.php
+++ b/newsletters-lite/views/default2/subscribe.php
@@ -568,9 +568,9 @@
<?php $current_user = wp_get_current_user(); ?>
<?php global $wpdb; ?>
- <?php if ($wpdb -> get_row("SELECT * FROM " . $wpdb -> prefix . $Subscriber -> table . " WHERE `email` = '" . $current_user -> user_email . "' AND `user_id` = '" . $current_user -> ID . "'")) : ?>
+ <?php if ($wpdb -> get_row($wpdb -> prepare("SELECT * FROM `" . $wpdb -> prefix . $Subscriber -> table . "` WHERE `email` = %s AND `user_id` = %d", $current_user -> user_email, $current_user -> ID))) : ?>
<div class="alert alert-success">
- <i class="fa fa-check"></i> <?php echo sprintf(__('You are already subscribed with email address %s. Go to the %s page to manage your subscription.', 'wp-mailinglist'), '<strong>' . $current_user -> user_email . '</strong>', '<a href="' . $this -> get_managementpost(true) . '">' . __('manage subscriptions', 'wp-mailinglist') . '</a>'); ?>
+ <i class="fa fa-check"></i> <?php echo sprintf(__('You are already subscribed with email address %s. Go to the %s page to manage your subscription.', 'wp-mailinglist'), '<strong>' . esc_html($current_user -> user_email) . '</strong>', '<a href="' . $this -> get_managementpost(true) . '">' . __('manage subscriptions', 'wp-mailinglist') . '</a>'); ?>
</div>
<?php endif; ?>
<?php endif; ?>
--- a/newsletters-lite/views/default2/widget.php
+++ b/newsletters-lite/views/default2/widget.php
@@ -9,9 +9,9 @@
<?php if (is_user_logged_in()) : ?>
<?php $current_user = wp_get_current_user(); ?>
<?php global $wpdb; ?>
- <?php if ($wpdb -> get_row("SELECT * FROM " . $wpdb -> prefix . $Subscriber -> table . " WHERE `email` = '" . $current_user -> user_email . "' AND `user_id` = '" . $current_user -> ID . "'")) : ?>
+ <?php if ($wpdb -> get_row($wpdb -> prepare("SELECT * FROM `" . $wpdb -> prefix . $Subscriber -> table . "` WHERE `email` = %s AND `user_id` = %d", $current_user -> user_email, $current_user -> ID))) : ?>
<div class="alert alert-success">
- <i class="fa-solid fa-check"></i> <?php echo sprintf(__('You are already subscribed with email address %s. Go to the %s page to manage your subscription.', 'wp-mailinglist'), '<strong>' . $current_user -> user_email . '</strong>', '<a href="' . $this -> get_managementpost(true) . '">' . __('manage subscriptions', 'wp-mailinglist') . '</a>'); ?>
+ <i class="fa-solid fa-check"></i> <?php echo sprintf(__('You are already subscribed with email address %s. Go to the %s page to manage your subscription.', 'wp-mailinglist'), '<strong>' . esc_html($current_user -> user_email) . '</strong>', '<a href="' . $this -> get_managementpost(true) . '">' . __('manage subscriptions', 'wp-mailinglist') . '</a>'); ?>
</div>
<?php endif; ?>
<?php endif; ?>
--- a/newsletters-lite/wp-mailinglist-plugin.php
+++ b/newsletters-lite/wp-mailinglist-plugin.php
@@ -8,7 +8,7 @@
var $name = 'Newsletters';
var $plugin_base;
var $pre = 'wpml';
- var $version = '4.18.2';
+ var $version = '4.18.3';
var $dbversion = '1.2.3';
var $debugging = false; //set to "true" to turn on debugging
var $debug_level = 2; //set to 1 for only database errors and var dump; 2 for PHP errors as well
@@ -3314,19 +3314,37 @@
check_ajax_referer('refreshfields', 'security');
- // No current_user_can required, this is open to all roles and non-users on the front-end
+ // Subscription form rendering is available to all roles and front-end visitors.
global $wpdb, $FieldsList, $Subscriber;
$widget_id = sanitize_text_field(wp_unslash($_GET['widget_id']));
- $instance = map_deep(wp_unslash($_POST['instance']), 'sanitize_text_field');
+ if (isset($_POST['instance']) && !is_array($_POST['instance'])) {
+ wp_die(__('Invalid form instance.', 'wp-mailinglist'), '', array('response' => 400));
+ }
+ $instance = isset($_POST['instance']) ? map_deep(wp_unslash($_POST['instance']), 'sanitize_text_field') : array();
+ if (isset($instance['lists'])) {
+ $instance_lists = $this -> normalize_mailinglist_ids($instance['lists']);
+ if ($instance_lists === false) {
+ wp_die(__('Invalid mailing list IDs.', 'wp-mailinglist'), '', array('response' => 400));
+ }
+ $instance['lists'] = implode(',', $instance_lists);
+ }
+ $list_id = isset($_POST['list_id']) ? wp_unslash($_POST['list_id']) : array();
+ if ($list_id !== 'all') {
+ $list_id = $this -> normalize_mailinglist_ids($list_id);
+ if ($list_id === false) {
+ wp_die(__('Invalid mailing list IDs.', 'wp-mailinglist'), '', array('response' => 400));
+ }
+ }
- $Subscriber -> data = map_deep(wp_unslash($_POST), 'sanitize_text_field');
+ $Subscriber -> data = map_deep(wp_unslash($_POST), array($this, 'sanitize_field_request_value'));
echo '<div class="newsletters-new-fields">';
- if ($fields = $FieldsList -> fields_by_list(sanitize_text_field(wp_unslash($_POST['list_id'])), "order", "ASC")) {
+ if ($fields = $FieldsList -> fields_by_list($list_id, "order", "ASC")) {
foreach ($fields as $field) {
- $this -> render_field($field -> id, true, $widget_id, true, true, $instance);
+ // Request-supplied instance settings must not expose private lists.
+ $this -> render_field($field -> id, true, $widget_id, true, true, $instance, false, array(), null, null, false);
}
}
@@ -5027,10 +5045,10 @@
$fields = $FieldsList -> fields_by_list($lists, 'order', "ASC", (($this -> get_option('managementallowemailchange') == "Y") ? true : false));
- $_POST = $oldpost;
- unset($_POST['action']);
- unset($_POST['subscriber_id']);
- unset($_POST['id']);
+ $_POST = $oldpost;
+ unset($_POST['action']);
+ unset($_POST['subscriber_id']);
+ unset($_POST['id']);
if (!empty($_POST)) {
$emailfield = $Field -> email_field();
@@ -5044,8 +5062,8 @@
$_POST['list_id'] = $lists;
- $_POST = $data = $Field -> validate_optin($_POST, 'management');
- $data['id'] = (int) $subscriber -> id;
+ $_POST = $data = $Field -> validate_optin($_POST, 'management');
+ $data['id'] = (int) $subscriber -> id;
if (!empty($Field -> errors)) {
$errors = array_merge((array) $errors, (array) $Field -> errors);
}
@@ -8546,7 +8564,67 @@
return false;
}
- function render_field($field_id = null, $fieldset = true, $optinid = null, $showcaption = true, $watermark = true, $instance = null, $offsite = false, $errors = array(), $form_id = null, $form_field = null) {
+ function normalize_mailinglist_ids($ids) {
+ if (is_string($ids)) {
+ $ids = explode(',', $ids);
+ } elseif (is_int($ids)) {
+ $ids = array($ids);
+ }
+ if (!is_array($ids)) {
+ return false;
+ }
+
+ $normalized = array();
+ foreach ($ids as $id) {
+ if (!is_string($id) && !is_int($id)) {
+ return false;
+ }
+ $id = trim((string) $id);
+ if ($id === '') {
+ continue;
+ }
+ if (!preg_match('/^[0-9]+$/D', $id) || (int) $id <= 0 || (string) (int) $id !== ltrim($id, '0')) {
+ return false;
+ }
+ $normalized[] = (int) $id;
+ }
+ return array_values(array_unique($normalized));
+ }
+
+ function sanitize_field_request_value($value) {
+ $value = sanitize_text_field($value);
+ // Form values are plain text or arrays, never PHP serialized data.
+ return is_serialized($value) ? '' : $value;
+ }
+
+ function date_field_timestamp($value, $from_request = false) {
+ if (is_string($value) && is_serialized($value)) {
+ if ($from_request) {
+ return false;
+ }
+ // Keep legacy stored dates readable without instantiating any classes.
+ $value = @unserialize(trim($value), array('allowed_classes' => false));
+ }
+
+ if (is_array($value)) {
+ foreach (array('d', 'm', 'y') as $part) {
+ if (!isset($value[$part]) || (!is_string($value[$part]) && !is_int($value[$part])) || !ctype_digit((string) $value[$part])) {
+ return false;
+ }
+ }
+ if (!checkdate((int) $value['m'], (int) $value['d'], (int) $value['y'])) {
+ return false;
+ }
+ $value = sprintf('%04d-%02d-%02d', $value['y'], $value['m'], $value['d']);
+ }
+
+ if (!is_string($value) || $value === '' || $value === '0000-00-00') {
+ return false;
+ }
+ return strtotime($value);
+ }
+
+ function render_field($field_id = null, $fieldset = true, $optinid = null, $showcaption = true, $watermark = true, $instance = null, $offsite = false, $errors = array(), $form_id = null, $form_field = null, $privatelists = true) {
global $Html, $Field, $wpmltabindex, $Mailinglist, $Subscriber,
${'newsletters_fields_count_' . $optinid}, $newsletters_is_management;
@@ -8620,7 +8698,7 @@
{
if (!empty($includelists)) {
- $lists_temp = $Mailinglist -> select(true, $includelists);
+ $lists_temp = $Mailinglist -> select($privatelists, $includelists);
} else {
$lists_temp = $Mailinglist -> select(false);
}
@@ -8787,7 +8865,7 @@
if (!empty($list)) {
switch ($list) {
case 'admin' :
- $lists = $Mailinglist -> select(true, $adminlists);
+ $lists = $Mailinglist -> select($privatelists, $adminlists);
if (!empty($lists)) {
foreach ($lists as $list_id => $list_title) {
echo '<input type="hidden" name="list_id[]" value="' . $list_id . '" />';
@@ -8796,7 +8874,7 @@
break;
case 'select' :
if (!empty($includelists)) {
- $lists = $Mailinglist -> select(true, $includelists);
+ $lists = $Mailinglist -> select($privatelists, $includelists);
} else {
$lists = $Mailinglist -> select(false);
}
@@ -8819,7 +8897,7 @@
break;
case 'checkboxes' :
if (!empty($includelists)) {
- $lists = $Mailinglist -> select(true, $includelists);
+ $lists = $Mailinglist -> select($privatelists, $includelists);
} else {
$lists = $Mailinglist -> select(false);
}
@@ -8867,8 +8945,9 @@
echo '</label>';
}
- $instance['lists'] = array_filter(explode(",", $instance['lists']));
- $lists = (empty($instance['lists'])) ? $Mailinglist -> select(false) : $Mailinglist -> select(true, $instance['lists']);
+ $instance_lists = $this -> normalize_mailinglist_ids(isset($instance['lists']) ? $instance['lists'] : array());
+ $lists = ($instance_lists === false) ? array() : (empty($instance_lists) ? $Mailinglist -> select(false) : $Mailinglist -> select($privatelists, $instance_lists));
+ $lists = is_array($lists) ? $lists : array();
if ($list == "checkboxes") {
foreach ($lists as $list_id => $list_title) {
@@ -9040,25 +9119,10 @@
case 'pre_date' :
ob_start();
- $field_value = false;
- if (!empty($fieldvalue)) {
- if ($fieldvalue_from_request) {
- $field_value = $fieldvalue;
- } elseif (is_string($fieldvalue) && function_exists('is_serialized') && is_serialized($fieldvalue)) {
- $maybe_unserialized = @unserialize($fieldvalue, array('allowed_classes' => false));
- $field_value = ($maybe_unserialized !== false || $fieldvalue === 'b:0;') ? $maybe_unserialized : $fieldvalue;
- } else {
- $field_value = $fieldvalue;
- }
- }
-
+ $date_timestamp = $this -> date_field_timestamp($fieldvalue, $fieldvalue_from_request);
$currentDate = "";
- if (!empty($field_value) && $field_value != "0000-00-00") {
- if (is_array($field_value)) {
- $currentDate = date_i18n(get_option('date_format'), strtotime($field_value['d'] . '/' . $field_value['m'] . '/' . $field_value['y']));
- } else {
- $currentDate = date_i18n(get_option('date_format'), strtotime($field_value));
- }
+ if ($date_timestamp !== false) {
+ $currentDate = date_i18n(get_option('date_format'), $date_timestamp);
}
if (!empty($currentDate)) {
--- a/newsletters-lite/wp-mailinglist.php
+++ b/newsletters-lite/wp-mailinglist.php
@@ -3,7 +3,7 @@
/*
Plugin Name: Newsletters
Plugin URI: https://tribulant.com/plugins/view/1/
-Version: 4.18.2
+Version: 4.18.3
Description: This newsletter software by Tribulant allows users to subscribe to multiple mailing lists on your WordPress website. Send newsletters manually or from posts, manage newsletter templates, view a complete history with tracking, import/export subscribers, accept paid subscriptions and much more. Remove limits by buying PRO. Once purchased, to avoid future issues, remove this version and install and use the paid version in its stead. No data will be lost.
Author: Tribulant
Author URI: https://tribulant.com
@@ -1349,6 +1349,10 @@
}
break;
case 'delete_transient' :
+ if (!current_user_can('manage_options')) {
+ wp_die(__('You do not have permission', 'wp-mailinglist'), '', array('response' => 403));
+ }
+ check_admin_referer('newsletters_delete_transient');
if (!empty($_GET['transient'])) {
delete_transient(sanitize_text_field(wp_unslash($_GET['transient'])));
$this -> redirect(admin_url('admin.php?page=' . $this -> sections -> queue));
@@ -10444,6 +10448,10 @@
do_action('newsletters_admin_settings');
if (!empty($_GET['reset']) && $_GET['reset'] == 1) {
+ if (!current_user_can('newsletters_settings')) {
+ wp_die(__('You do not have permission', 'wp-mailinglist'), '', array('response' => 403));
+ }
+ check_admin_referer($this -> sections -> settings . '_reset');
$this -> update_options();
$this -> redirect($this -> url);
}
@@ -10530,7 +10538,7 @@
}
$this -> update_option('sanitize_content', 1);
- $this -> redirect($Html -> retainquery('reset=1', $this -> url), $msg_type, $message);
+ $this -> redirect(add_query_arg('_wpnonce', wp_create_nonce($this -> sections -> settings . '_reset'), $Html -> retainquery('reset=1', $this -> url)), $msg_type, $message);
break;
default :
//make sure that data has been posted