Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/pdf-for-woocommerce/frontend/index.php
+++ b/pdf-for-woocommerce/frontend/index.php
@@ -69,6 +69,31 @@
$result = str_replace('"', "'", $result);
return $result;
}
+ /**
+ * Remove mPDF's internal object marker (Mpdf::OBJECT_IDENTIFIER, the bytes BB A4 AC,
+ * i.e. the characters U+00BB U+00A4 U+00AC) from HTML before it reaches mPDF.
+ *
+ * mPDF treats text that starts with this marker as a serialized internal object
+ * ("type=...,objattr=..."). It must never come from document content: a customer
+ * value written as the characters or as entities (»¤¬, »...)
+ * turns back into the raw marker once mPDF decodes entities and, for core fonts,
+ * converts UTF-8 to cp1252. Template HTML never legitimately contains this
+ * three-character sequence.
+ */
+ public static function strip_mpdf_object_marker($html)
+ {
+ $html = (string) $html;
+ $amp = '&(?:amp;)*';
+ $c1 = '(?:xC2xBB|xBB|' . $amp . '(?:raquo|#0*187|#x0*bb);)';
+ $c2 = '(?:xC2xA4|xA4|' . $amp . '(?:curren|#0*164|#x0*a4);)';
+ $c3 = '(?:xC2xAC|xAC|' . $amp . '(?:not|#0*172|#x0*ac);)';
+ $pattern = '/' . $c1 . $c2 . $c3 . '/i';
+ do {
+ $previous = $html;
+ $html = preg_replace($pattern, '', $html);
+ } while ($html !== null && $html !== $previous);
+ return $html === null ? '' : $html;
+ }
function load_custom_template_woo()
{
add_filter('template_include', array($this, 'template_include'), 99);
@@ -375,6 +400,8 @@
}
// QR code / barcode shortcodes return a "data---image" placeholder; resolve it for every output type (download, upload, preview).
$html = str_replace("data---image", "data:image", $html);
+ // Security: never let document HTML carry mPDF's internal object marker.
+ $html = self::strip_mpdf_object_marker($html);
switch ($data_attrs["type"]) {
case "download":
$mpdf->WriteHTML($html);
--- a/pdf-for-woocommerce/libs/HtmlDocument.php
+++ b/pdf-for-woocommerce/libs/HtmlDocument.php
@@ -302,6 +302,21 @@
ENT_QUOTES | ENT_HTML5,
$this->_target_charset
);
+ // Security: makeup()/outertext print text nodes as-is, so decoded text such as
+ // "<img src=...>" from customer data would come back out as a live tag
+ // (and mPDF markup) when the document is serialized again. Re-encode the HTML
+ // special characters of real text nodes; what is displayed stays the same.
+ // Comments/CDATA and <style>/<script> contents are left untouched.
+ if ($node->nodetype === HtmlNode::HDOM_TYPE_TEXT
+ && !($node->parent && in_array(strtolower((string) $node->parent->tag), array('style', 'script'), true))
+ ) {
+ $node->_[HtmlNode::HDOM_INFO_TEXT] = htmlspecialchars(
+ $node->_[HtmlNode::HDOM_INFO_TEXT],
+ ENT_NOQUOTES | ENT_SUBSTITUTE,
+ $this->_target_charset,
+ true
+ );
+ }
}
if (isset($node->_[HtmlNode::HDOM_INFO_INNER])) {
$node->_[HtmlNode::HDOM_INFO_INNER] = html_entity_decode(
@@ -309,6 +324,19 @@
ENT_QUOTES | ENT_HTML5,
$this->_target_charset
);
+ // Security: for an element, INNER holds the text right after its opening tag
+ // and is printed as-is, exactly like a text node. Re-encode it the same way
+ // (not for comments, CDATA, <style> or <script>, whose content is raw).
+ if ($node->nodetype === HtmlNode::HDOM_TYPE_ELEMENT
+ && !in_array(strtolower((string) $node->tag), array('style', 'script'), true)
+ ) {
+ $node->_[HtmlNode::HDOM_INFO_INNER] = htmlspecialchars(
+ $node->_[HtmlNode::HDOM_INFO_INNER],
+ ENT_NOQUOTES | ENT_SUBSTITUTE,
+ $this->_target_charset,
+ true
+ );
+ }
}
if (isset($node->attr) && is_array($node->attr)) {
foreach ($node->attr as $a => $v) {
--- a/pdf-for-woocommerce/pdf-for-woocommerce.php
+++ b/pdf-for-woocommerce/pdf-for-woocommerce.php
@@ -4,7 +4,7 @@
* Plugin Name: PDF Invoice for WooCommerce + Drag and Drop Template Builder
* Requires Plugins: woocommerce
* Description: WooCommerce PDF Customizer is a helpful tool that helps you build and customize the PDF Templates for WooCommerce.
- * Version: 7.2.0
+ * Version: 7.2.1
* Requires PHP: 7.0
* Author: add-ons.org
* Tested up to: 7.1
--- a/pdf-for-woocommerce/preview.php
+++ b/pdf-for-woocommerce/preview.php
@@ -1,40 +1,70 @@
-<?php
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-if( isset($_GET['id'])) {
- $id_template = sanitize_text_field( $_GET['id'] );
- $type = "preview";
- if( isset($_GET["download"]) ){
- $type = "download";
- }
- if( isset($_GET["html"]) ){
- $type = "html";
- }
- $name ="pdf_name";
- if( isset($_GET["pdf_name"]) ){
- $name = sanitize_text_field($_GET["pdf_name"]);
- $name = urldecode($name);
- $name = sanitize_file_name($name);
- }
- $user = wp_get_current_user();
- $allowed_roles = array('editor', 'administrator', 'author',"shop_manager");
- $check = false;
- if ( isset( $_REQUEST['_wpnonce']) && wp_verify_nonce( $_REQUEST['_wpnonce'], 'yeepdf' ) ) {
- $check = true;
- }
- if( array_intersect($allowed_roles, $user->roles ) ) {
- $check = true;
- }
- if( $check ){
- $order_id = "";
- if( isset($_GET["woo_order"]) ) {
- $order_id = sanitize_text_field( $_GET['woo_order'] );
- }
- $data_send_settings = array(
- "id_template"=> $id_template,
- "type"=> $type,
- "woo_order_id" =>$order_id,
- "name" => $name
- );
- Yeepdf_Create_PDF::pdf_creator_preview($data_send_settings);
- }
+<?php
+if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
+if( isset($_GET['id'])) {
+ $id_template = sanitize_text_field( $_GET['id'] );
+ $type = "preview";
+ if( isset($_GET["download"]) ){
+ $type = "download";
+ }
+ if( isset($_GET["html"]) ){
+ $type = "html";
+ }
+ $name ="pdf_name";
+ if( isset($_GET["pdf_name"]) ){
+ $name = sanitize_text_field($_GET["pdf_name"]);
+ $name = urldecode($name);
+ $name = sanitize_file_name($name);
+ }
+ $order_id = "";
+ $order_ids = array();
+ if( isset($_GET["woo_order"]) ) {
+ $order_ids = array_values(array_filter(array_map('absint', explode(',', sanitize_text_field(wp_unslash($_GET['woo_order']))))));
+ $order_id = implode(',', $order_ids);
+ }
+ $can_manage_orders = current_user_can('edit_shop_orders') || current_user_can('manage_woocommerce');
+ $check = false;
+ if ( $can_manage_orders ) {
+ $check = true;
+ } elseif ( !empty($order_ids) ) {
+ // Order data: only the customer's own order(s), or one order opened with its order key
+ // (guest checkout / email links). A shared nonce is not tied to an order, so it is not enough.
+ $order_key = isset($_GET['key']) ? sanitize_text_field(wp_unslash($_GET['key'])) : '';
+ $user_id = get_current_user_id();
+ $check = function_exists('wc_get_order');
+ foreach ( $order_ids as $check_order_id ) {
+ $check_order = $check ? wc_get_order($check_order_id) : false;
+ $is_owner = $check_order && $user_id && (int) $check_order->get_customer_id() === $user_id;
+ $has_key = $check_order && count($order_ids) === 1 && $order_key !== '' && hash_equals((string) $check_order->get_order_key(), $order_key);
+ if ( !$is_owner && !$has_key ) {
+ $check = false;
+ break;
+ }
+ }
+ // The raw HTML view is for shop managers only.
+ if ( $type == "html" ) {
+ $check = false;
+ }
+ } else {
+ // Template preview with sample data (no order).
+ if ( isset( $_REQUEST['_wpnonce']) && wp_verify_nonce( sanitize_text_field(wp_unslash($_REQUEST['_wpnonce'])), 'yeepdf' ) ) {
+ $check = true;
+ }
+ if ( current_user_can('edit_posts') ) {
+ $check = true;
+ }
+ }
+ if ( !$check && !empty($order_ids) ) {
+ status_header(403);
+ nocache_headers();
+ wp_die(esc_html__('You are not allowed to view this document.', 'pdf-for-woocommerce'), '', array('response' => 403));
+ }
+ if( $check ){
+ $data_send_settings = array(
+ "id_template"=> $id_template,
+ "type"=> $type,
+ "woo_order_id" =>$order_id,
+ "name" => $name
+ );
+ Yeepdf_Create_PDF::pdf_creator_preview($data_send_settings);
+ }
}
No newline at end of file
--- a/pdf-for-woocommerce/vendor/mpdf/mpdf/src/Mpdf.php
+++ b/pdf-for-woocommerce/vendor/mpdf/mpdf/src/Mpdf.php
@@ -9102,7 +9102,12 @@
$sp[$v[0]] = trim($v[1], Mpdf::OBJECT_IDENTIFIER);
}
- return (unserialize($sp['objattr']));
+ // Security: objattr is always a plain array written by mPDF itself (see the
+ // serialize() calls for type=image/listmarker/textarea/...). Forbidding classes
+ // turns any injected serialized object into __PHP_Incomplete_Class, so a crafted
+ // value reaching this point (e.g. via user-controlled HTML) cannot build a POP
+ // gadget chain. Hardens against the object-injection file-deletion report.
+ return (unserialize($sp['objattr'], array('allowed_classes' => false)));
}
function inlineObject($type, $x, $y, $objattr, $Lmargin, $widthUsed, $maxWidth, $lineHeight, $paint = false, $is_table = false)
@@ -13637,7 +13642,8 @@
$this->OTLdata = [];
} // TEXTAREA
else {
- $objattr = unserialize($this->specialcontent);
+ // Security: specialcontent is always an array serialized by TagTextArea.
+ $objattr = unserialize($this->specialcontent, array('allowed_classes' => false));
$objattr['text'] = $e;
$objattr['OTLdata'] = $this->OTLdata;
$this->OTLdata = [];
--- a/pdf-for-woocommerce/woocommerce/emails/index.php
+++ b/pdf-for-woocommerce/woocommerce/emails/index.php
@@ -237,7 +237,10 @@
$name = do_shortcode($name);
$name = urlencode($name);
$password = urlencode($password);
- $link_download = add_query_arg(array("pdf_preview" => "preview", "id" => $data["template_id"], "download" => "1", "woo_order" => $order_id, "pdf_name" => $name, "pdf_password" => $password), $link_download_home);
+ $link_args = array("pdf_preview" => "preview", "id" => $data["template_id"], "download" => "1", "woo_order" => $order_id, "pdf_name" => $name, "pdf_password" => $password);
+ // The order key ties the link to this one order (guests and email recipients).
+ $link_args["key"] = $order->get_order_key();
+ $link_download = add_query_arg($link_args, $link_download_home);
$link_download_pdf = wp_nonce_url($link_download, "yeepdf");
$link_download_pdfs[$data["id"]] = array("link" => $link_download_pdf, "label" => $data["label"], "date" => wp_date(get_option('date_format')));
}
--- a/pdf-for-woocommerce/woocommerce/shortcodes.php
+++ b/pdf-for-woocommerce/woocommerce/shortcodes.php
@@ -527,7 +527,7 @@
break;
case 'yeepdf_woo_billing_address':
if (isset($order) && $order != null) {
- return $order->get_formatted_billing_address();
+ return self::escape_pdf_address($order->get_formatted_billing_address());
} else {
return self::order_billing();
}
@@ -975,7 +975,7 @@
$address = $order->get_formatted_billing_address();
?>
<div class="address">
- <?php echo wp_kses_post($address ? $address : esc_html__('N/A', 'woocommerce')); //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
+ <?php echo self::escape_pdf_address($address ? $address : esc_html__('N/A', 'woocommerce')); //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
?>
<?php if ($order->get_billing_phone()) : ?>
<br /><?php echo wc_make_phone_clickable($order->get_billing_phone()); // phpcs:ignore WordPress.Security.EscapeOutput
@@ -1016,7 +1016,7 @@
if (! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && $shipping) :
?>
<div class="address">
- <?php echo wp_kses_post($shipping); ?>
+ <?php echo self::escape_pdf_address($shipping); ?>
<?php if ($order->get_shipping_phone()) : ?>
<br /><?php echo wc_make_phone_clickable($order->get_shipping_phone()); // phpcs:ignore WordPress.Security.EscapeOutput
?>
@@ -1051,11 +1051,34 @@
$previous = $note;
$note = html_entity_decode($note, ENT_QUOTES | ENT_HTML5, 'UTF-8');
$note = wp_strip_all_tags($note);
+ // The marker also forms again from its UTF-8 characters (core-font cp1252 conversion).
+ $note = str_replace(array("xbbxa4xac", "xc2xbbxc2xa4xc2xac"), '', $note);
// Repeat because removing markup can expose another entity or tag.
} while ($note !== $previous);
return nl2br(esc_html($note));
}
+ /**
+ * Render a WooCommerce formatted address (billing/shipping) safely for the PDF.
+ *
+ * A formatted address is user-controlled text (first name, company, address…)
+ * where the only legitimate markup WooCommerce adds is <br/> between lines.
+ * Each line is neutralised like a note so an encoded mPDF object marker in, e.g.,
+ * the billing first name cannot be re-materialised by the builder's entity-decoding
+ * pass, while the line breaks are preserved.
+ */
+ public static function escape_pdf_address($address)
+ {
+ $parts = preg_split('/<brs*/?>/i', (string) $address);
+ $clean = array();
+ foreach ($parts as $part) {
+ $part = self::escape_pdf_note($part);
+ if ($part !== '') {
+ $clean[] = $part;
+ }
+ }
+ return implode('<br/>', $clean);
+ }
public static function customer_notes($notes)
{
ob_start();
--- a/pdf-for-woocommerce/woocommerce/templates/emails/address-billing.php
+++ b/pdf-for-woocommerce/woocommerce/templates/emails/address-billing.php
@@ -1,18 +1,18 @@
-<?php
-if (! defined('ABSPATH')) {
- exit;
-}
-$text_align = is_rtl() ? 'right' : 'left';
-$address = $order->get_formatted_billing_address();
-?>
-<address class="address">
- <?php echo wp_kses_post($address ? $address : esc_html__('N/A', "woocommerce")); //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
- ?>
- <?php if ($order->get_billing_phone()) : ?>
- <br /><?php echo wc_make_phone_clickable($order->get_billing_phone()); // phpcs:ignore WordPress.Security.EscapeOutput
- ?>
- <?php endif; ?>
- <?php if ($order->get_billing_email()) : ?>
- <br /><?php echo esc_html($order->get_billing_email()); ?>
- <?php endif; ?>
+<?php
+if (! defined('ABSPATH')) {
+ exit;
+}
+$text_align = is_rtl() ? 'right' : 'left';
+$address = $order->get_formatted_billing_address();
+?>
+<address class="address">
+ <?php echo Yeepdf_Addons_Woocommerce_Shortcodes::escape_pdf_address($address ? $address : esc_html__('N/A', "woocommerce")); //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
+ ?>
+ <?php if ($order->get_billing_phone()) : ?>
+ <br /><?php echo wc_make_phone_clickable($order->get_billing_phone()); // phpcs:ignore WordPress.Security.EscapeOutput
+ ?>
+ <?php endif; ?>
+ <?php if ($order->get_billing_email()) : ?>
+ <br /><?php echo esc_html($order->get_billing_email()); ?>
+ <?php endif; ?>
</address>
No newline at end of file
--- a/pdf-for-woocommerce/woocommerce/templates/emails/address-shipping.php
+++ b/pdf-for-woocommerce/woocommerce/templates/emails/address-shipping.php
@@ -1,11 +1,11 @@
-<?php
-if (! defined('ABSPATH')) {
- exit;
-}
-$text_align = is_rtl() ? 'right' : 'left';
-$shipping = $order->get_formatted_shipping_address();
-if ($shipping == "") {
- $shipping = esc_html__("No shipping address set.", "woocommerce"); //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
-}
-?>
-<address class="address"><?php echo wp_kses_post($shipping); ?></address>
No newline at end of file
+<?php
+if (! defined('ABSPATH')) {
+ exit;
+}
+$text_align = is_rtl() ? 'right' : 'left';
+$shipping = $order->get_formatted_shipping_address();
+if ($shipping == "") {
+ $shipping = esc_html__("No shipping address set.", "woocommerce"); //phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
+}
+?>
+<address class="address"><?php echo Yeepdf_Addons_Woocommerce_Shortcodes::escape_pdf_address($shipping); ?></address>
No newline at end of file
--- a/pdf-for-woocommerce/woocommerce/templates/emails/email-addresses.php
+++ b/pdf-for-woocommerce/woocommerce/templates/emails/email-addresses.php
@@ -1,52 +1,52 @@
-<?php
-
-/**
- * Email Addresses
- *
- * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-addresses.php.
- *
- * HOWEVER, on occasion WooCommerce will need to update template files and you
- * (the theme developer) will need to copy the new files to your theme to
- * maintain compatibility. We try to do this as little as possible, but it does
- * happen. When this occurs the version of the template file will be bumped and
- * the readme will list any important changes.
- *
- * @see https://docs.woocommerce.com/document/template-structure/
- * @package WooCommerce/Templates/Emails
- * @version 3.9.0
- */
-
-if (! defined('ABSPATH')) {
- exit;
-}
-//phpcs:disable WordPress.WP.I18n.TextDomainMismatch
-$text_align = is_rtl() ? 'right' : 'left';
-$address = $order->get_formatted_billing_address();
-$shipping = $order->get_formatted_shipping_address();
-
-?><table class="yeemail-woocommerce-style" cellspacing="0" cellpadding="0" style="vertical-align: top; background-color: #FFF;padding: 15px 30px;font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; " border="0">
- <tr>
- <td style="" valign="top" width="50%">
- <h2><?php esc_html_e('Billing address', "woocommerce"); ?></h2>
- <address class="address">
- <?php echo wp_kses_post($address ? $address : esc_html__('N/A', "woocommerce")); ?>
- <?php if ($order->get_billing_phone()) : ?>
- <br /><?php echo wc_make_phone_clickable($order->get_billing_phone()); // phpcs:ignore WordPress.Security.EscapeOutput
- ?>
- <?php endif; ?>
- <?php if ($order->get_billing_email()) : ?>
- <br /><?php echo esc_html($order->get_billing_email()); ?>
- <?php endif; ?>
- </address>
- </td>
- <?php if (! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && $shipping) : ?>
- <td style="" valign="top" width="50%">
- <h2><?php esc_html_e('Shipping address', "woocommerce"); ?></h2>
-
- <address class="address"><?php echo wp_kses_post($shipping); ?></address>
- </td>
- <?php endif; ?>
- </tr>
-</table>
-<?php //phpcs:enable WordPress.WP.I18n.TextDomainMismatch
+<?php
+
+/**
+ * Email Addresses
+ *
+ * This template can be overridden by copying it to yourtheme/woocommerce/emails/email-addresses.php.
+ *
+ * HOWEVER, on occasion WooCommerce will need to update template files and you
+ * (the theme developer) will need to copy the new files to your theme to
+ * maintain compatibility. We try to do this as little as possible, but it does
+ * happen. When this occurs the version of the template file will be bumped and
+ * the readme will list any important changes.
+ *
+ * @see https://docs.woocommerce.com/document/template-structure/
+ * @package WooCommerce/Templates/Emails
+ * @version 3.9.0
+ */
+
+if (! defined('ABSPATH')) {
+ exit;
+}
+//phpcs:disable WordPress.WP.I18n.TextDomainMismatch
+$text_align = is_rtl() ? 'right' : 'left';
+$address = $order->get_formatted_billing_address();
+$shipping = $order->get_formatted_shipping_address();
+
+?><table class="yeemail-woocommerce-style" cellspacing="0" cellpadding="0" style="vertical-align: top; background-color: #FFF;padding: 15px 30px;font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif; " border="0">
+ <tr>
+ <td style="" valign="top" width="50%">
+ <h2><?php esc_html_e('Billing address', "woocommerce"); ?></h2>
+ <address class="address">
+ <?php echo Yeepdf_Addons_Woocommerce_Shortcodes::escape_pdf_address($address ? $address : esc_html__('N/A', "woocommerce")); ?>
+ <?php if ($order->get_billing_phone()) : ?>
+ <br /><?php echo wc_make_phone_clickable($order->get_billing_phone()); // phpcs:ignore WordPress.Security.EscapeOutput
+ ?>
+ <?php endif; ?>
+ <?php if ($order->get_billing_email()) : ?>
+ <br /><?php echo esc_html($order->get_billing_email()); ?>
+ <?php endif; ?>
+ </address>
+ </td>
+ <?php if (! wc_ship_to_billing_address_only() && $order->needs_shipping_address() && $shipping) : ?>
+ <td style="" valign="top" width="50%">
+ <h2><?php esc_html_e('Shipping address', "woocommerce"); ?></h2>
+
+ <address class="address"><?php echo Yeepdf_Addons_Woocommerce_Shortcodes::escape_pdf_address($shipping); ?></address>
+ </td>
+ <?php endif; ?>
+ </tr>
+</table>
+<?php //phpcs:enable WordPress.WP.I18n.TextDomainMismatch
?>
No newline at end of file