Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/premmerce-woocommerce-brands/premmerce-brands.php
+++ b/premmerce-woocommerce-brands/premmerce-brands.php
@@ -10,7 +10,7 @@
* Plugin Name: Premmerce Brands for WooCommerce
* Plugin URI: https://premmerce.com/premmerce-woocommerce-brands-free-plugin/
* Description: This plugin makes it possible to create an unlimited number of brands that can be assigned to the products for better cataloging.
- * Version: 1.2.16
+ * Version: 1.2.17
* Author: Premmerce
* Author URI: https://premmerce.com/
* License: GPL-2.0+
--- a/premmerce-woocommerce-brands/src/Admin/Admin.php
+++ b/premmerce-woocommerce-brands/src/Admin/Admin.php
@@ -38,7 +38,11 @@
add_filter('manage_product_brand_custom_column', array($this, 'productCatColumn'), 10, 3);
add_action('quick_edit_custom_box', array($this, 'quickEdit'), 10, 2);
add_action('manage_product_posts_custom_column', array($this, 'renderProductColumns'));
- add_action('woocommerce_product_bulk_and_quick_edit', array($this, 'saveEditPost'));
+ // Both fire only after WooCommerce has checked the nonce and the edit_post capability.
+ // Never use woocommerce_product_bulk_and_quick_edit: it fires on every admin save_post,
+ // including an anonymous checkout through admin-ajax.php.
+ add_action('woocommerce_product_quick_edit_save', array($this, 'saveQuickEdit'));
+ add_action('woocommerce_process_product_meta', array($this, 'saveProductBrand'));
add_action('restrict_manage_posts', array($this, 'productFilterDropdown'), 999);
// Bulk edit
@@ -296,14 +300,58 @@
}
/**
- * Save brand from quick edit form
+ * Save brand from the product quick edit form
+ *
+ * @param WC_Product $product
+ */
+ public function saveQuickEdit($product)
+ {
+ if (isset($_POST['product_brand'])) {
+ $this->setProductBrand($product->get_id(), wp_unslash($_POST['product_brand']));
+ }
+ }
+
+ /**
+ * Save brand from the brand meta box on the product edit screen
*
* @param int $postId
*/
- public function saveEditPost($postId)
+ public function saveProductBrand($postId)
{
if (isset($_POST['product_brand'])) {
- wp_set_post_terms($postId, $_POST['product_brand'], 'product_brand');
+ $this->setProductBrand($postId, wp_unslash($_POST['product_brand']));
+ }
+ }
+
+ /**
+ * Set a product's brand to an existing brand, or clear it.
+ * Never creates a brand: the value must match an existing brand's slug or name.
+ *
+ * @param int $postId
+ * @param mixed $value Brand slug or name; '0' or 'not_specified' clears the brand
+ */
+ private function setProductBrand($postId, $value)
+ {
+ if (! is_scalar($value) || 'product' !== get_post_type($postId) || ! current_user_can('edit_post', $postId)) {
+ return;
+ }
+
+ $value = sanitize_text_field((string) $value);
+
+ if (in_array($value, array('', '0', 'not_specified'), true)) {
+ wp_set_object_terms($postId, array(), 'product_brand');
+
+ return;
+ }
+
+ $term = get_term_by('slug', $value, 'product_brand');
+
+ if (! $term) {
+ $term = get_term_by('name', $value, 'product_brand');
+ }
+
+ if ($term) {
+ wp_set_object_terms($postId, array((int) $term->term_id), 'product_brand');
}
}
@@ -357,18 +405,9 @@
$product_id = method_exists($product, 'get_id') ? $product->get_id() : $product->id;
- if (isset($_REQUEST['product_brand']) && $_REQUEST['product_brand'] != '') {
-
- // Delete term if brand is < Not specified > and set term or not
- if ($_REQUEST['product_brand'] == 'not_specified') {
-
- wp_set_post_terms($product_id, '', 'product_brand');
-
- } else {
-
- wp_set_post_terms($product_id, $_REQUEST['product_brand'], 'product_brand');
-
- }
+ // An empty value means "No change"; 'not_specified' clears the brand.
+ if (isset($_REQUEST['product_brand']) && '' !== $_REQUEST['product_brand']) {
+ $this->setProductBrand($product_id, wp_unslash($_REQUEST['product_brand']));
}
}
}
--- a/premmerce-woocommerce-brands/src/Frontend/Widgets/BrandsWidget.php
+++ b/premmerce-woocommerce-brands/src/Frontend/Widgets/BrandsWidget.php
@@ -81,11 +81,11 @@
*/
public function update($newInstance, $oldInstance)
{
- $values['title'] = sanitize_text_field($newInstance['title']);
- $values['only_photo'] = $newInstance['only_photo'];
- $values['limit'] = ((int)$newInstance['limit'] > 0)? intval($newInstance['limit']) : '';
- $values['selected'] = $newInstance['selected'];
- $values['mode'] = $newInstance['mode'];
+ $values['title'] = sanitize_text_field(isset($newInstance['title']) ? $newInstance['title'] : '');
+ $values['only_photo'] = ! empty($newInstance['only_photo']) ? 'on' : null;
+ $values['limit'] = (isset($newInstance['limit']) && (int)$newInstance['limit'] > 0)? intval($newInstance['limit']) : '';
+ $values['selected'] = (isset($newInstance['selected']) && is_array($newInstance['selected']))? array_map('absint', $newInstance['selected']) : array();
+ $values['mode'] = (isset($newInstance['mode']) && 'custom' === $newInstance['mode'])? 'custom' : 'auto';
return $values;
}
--- a/premmerce-woocommerce-brands/vendor/composer/installed.php
+++ b/premmerce-woocommerce-brands/vendor/composer/installed.php
@@ -1,9 +1,9 @@
<?php return array(
'root' => array(
'name' => 'premmerce/premmerce-woocommerce-brands',
- 'pretty_version' => '1.2.16',
- 'version' => '1.2.16.0',
- 'reference' => 'ba60a567bf944dfd5bbf5f6237542825d2dfdc11',
+ 'pretty_version' => '1.2.17',
+ 'version' => '1.2.17.0',
+ 'reference' => 'cf57d6ea2cd6fe519c24aaab7309f0bb381485c6',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -11,9 +11,9 @@
),
'versions' => array(
'premmerce/premmerce-woocommerce-brands' => array(
- 'pretty_version' => '1.2.16',
- 'version' => '1.2.16.0',
- 'reference' => 'ba60a567bf944dfd5bbf5f6237542825d2dfdc11',
+ 'pretty_version' => '1.2.17',
+ 'version' => '1.2.17.0',
+ 'reference' => 'cf57d6ea2cd6fe519c24aaab7309f0bb381485c6',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
--- a/premmerce-woocommerce-brands/views/admin/brands-bulk-edit.php
+++ b/premmerce-woocommerce-brands/views/admin/brands-bulk-edit.php
@@ -9,7 +9,7 @@
<option value="not_specified"> <?php _e( 'Not specified', 'premmerce-brands' ) ?> </option>
<?php foreach ($brands as $brand):?>
- <option value="<?= $brand->slug; ?>"><?= $brand->name; ?></option>
+ <option value="<?php echo esc_attr($brand->slug); ?>"><?php echo esc_html($brand->name); ?></option>
<?php endforeach; ?>
</select>
</span>
--- a/premmerce-woocommerce-brands/views/admin/brands-filter-select.php
+++ b/premmerce-woocommerce-brands/views/admin/brands-filter-select.php
@@ -3,10 +3,10 @@
<select name="product_brand" id="product_brand_select">
<option value=""> <?php _e('Filter by brand', 'premmerce-brands') ?> </option>
<?php foreach ($brands as $brand):?>
- <?php $filterGetParam = isset($_GET['product_brand'])?$_GET['product_brand']:''?>
+ <?php $filterGetParam = isset($_GET['product_brand']) ? sanitize_title(wp_unslash($_GET['product_brand'])) : ''?>
<?php $selected = selected( $filterGetParam, $brand->slug, false ); ?>
- <option value="<?= $brand->slug; ?>" <?=$selected; ?> ><?= $brand->name; ?></option>
+ <option value="<?php echo esc_attr($brand->slug); ?>" <?=$selected; ?> ><?php echo esc_html($brand->name); ?></option>
<?php endforeach; ?>
</select>
No newline at end of file
--- a/premmerce-woocommerce-brands/views/admin/brands-quick-edit.php
+++ b/premmerce-woocommerce-brands/views/admin/brands-quick-edit.php
@@ -7,7 +7,7 @@
<option value="0" selected><?php _e('Not specified', 'premmerce-brands'); ?></option>
<?php foreach ($brands as $brand) : ?>
- <option value="<?= $brand->slug; ?>"><?= $brand->name; ?></option>
+ <option value="<?php echo esc_attr($brand->slug); ?>"><?php echo esc_html($brand->name); ?></option>
<?php endforeach; ?>
</select>
</div>
--- a/premmerce-woocommerce-brands/views/admin/brands-select.php
+++ b/premmerce-woocommerce-brands/views/admin/brands-select.php
@@ -5,7 +5,7 @@
<option value="0"><?php _e('Not specified', 'premmerce-brands'); ?></option>
<?php foreach ($terms as $term) : ?>
- <option value="<?php esc_attr_e($term->name); ?>" <?php selected($term->name, $name); ?>><?php esc_html_e($term->name); ?></option>
+ <option value="<?php echo esc_attr($term->name); ?>" <?php selected($term->name, $name); ?>><?php echo esc_html($term->name); ?></option>
<?php endforeach ?>
</select>
</div>
No newline at end of file
--- a/premmerce-woocommerce-brands/views/admin/brands-widget-form.php
+++ b/premmerce-woocommerce-brands/views/admin/brands-widget-form.php
@@ -1,38 +1,38 @@
<?php if ( ! defined( 'WPINC' ) ) die; ?>
<p>
- <label for="<?= $widget->get_field_id('title') ?>"><?php _e('Title'); ?></label>
- <input id="<?= $widget->get_field_id('title'); ?>" class="widefat" type="text" name="<?=
- $widget->get_field_name('title'); ?>" value="<?= $title; ?>">
+ <label for="<?php echo esc_attr($widget->get_field_id('title')); ?>"><?php _e('Title'); ?></label>
+ <input id="<?php echo esc_attr($widget->get_field_id('title')); ?>" class="widefat" type="text" name="<?php echo
+ esc_attr($widget->get_field_name('title')); ?>" value="<?php echo esc_attr($title); ?>">
</p>
<p>
- <label for="<?= $widget->get_field_id('mode') ?>"><?php _e('Mode', 'premmerce-brands'); ?></label>
- <select id="<?= $widget->get_field_id('mode') ?>" name="<?=
- $widget->get_field_name('mode'); ?>" class="widefat premmerce-carousel-select">
+ <label for="<?php echo esc_attr($widget->get_field_id('mode')); ?>"><?php _e('Mode', 'premmerce-brands'); ?></label>
+ <select id="<?php echo esc_attr($widget->get_field_id('mode')); ?>" name="<?php echo
+ esc_attr($widget->get_field_name('mode')); ?>" class="widefat premmerce-carousel-select">
<option value="auto" <?php selected(($mode == 'auto') ? 1 : 0); ?>><?php _e('Auto', 'premmerce-brands'); ?></option>
<option value="custom" <?php selected(($mode == 'custom') ? 1 : 0); ?>><?php _e('Custom', 'premmerce-brands'); ?></option>
</select>
</p>
<div data-select="premmerce-filter-auto" <?= ($mode == 'auto') ?: 'style="display: none"'; ?>>
<p>
- <input id="<?= $widget->get_field_id('only_photo') ?>" type="checkbox" <?php checked($onlyPhoto ? 1 : 0); ?> name="<?=
- $widget->get_field_name('only_photo'); ?>">
- <label for="<?= $widget->get_field_id('only_photo'); ?>"><?php _e('Only with photo', 'premmerce-brands'); ?></label>
+ <input id="<?php echo esc_attr($widget->get_field_id('only_photo')); ?>" type="checkbox" <?php checked($onlyPhoto ? 1 : 0); ?> name="<?php echo
+ esc_attr($widget->get_field_name('only_photo')); ?>">
+ <label for="<?php echo esc_attr($widget->get_field_id('only_photo')); ?>"><?php _e('Only with photo', 'premmerce-brands'); ?></label>
</p>
<p>
- <label for="<?= $widget->get_field_id('limit') ?>"><?php _e('Limit', 'premmerce-brands'); ?></label>
- <input id="<?= $widget->get_field_id('limit'); ?>" class="tiny-text" type="number" min="0" name="<?=
- $widget->get_field_name('limit'); ?>" value="<?= $limit; ?>">
+ <label for="<?php echo esc_attr($widget->get_field_id('limit')); ?>"><?php _e('Limit', 'premmerce-brands'); ?></label>
+ <input id="<?php echo esc_attr($widget->get_field_id('limit')); ?>" class="tiny-text" type="number" min="0" name="<?php echo
+ esc_attr($widget->get_field_name('limit')); ?>" value="<?php echo esc_attr($limit); ?>">
</p>
</div>
<div data-select="premmerce-filter-custom" <?= ($mode == 'custom') ?: 'style="display: none"'; ?>>
<p>
- <label for="<?= $widget->get_field_id('selected[]') ?>"><?php _e('Selected', 'premmerce-brands'); ?></label>
- <select style="width: 100%;" data-select="brands" id="<?= $widget->get_field_id('selected[]'); ?>" name="<?=
- $widget->get_field_name('selected[]'); ?>" multiple>
+ <label for="<?php echo esc_attr($widget->get_field_id('selected[]')); ?>"><?php _e('Selected', 'premmerce-brands'); ?></label>
+ <select style="width: 100%;" data-select="brands" id="<?php echo esc_attr($widget->get_field_id('selected[]')); ?>" name="<?php echo
+ esc_attr($widget->get_field_name('selected[]')); ?>" multiple>
<?php foreach ($brands as $brand) : ?>
- <option value="<?= $brand->term_id; ?>" <?php selected(in_array($brand->term_id, $selected) ? 1 : 0); ?>><?= $brand->name; ?></option>
+ <option value="<?php echo esc_attr($brand->term_id); ?>" <?php selected(in_array($brand->term_id, $selected) ? 1 : 0); ?>><?php echo esc_html($brand->name); ?></option>
<?php endforeach; ?>
</select>
--- a/premmerce-woocommerce-brands/views/admin/edit-brands-fields.php
+++ b/premmerce-woocommerce-brands/views/admin/edit-brands-fields.php
@@ -5,7 +5,7 @@
<td>
<div data-type="brands_thumbnail" class="brands_thumbnail"><img width="60" height="60" src="<?= esc_url($image); ?>"/></div>
<div class="brands_thumbnail_buttons">
- <input type="hidden" data-type="brands_thumbnail_id" name="brands_thumbnail_id" value="<?= $thumbnailId; ?>"/>
+ <input type="hidden" data-type="brands_thumbnail_id" name="brands_thumbnail_id" value="<?php echo esc_attr($thumbnailId); ?>"/>
<button type="button" data-type="upload_image" class="upload_image_button button"><?php _e('Upload/Add image', 'woocommerce'); ?></button>
<button type="button" data-type="remove_image" class="remove_image_button button"><?php _e('Remove image', 'woocommerce'); ?></button>
</div>
--- a/premmerce-woocommerce-brands/views/frontend/brands-meta.php
+++ b/premmerce-woocommerce-brands/views/frontend/brands-meta.php
@@ -3,5 +3,5 @@
<span class="product-brand tagged_as">
<?php _e('Brand', 'premmerce-brands'); ?>:
- <a href="<?= get_term_link($brand->slug, 'product_brand'); ?>"><?= $brand->name; ?></a>
+ <a href="<?php echo esc_url(get_term_link($brand)); ?>"><?php echo esc_html($brand->name); ?></a>
</span>
No newline at end of file
--- a/premmerce-woocommerce-brands/views/frontend/brands-page.php
+++ b/premmerce-woocommerce-brands/views/frontend/brands-page.php
@@ -7,15 +7,15 @@
$imageURL = $imageURL ?: plugins_url('../../assets/frontend/img/placeholder.png', __FILE__);
?>
<div class="prm-brands-list__col">
- <a class="prm-brands-list__item" href="<?= get_term_link($brand->slug, 'product_brand'); ?>">
+ <a class="prm-brands-list__item" href="<?php echo esc_url(get_term_link($brand)); ?>">
<div class="prm-brands-list__image">
- <img src="<?= $imageURL; ?>" alt="<?= $brand->name; ?>">
+ <img src="<?php echo esc_url($imageURL); ?>" alt="<?php echo esc_attr($brand->name); ?>">
</div>
- <div class="prm-brands-list__title"><?= $brand->name; ?></div>
+ <div class="prm-brands-list__title"><?php echo esc_html($brand->name); ?></div>
</a>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="woocommerce-info"><?php _e('No brands ware found.', 'premmerce-brands'); ?></p>
-<?php endif;?>
No newline at end of file
+<?php endif;?>
--- a/premmerce-woocommerce-brands/views/frontend/brands-widget.php
+++ b/premmerce-woocommerce-brands/views/frontend/brands-widget.php
@@ -3,18 +3,18 @@
<?= $args['before_widget']; ?>
<?php if ($title) : ?>
- <?= $args['before_title'] . $title . $args['after_title']; ?>
+ <?= $args['before_title'] . esc_html($title) . $args['after_title']; ?>
<?php endif ?>
<div class="prm-brands-widget">
<?php foreach ($brands as $brand) : ?>
- <a class="prm-brands-widget__item" href="<?= get_term_link($brand->slug, 'product_brand'); ?>">
+ <a class="prm-brands-widget__item" href="<?php echo esc_url(get_term_link($brand)); ?>">
<?php if ($imageURL = wp_get_attachment_image_url(get_term_meta($brand->term_id, 'thumbnail_id', true), 'thumbnail')) : ?>
- <img class="prm-brands-widget__image" src="<?= $imageURL; ?>">
+ <img class="prm-brands-widget__image" src="<?php echo esc_url($imageURL); ?>">
<?php endif ?>
<div class="prm-brands-widget__title">
- <?= $brand->name ?>
+ <?php echo esc_html($brand->name); ?>
</div>
</a>
<?php endforeach ?>