Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/motors-car-dealership-classified-listings/includes/actions.php
+++ b/motors-car-dealership-classified-listings/includes/actions.php
@@ -984,28 +984,80 @@
$response = array( 'status' => 'Error' );
- $car_id = intval( filter_var( wp_unslash( $_POST['car_id'] ), FILTER_SANITIZE_NUMBER_INT ) );
- $price = floatval( filter_var( wp_unslash( $_POST['price'] ), FILTER_SANITIZE_NUMBER_FLOAT ) );
+ $car_id = isset( $_POST['car_id'] ) ? absint( wp_unslash( $_POST['car_id'] ) ) : 0;
- if ( ! empty( $car_id ) && ! empty( $price ) ) {
+ if ( ! empty( $car_id ) && stm_is_listing_available_for_online_purchase( $car_id ) ) {
+ $price = stm_get_listing_online_purchase_price( $car_id );
- update_post_meta( $car_id, '_price', $price );
- update_post_meta( $car_id, 'is_sell_online_status', 'in_cart' );
+ if ( $price > 0 ) {
+ update_post_meta( $car_id, '_price', wc_format_decimal( $price ) );
+ update_post_meta( $car_id, 'is_sell_online_status', 'in_cart' );
- $checkout_url = wc_get_checkout_url() . '?add-to-cart=' . $car_id;
+ $checkout_url = add_query_arg( 'add-to-cart', $car_id, wc_get_checkout_url() );
- $response = array(
- 'status' => 'success',
- 'redirect_url' => $checkout_url,
- );
+ $response = array(
+ 'status' => 'success',
+ 'redirect_url' => $checkout_url,
+ );
- wp_send_json( $response );
+ wp_send_json( $response );
+ }
}
wp_send_json( $response );
}
}
+if ( ! function_exists( 'stm_get_online_purchase_listing_post_types' ) ) {
+ function stm_get_online_purchase_listing_post_types() {
+ $post_types = array( apply_filters( 'stm_listings_post_type', 'listings' ) );
+
+ if ( class_exists( 'STMMultiListing' ) ) {
+ $slugs = STMMultiListing::stm_get_listing_type_slugs();
+
+ if ( ! empty( $slugs ) ) {
+ $post_types = array_merge( $post_types, $slugs );
+ }
+ }
+
+ return array_unique( array_filter( $post_types ) );
+ }
+}
+
+if ( ! function_exists( 'stm_is_listing_available_for_online_purchase' ) ) {
+ function stm_is_listing_available_for_online_purchase( $listing_id ) {
+ if ( ! in_array( get_post_type( $listing_id ), stm_get_online_purchase_listing_post_types(), true ) ) {
+ return false;
+ }
+
+ if ( 'publish' !== get_post_status( $listing_id ) ) {
+ return false;
+ }
+
+ if ( empty( get_post_meta( $listing_id, 'car_mark_woo_online', true ) ) ) {
+ return false;
+ }
+
+ if ( ! empty( get_post_meta( $listing_id, 'car_mark_as_sold', true ) ) ) {
+ return false;
+ }
+
+ return true;
+ }
+}
+
+if ( ! function_exists( 'stm_get_listing_online_purchase_price' ) ) {
+ function stm_get_listing_online_purchase_price( $listing_id ) {
+ $price = get_post_meta( $listing_id, 'sale_price', true );
+
+ if ( empty( $price ) ) {
+ $price = get_post_meta( $listing_id, 'price', true );
+ }
+
+ return (float) wc_format_decimal( $price );
+ }
+}
+
//Trade in form ajax
if ( ! function_exists( 'handle_stm_trade_in_form' ) ) {
function handle_stm_trade_in_form() {
--- a/motors-car-dealership-classified-listings/includes/class/User/Model/UserModel.php
+++ b/motors-car-dealership-classified-listings/includes/class/User/Model/UserModel.php
@@ -191,9 +191,13 @@
}
public function fields_by_location( $lat, $lng ) {
- if ( empty( $lat ) ) {
+ if ( false === filter_var( $lat, FILTER_VALIDATE_FLOAT ) || false === filter_var( $lng, FILTER_VALIDATE_FLOAT ) ) {
return '';
}
+
+ $lat = (float) $lat;
+ $lng = (float) $lng;
+
$formula = "6378.137 * ACOS(COS(RADIANS(stm_lat_prefix.meta_value))
* COS(RADIANS($lat))
* COS(RADIANS(stm_lng_prefix.meta_value) - RADIANS($lng)) + SIN(RADIANS(stm_lat_prefix.meta_value))
@@ -203,7 +207,7 @@
}
public function join_by_location( $lat ) {
- if ( empty( $lat ) ) {
+ if ( false === filter_var( $lat, FILTER_VALIDATE_FLOAT ) ) {
return '';
}
$join = " JOIN $this->user_meta_table AS stm_lat_prefix ON (u.ID = stm_lat_prefix.user_id AND stm_lat_prefix.meta_key = 'stm_dealer_location_lat')";
@@ -213,15 +217,17 @@
}
public function having_by_location( $lat, $radius ) {
- if ( empty( $lat ) ) {
+ if ( false === filter_var( $lat, FILTER_VALIDATE_FLOAT ) || false === filter_var( $radius, FILTER_VALIDATE_FLOAT ) ) {
return '';
}
+ $radius = (float) $radius;
+
return "HAVING distance <= $radius";
}
public function order_by_location( $lat ) {
- if ( empty( $lat ) ) {
+ if ( false === filter_var( $lat, FILTER_VALIDATE_FLOAT ) ) {
return '';
}
--- a/motors-car-dealership-classified-listings/includes/class/User/UserController.php
+++ b/motors-car-dealership-classified-listings/includes/class/User/UserController.php
@@ -64,12 +64,12 @@
}
}
- $lat = apply_filters( 'stm_listings_input', null, 'stm_lat' );
- $lng = apply_filters( 'stm_listings_input', null, 'stm_lng' );
- $radius = apply_filters( 'motors_vl_get_nuxy_mod', '', 'distance_search' );
- $radius = ( ! empty( $radius ) ) ? $radius : 5000;
+ $lat = filter_var( apply_filters( 'stm_listings_input', null, 'stm_lat' ), FILTER_VALIDATE_FLOAT );
+ $lng = filter_var( apply_filters( 'stm_listings_input', null, 'stm_lng' ), FILTER_VALIDATE_FLOAT );
+ $radius = filter_var( apply_filters( 'motors_vl_get_nuxy_mod', '', 'distance_search' ), FILTER_VALIDATE_FLOAT );
+ $radius = ( false !== $radius && $radius > 0 ) ? $radius : 5000;
- if ( empty( $left_join ) && ! empty( floatval( $lat ) ) && ! empty( floatval( $lng ) ) ) {
+ if ( empty( $left_join ) && false !== $lat && false !== $lng ) {
$include_users = $model->get_filtered_users_by_location( $model->fields_by_location( $lat, $lng ), $model->join_by_location( $lat ), $model->having_by_location( $lat, $radius ), $model->order_by_location( $lat ) );
} elseif ( ! empty( $left_join ) && ! empty( $where ) ) {
$include_users = $model->get_filtered_users( $left_join, $where, $model->fields_by_location( $lat, $lng ), $model->join_by_location( $lat ), $model->having_by_location( $lat, $radius ), $model->order_by_location( $lat ) );
--- a/motors-car-dealership-classified-listings/includes/helpers.php
+++ b/motors-car-dealership-classified-listings/includes/helpers.php
@@ -1337,7 +1337,7 @@
$page = 'inventory';
if ( isset( $_GET['page'] ) ) {
- $page = sanitize_text_field( $_GET['page'] );
+ $page = sanitize_key( wp_unslash( $_GET['page'] ) );
}
if ( ! empty( $_GET['my_favourites'] ) ) {
--- a/motors-car-dealership-classified-listings/includes/templates.php
+++ b/motors-car-dealership-classified-listings/includes/templates.php
@@ -15,6 +15,12 @@
$located = false;
foreach ( (array) $templates as $template ) {
+ if ( ! stm_listings_is_safe_template_path( $template ) ) {
+ continue;
+ }
+
+ $template = ltrim( str_replace( '\', '/', $template ), '/' );
+
if ( substr( $template, - 4 ) !== '.php' ) {
$template .= '.php';
}
@@ -26,12 +32,18 @@
}
if ( ! ( $located ) ) {
- if ( file_exists( realpath( apply_filters( 'stm_listings_template_file', STM_LISTINGS_PATH, $template ) . '/templates/' . $template ) ) ) {
- $located = realpath( apply_filters( 'stm_listings_template_file', STM_LISTINGS_PATH, $template ) . '/templates/' . $template );
+ $template_base = realpath( apply_filters( 'stm_listings_template_file', STM_LISTINGS_PATH, $template ) . '/templates' );
+
+ if ( $template_base ) {
+ $template_path = realpath( $template_base . '/' . $template );
+
+ if ( $template_path && 0 === strpos( $template_path, $template_base . DIRECTORY_SEPARATOR ) && file_exists( $template_path ) ) {
+ $located = $template_path;
+ }
}
}
- if ( file_exists( $located ) ) {
+ if ( $located && file_exists( $located ) ) {
break;
}
}
@@ -40,6 +52,33 @@
}
/**
+ * Check that a requested template path cannot escape the listings template scope.
+ *
+ * @param mixed $template Template path.
+ *
+ * @return bool
+ */
+function stm_listings_is_safe_template_path( $template ) {
+ if ( ! is_string( $template ) || '' === $template || str_contains( $template, "