Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/coupon-creator/coupon_creator.php
+++ b/coupon-creator/coupon_creator.php
@@ -3,7 +3,7 @@
Plugin Name: Coupon Creator
Plugin URI: https://artifexrouting.com/wordpress-plugins/coupon-creator/
Description: Designed, printable coupons for WordPress. Put a real coupon on your site.
-Version: 3.6.5
+Version: 3.6.6
Author: Artifex Routing Co
Author URI: https://artifexrouting.com
Text Domain: coupon-creator
--- a/coupon-creator/plugin-engine/src/Pngx/Admin/Ajax.php
+++ b/coupon-creator/plugin-engine/src/Pngx/Admin/Ajax.php
@@ -234,6 +234,22 @@
$post_id = absint( $_POST['post_id'] );
+ /*
+ * The nonce proves intent, not permission. An existing post needs edit_post.
+ * A new post is saved as published, so it needs publish_posts on its type.
+ * Protected (underscore and cctor_) keys are never written from here.
+ */
+ $post_type_object = get_post_type_object( sanitize_key( wp_unslash( $_POST['post_type'] ) ) );
+ if ( $post_id ) {
+ $can_save = current_user_can( 'edit_post', $post_id );
+ } else {
+ $can_save = $post_type_object && current_user_can( $post_type_object->cap->publish_posts );
+ }
+
+ if ( ! $can_save || is_protected_meta( (string) wp_unslash( $_POST['field_name'] ), 'post' ) ) {
+ wp_send_json_error( __( 'Permission Error has occurred. Please save, reload, and try again.', 'plugin-engine' ) );
+ }
+
if ( empty( $post_id ) || ! empty( $_POST['title_field'] ) ) {
$menu_item = array(
--- a/coupon-creator/plugin-engine/src/Pngx/Allowed_Tags.php
+++ b/coupon-creator/plugin-engine/src/Pngx/Allowed_Tags.php
@@ -8,10 +8,39 @@
/**
* Allowed Tags in Fields
*
- * Used with strip_tags();
+ * Used with kses();
*/
class Pngx__Allowed_Tags {
+ /**
+ * Filters HTML down to an allowed-tags string such as `<p><img><a>`.
+ *
+ * Replaces strip_tags( $content, $tags ): strip_tags keeps every attribute
+ * on an allowed tag, so `<img onerror=...>` got through. This keeps the same
+ * tags, with the attributes and URL protocols wp_kses_post() allows for each
+ * one. A tag outside that list, such as `<style>`, is kept with no attributes.
+ *
+ * @since 4.0.12
+ *
+ * @param mixed $content HTML to filter.
+ * @param mixed $tags Allowed tags, as a string of `<tag>` names.
+ *
+ * @return string
+ */
+ public static function kses( $content, $tags ) {
+ $post_tags = wp_kses_allowed_html( 'post' );
+ $allowed = array();
+
+ preg_match_all( '/<([a-z][a-z0-9]*)>/i', is_string( $tags ) ? $tags : '', $matches );
+
+ foreach ( $matches[1] as $tag ) {
+ $tag = strtolower( $tag );
+ $allowed[ $tag ] = isset( $post_tags[ $tag ] ) ? $post_tags[ $tag ] : array();
+ }
+
+ return wp_kses( (string) $content, $allowed );
+ }
+
/*
* Allowed Tags for content without links support
*/
--- a/coupon-creator/plugin-engine/src/Pngx/Field/Content.php
+++ b/coupon-creator/plugin-engine/src/Pngx/Field/Content.php
@@ -52,7 +52,7 @@
?>
<div class="pngx-content <?php echo esc_attr( $class ); ?>" <?php echo wp_strip_all_tags( $style ); ?>>
- <?php echo strip_tags( $meta, apply_filters( 'pngx_filter_content_allowed_tags', Pngx__Allowed_Tags::$tags() ) ); ?>
+ <?php echo Pngx__Allowed_Tags::kses( $meta, apply_filters( 'pngx_filter_content_allowed_tags', Pngx__Allowed_Tags::$tags() ) ); ?>
</div>
<?php
}
--- a/coupon-creator/plugin-engine/src/Pngx/Field/Image.php
+++ b/coupon-creator/plugin-engine/src/Pngx/Field/Image.php
@@ -32,7 +32,7 @@
if ( $image_src ) {
?>
<div class="pngx-image <?php echo esc_attr( $class ); ?>" <?php echo wp_strip_all_tags( $style ); ?>>
- <img src='<?php echo esc_url( $image_src ); ?>' alt='<?php echo get_the_title(); ?>' title='<?php echo get_the_title(); ?>'>
+ <img src='<?php echo esc_url( $image_src ); ?>' alt='<?php echo esc_attr( get_the_title() ); ?>' title='<?php echo esc_attr( get_the_title() ); ?>'>
</div>
<?php
}
--- a/coupon-creator/plugin-engine/src/Pngx/Field/Title.php
+++ b/coupon-creator/plugin-engine/src/Pngx/Field/Title.php
@@ -32,7 +32,7 @@
<?php echo $wrap ? '<' . esc_attr( $wrap ) . ' class="' . esc_attr( $class ) . '" ' . wp_strip_all_tags( $style ) . '>' : ''; ?>
- <?php echo strip_tags( $meta, Pngx__Allowed_Tags::$tags() ); ?>
+ <?php echo Pngx__Allowed_Tags::kses( $meta, Pngx__Allowed_Tags::$tags() ); ?>
<?php echo $wrap ? '</' . esc_attr( $wrap ) . '>' : ''; ?>
--- a/coupon-creator/plugin-engine/src/Pngx/Main.php
+++ b/coupon-creator/plugin-engine/src/Pngx/Main.php
@@ -11,7 +11,7 @@
*
* @var string
*/
- const VERSION = '4.0.11';
+ const VERSION = '4.0.12';
/**
* Stores the slug for the plugin engine.
--- a/coupon-creator/plugin-engine/src/Pngx/Style/Linked.php
+++ b/coupon-creator/plugin-engine/src/Pngx/Style/Linked.php
@@ -31,15 +31,15 @@
foreach ( $field['styles'] as $type => $field_name ) {
if ( 'font-color' === $type && $color = get_post_meta( $post_id, $field_name, true ) ) {
- $style .= 'color:' . $color . '; ';
+ $style .= 'color:' . self::css_value( $color ) . '; ';
}
if ( 'background-color' === $type && $color = get_post_meta( $post_id, $field_name, true ) ) {
- $style .= 'background-color:' . $color . '; ';
+ $style .= 'background-color:' . self::css_value( $color ) . '; ';
}
if ( 'background-color:hover' === $type && $color = get_post_meta( $post_id, $field_name, true ) ) {
- $style .= 'background-color:hover ' . $color . '; ';
+ $style .= 'background-color:hover ' . self::css_value( $color ) . '; ';
}
}
@@ -51,18 +51,18 @@
foreach ( $field['styles'] as $type => $field_name ) {
if ( 'font-color' === $type && $color = get_post_meta( $post_id, $field_name, true ) ) {
- $style .= '.' . esc_attr( $target['wrap'] ) . absint( $post_id ) . ' .' . esc_attr( $target['selector'] ) . '{ color:' . esc_attr( $color ) . '; }';
+ $style .= '.' . esc_attr( $target['wrap'] ) . absint( $post_id ) . ' .' . esc_attr( $target['selector'] ) . '{ color:' . self::css_value( $color ) . '; }';
}
if ( 'background-color' === $type && $color = get_post_meta( $post_id, $field_name, true ) ) {
- $style .= '.' . esc_attr( $target['wrap'] ) . absint( $post_id ) . ' .' . esc_attr( $target['selector'] ) . '{ background-color:' . esc_attr( $color ) . '; }';
+ $style .= '.' . esc_attr( $target['wrap'] ) . absint( $post_id ) . ' .' . esc_attr( $target['selector'] ) . '{ background-color:' . self::css_value( $color ) . '; }';
}
//todo create a filter here and modify the output using that instead of adding specific styling
if ( 'background-color-fold' === $type && $color = get_post_meta( $post_id, $field['styles']['background-color'], true ) ) {
$style .= '.' . esc_attr( $target['wrap'] ) . absint( $post_id ) . ' .' . esc_attr( $target['selector'] ) . ':after {
- border-left: solid 6px' . esc_attr( $color ) . ';
- border-top: solid 6px' . esc_attr( $color ) . ';
+ border-left: solid 6px' . self::css_value( $color ) . ';
+ border-top: solid 6px' . self::css_value( $color ) . ';
}';
$style .= '.' . esc_attr( $target['wrap'] ) . absint( $post_id ) . ' .' . esc_attr( $target['selector'] ) . '.revealed:after {
@@ -73,7 +73,7 @@
}
if ( 'background-color:hover' === $type && $color = get_post_meta( $post_id, $field_name, true ) ) {
- $style .= '.' . esc_attr( $target['wrap'] ) . absint( $post_id ) . ' .' . esc_attr( $target['selector'] ) . ':hover' . '{ background-color:' . esc_attr( $color ) . '; }';
+ $style .= '.' . esc_attr( $target['wrap'] ) . absint( $post_id ) . ' .' . esc_attr( $target['selector'] ) . ':hover' . '{ background-color:' . self::css_value( $color ) . '; }';
}
}
@@ -85,4 +85,24 @@
}
+ /**
+ * Returns a stored color only when it is a plain CSS color value.
+ *
+ * The values are post meta that end up inside a style attribute or a
+ * <style> block. Letters, digits, `#`, `(`, `)`, `,`, `.`, `%` and spaces
+ * cover hex, rgb(a), hsl(a) and named colors, and leave no way to close the
+ * attribute (`"`), the rule (`;` `}`) or the tag (`<`).
+ *
+ * @since 4.0.12
+ *
+ * @param mixed $value Stored color.
+ *
+ * @return string The color, or an empty string.
+ */
+ protected static function css_value( $value ) {
+ $value = trim( (string) $value );
+
+ return preg_match( '/^[#a-zA-Z0-9(),.%s]+$/', $value ) ? $value : '';
+ }
+
}
--- a/coupon-creator/src/Cctor/Admin/Columns.php
+++ b/coupon-creator/src/Cctor/Admin/Columns.php
@@ -223,7 +223,7 @@
esc_html_e( 'No expiration', 'coupon-creator' );
} else {
$display_expiration = $coupon_expiration->get_display_expiration();
- echo $display_expiration ? $display_expiration : '—';
+ echo $display_expiration ? esc_html( (string) $display_expiration ) : '—';
}
break;
--- a/coupon-creator/src/Cctor/Main.php
+++ b/coupon-creator/src/Cctor/Main.php
@@ -44,7 +44,7 @@
protected $min_php = '8.2';
const VERSION_KEY = 'cctor_coupon_version';
- const VERSION_NUM = '3.6.5';
+ const VERSION_NUM = '3.6.6';
const MIN_PNGX_VERSION = '4.0.2';
// Minimum add-on versions this core is compatible with — enforced by
// gate_outdated_extensions(), which unhooks anything below them rather than
@@ -66,7 +66,7 @@
const OPTIONS_ID = 'coupon_creator_options';
public $VERSION_KEY = 'cctor_coupon_version';
- public $VERSION_NUM = '3.6.5';
+ public $VERSION_NUM = '3.6.6';
public $MIN_PNGX_VERSION = '4.0.2';
public $WP_PLUGIN_URL = 'https://wordpress.org/plugins/coupon-creator/';
public $COUPON_CREATOR_STORE_URL = 'https://artifexrouting.com/edd-api/';
--- a/coupon-creator/src/Cctor/Post_Type_Coupon.php
+++ b/coupon-creator/src/Cctor/Post_Type_Coupon.php
@@ -262,6 +262,31 @@
}
/**
+ * Marks every `cctor_` post meta key as protected.
+ *
+ * The coupon post type supports 'custom-fields', so without this any user who
+ * can edit a coupon could write these keys raw through core's Custom Fields box
+ * (admin-ajax add-meta / update-meta), skipping the coupon meta box sanitizers.
+ * Protected keys are hidden from that box and refused by those requests. The
+ * plugin's own saves use update_post_meta() directly and are not affected.
+ *
+ * @since 3.6.6
+ *
+ * @param bool $protected Whether the key is protected.
+ * @param string $meta_key Meta key.
+ * @param string|null $meta_type Object type.
+ *
+ * @return bool
+ */
+ public function protect_coupon_meta( $protected, $meta_key, $meta_type = null ) {
+ if ( 'post' === $meta_type && is_string( $meta_key ) && 0 === strpos( $meta_key, 'cctor_' ) ) {
+ return true;
+ }
+
+ return $protected;
+ }
+
+ /**
* Register the post types.
*
* @since 3.0
--- a/coupon-creator/src/Cctor/Provider.php
+++ b/coupon-creator/src/Cctor/Provider.php
@@ -61,6 +61,7 @@
add_filter( 'pngx_dropdown_cctor_coupons', array( 'Cctor__Coupon__Admin__Inserter', 'search_coupons' ), 10, 3 );
add_filter( 'pngx_dropdown_capability', array( 'Cctor__Coupon__Admin__Inserter', 'dropdown_capability' ), 10, 2 );
add_action( 'init', pngx_callback( 'cctor.post_menu', 'register' ), 5 );
+ add_filter( 'is_protected_meta', pngx_callback( 'cctor.post_menu', 'protect_coupon_meta' ), 10, 3 );
add_action( 'init', pngx_callback( 'Pngx__Cron_20', 'filter_cron_schedules' ) );
add_action( 'pre_get_posts', pngx_callback( 'cctor.search', 'remove_coupon_from_search' ) );
--- a/coupon-creator/src/Cctor/Templates.php
+++ b/coupon-creator/src/Cctor/Templates.php
@@ -64,6 +64,11 @@
$template .= '.php';
}
+ // The type name comes from post meta: never let it leave the views folders.
+ if ( 0 !== validate_file( $template ) ) {
+ return false;
+ }
+
$file = false;
// Theme override: [your-theme]/cctor-coupons/type/<type>.php
--- a/coupon-creator/src/functions/template-functions/cctor-function-image.php
+++ b/coupon-creator/src/functions/template-functions/cctor-function-image.php
@@ -36,6 +36,6 @@
*/
function cctor_show_print_img( $coupon_id, $couponimage ) {
- ?><img class='cctor_coupon_image' src='<?php echo esc_url( $couponimage ); ?>' alt='<?php echo get_the_title(); ?>' title='<?php echo get_the_title(); ?>'><?php
+ ?><img class='cctor_coupon_image' src='<?php echo esc_url( $couponimage ); ?>' alt='<?php echo esc_attr( get_the_title() ); ?>' title='<?php echo esc_attr( get_the_title() ); ?>'><?php
}
No newline at end of file
--- a/coupon-creator/src/functions/template-functions/cctor-function-links.php
+++ b/coupon-creator/src/functions/template-functions/cctor-function-links.php
@@ -31,7 +31,7 @@
</a><?php
} else {
//No Links for Image Coupon or Click to Print
- ?><img class='cctor_coupon_image' src='<?php echo esc_url( $couponimage ); ?>' alt='<?php echo get_the_title( $coupon_id ); ?>' title='<?php echo get_the_title( $coupon_id ); ?>'><?php
+ ?><img class='cctor_coupon_image' src='<?php echo esc_url( $couponimage ); ?>' alt='<?php echo esc_attr( get_the_title( $coupon_id ) ); ?>' title='<?php echo esc_attr( get_the_title( $coupon_id ) ); ?>'><?php
}
}
--- a/coupon-creator/src/functions/template-functions/cctor-function-meta.php
+++ b/coupon-creator/src/functions/template-functions/cctor-function-meta.php
@@ -14,7 +14,7 @@
if ( cctor_options( 'cctor_nofollow_print_template', true, 1 ) == 1 ) { ?>
<meta name="robots" content="noindex,nofollow"/>
<?php } ?>
- <title><?php echo get_the_title(); ?></title>
+ <title><?php echo esc_html( get_the_title() ); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11"/>
<!--Make Background White to Print Coupon -->
--- a/coupon-creator/vendor/composer/installed.php
+++ b/coupon-creator/vendor/composer/installed.php
@@ -3,7 +3,7 @@
'name' => 'artifexrouting/coupon-creator',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => 'c189aa2705c69266f2f72ca3f6e9c03b6ddb9584',
+ 'reference' => 'e961c8a796ec8651fe610f0135e3fa8d1ed02e58',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -13,7 +13,7 @@
'artifexrouting/coupon-creator' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => 'c189aa2705c69266f2f72ca3f6e9c03b6ddb9584',
+ 'reference' => 'e961c8a796ec8651fe610f0135e3fa8d1ed02e58',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),