Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/events-made-easy/events-manager.php
+++ b/events-made-easy/events-manager.php
@@ -6,7 +6,7 @@
/*
Plugin Name: Events Made Easy
-Version: 3.3.8
+Version: 3.3.9
Plugin URI: https://www.e-dynamics.be/wordpress
Description: Manage and display events and memberships. Also includes recurring events; locations; widgets; maps; RSVP; ICAL and RSS feeds; Paypal, Stripe, Mollie and others.
Author: Franky Van Liedekerke
@@ -35,7 +35,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-define( 'EME_VERSION', '3.3.8' );
+define( 'EME_VERSION', '3.3.9' );
define( 'EME_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'EME_INCLUDE_DIR', EME_PLUGIN_DIR . 'includes/' );
define( 'EME_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
--- a/events-made-easy/includes/eme-actions.php
+++ b/events-made-easy/includes/eme-actions.php
@@ -825,7 +825,7 @@
// remove potential unsecured tags
//$rendered = apply_filters('the_content', $content);
- $rendered = eme_kses($content);
+ $rendered = eme_kses_request( $content );
if ( ! empty( $_POST['screen_id'] ) && $_POST['screen_id'] == 'events-made-easy_page_eme-emails' ) {
$rendered = eme_replaceiframe($rendered);
--- a/events-made-easy/includes/eme-categories.php
+++ b/events-made-easy/includes/eme-categories.php
@@ -46,7 +46,7 @@
// category update required
$category = [];
$category['category_name'] = eme_sanitize_request( $_POST['category_name'] );
- $category['description'] = eme_kses( $_POST['description'] );
+ $category['description'] = eme_kses_request( $_POST['description'] );
if ( ! empty( $_POST['category_prefix'] ) ) {
$category['category_prefix'] = eme_sanitize_request( $_POST['category_prefix'] );
}
--- a/events-made-easy/includes/eme-events.php
+++ b/events-made-easy/includes/eme-events.php
@@ -433,7 +433,7 @@
$post_vars = [ 'event_seats', 'price', 'currency', 'event_author', 'event_contactperson_id', 'event_url', 'event_image_url', 'event_image_id', 'event_prefix', 'event_slug', 'event_page_title_format', 'event_contactperson_email_body', 'event_registration_recorded_ok_html', 'event_respondent_email_body', 'event_registration_pending_email_body', 'event_registration_updated_email_body', 'event_registration_cancelled_email_body', 'event_registration_trashed_email_body', 'event_registration_form_format', 'event_cancel_form_format', 'event_registration_paid_email_body' ];
foreach ( $post_vars as $post_var ) {
if ( isset( $_POST[ $post_var ] ) ) {
- $event[ $post_var ] = eme_kses( $_POST[ $post_var ] );
+ $event[ $post_var ] = eme_kses_request( $_POST[ $post_var ] );
}
}
@@ -448,8 +448,8 @@
}
// event notes and format
- $event['event_single_event_format'] = eme_kses_maybe_unfiltered( $_POST['event_single_event_format'] ?? '' );
- $event['event_notes'] = eme_kses_maybe_unfiltered( $_POST['content'] ?? '' );
+ $event['event_single_event_format'] = eme_kses_request_maybe_unfiltered( $_POST['event_single_event_format'] ?? '' );
+ $event['event_notes'] = eme_kses_request_maybe_unfiltered( $_POST['content'] ?? '' );
if ( ! current_user_can( get_option( 'eme_cap_publish_event' ) ) ) {
$event['event_status'] = EME_EVENT_STATUS_DRAFT;
@@ -551,7 +551,7 @@
$i=1;
while (isset( $_POST[ "eme_attr_{$i}_ref" ] ) && !eme_is_empty_string( $_POST[ "eme_attr_{$i}_ref" ] ) ) {
if ( !eme_is_empty_string( $_POST[ "eme_attr_{$i}_name" ] ) ) {
- $event_attributes[ $_POST[ "eme_attr_{$i}_ref" ] ] = eme_kses( $_POST[ "eme_attr_{$i}_name" ] );
+ $event_attributes[ $_POST[ "eme_attr_{$i}_ref" ] ] = eme_kses_request( $_POST[ "eme_attr_{$i}_name" ] );
}
$i++;
}
@@ -568,7 +568,7 @@
} elseif ( $found_key == 'multiprice_desc' ) {
$event_properties[ $found_key ] = eme_convert_array2multi( eme_sanitize_request( eme_text_split_newlines( $value ) ) );
} else {
- $event_properties[ $found_key ] = eme_kses( $value );
+ $event_properties[ $found_key ] = eme_kses_request( $value );
}
}
if ( preg_match( '/eme_loc_prop_(.+)/', eme_sanitize_request( $key ), $matches ) ) {
@@ -576,7 +576,7 @@
if ( preg_match( '/password/', $found_key ) ) {
$location_properties[ $found_key ] = $value;
} else {
- $location_properties[ $found_key ] = eme_kses( $value );
+ $location_properties[ $found_key ] = eme_kses_request( $value );
}
}
}
@@ -587,8 +587,8 @@
$event['event_properties'] = eme_init_event_props( $event_properties );
$location['location_properties'] = eme_init_location_props( $location_properties );
- $event = eme_sanitize_event( $event );
- $location = eme_sanitize_location( $location );
+ $event = eme_normalize_event( $event );
+ $location = eme_normalize_location( $location );
$validation_result = eme_validate_event( $event );
if ( !empty($validation_result) ) {
// validation unsuccessful
@@ -6134,7 +6134,7 @@
$event_id = eme_check_event_external_ref( $line['event_external_ref'] );
}
- $line = eme_sanitize_event( $line );
+ $line = eme_normalize_event( $line );
if ( $event_id ) {
// event_id is returned if update is ok, and we use the location id later on
$event_id = eme_db_update_event( $line, $event_id );
@@ -9319,7 +9319,15 @@
}
}
-function eme_sanitize_event( $event ) {
+// Normalizes an event array: removes unwanted fields, fixes the start/end
+// datetimes, seats, prices and derived properties.
+//
+// It deliberately does NOT filter HTML. Free-text fields (e.g. event_notes,
+// event_single_event_format) must be sanitized by the caller at input time
+// using eme_kses_request()/eme_kses_request_maybe_unfiltered(). Re-running kses
+// here would re-evaluate the *current* user's unfiltered_html capability against
+// already-stored data and could silently strip content on a later save.
+function eme_normalize_event( $event ) {
// remove possible unwanted fields
if ( isset( $event['event_id'] ) ) {
unset( $event['event_id'] );
@@ -9464,6 +9472,11 @@
return $event;
}
+// backwards compatible
+function eme_sanitize_event( $event ) {
+ return eme_normalize_event( $event );
+}
+
function eme_db_insert_event( $line, $event_is_part_of_recurrence = 0, $day_difference = 0, $plugin_installing = 0 ) {
global $wpdb;
@@ -10651,7 +10664,7 @@
$field_id = intval( $matches[1] );
$formfield = eme_get_formfield( $field_id );
if ( ! empty( $formfield ) && $formfield['field_purpose'] == 'events' ) {
- $value = eme_kses_maybe_unfiltered( $value );
+ $value = eme_kses_request_maybe_unfiltered( $value );
// for multivalue fields like checkbox, the value is in fact an array
// to store it, we make it a simple "multi" string using eme_convert_array2multi, so later on when we need to parse the values
// (when editing), we can re-convert it to an array with eme_convert_multi2array (see eme_formfields.php)
@@ -10773,6 +10786,9 @@
return [];
}
+ // let's not filter for more than 20 things
+ $val = array_slice( $val, 0, 20 );
+
$table = $wpdb->prefix . 'eme_answers';
// Build the query using proper prepared statements
--- a/events-made-easy/includes/eme-formfields.php
+++ b/events-made-easy/includes/eme-formfields.php
@@ -82,7 +82,7 @@
if (eme_is_empty_string($_POST['field_tags'] )) {
$field_tags_arr = [];
} else {
- $field_tags_arr = eme_kses( eme_convert_multi2array(eme_convert_array2multi( eme_text_split_newlines( $_POST['field_tags'] ) )));
+ $field_tags_arr = eme_kses_request( eme_convert_multi2array(eme_convert_array2multi( eme_text_split_newlines( $_POST['field_tags'] ) )));
}
if (eme_is_empty_string($_POST['admin_values'] )) {
$admin_values_arr = [];
@@ -92,7 +92,7 @@
if (eme_is_empty_string($_POST['admin_tags'] )) {
$admin_tags_arr = [];
} else {
- $admin_tags_arr = eme_kses( eme_convert_multi2array(eme_convert_array2multi( eme_text_split_newlines( $_POST['admin_tags'] ) )));
+ $admin_tags_arr = eme_kses_request( eme_convert_multi2array(eme_convert_array2multi( eme_text_split_newlines( $_POST['admin_tags'] ) )));
}
// some sanity checks
--- a/events-made-easy/includes/eme-fs.php
+++ b/events-made-easy/includes/eme-fs.php
@@ -663,7 +663,7 @@
$preserved_notes = $_POST['event']['event_notes'] ?? null;
$preserved_single_event_format = $_POST['event']['event_single_event_format'] ?? null;
$preserved_location_description = $_POST['event']['location_description'] ?? null;
- $event_data = eme_kses($_POST['event']);
+ $event_data = eme_kses_request($_POST['event']);
if ( ! is_array( $event_data ) ) {
$event_data = [];
}
@@ -673,21 +673,21 @@
}
}
if ( $preserved_notes !== null ) {
- $event_data['event_notes'] = eme_kses_maybe_unfiltered( $preserved_notes );
+ $event_data['event_notes'] = eme_kses_request_maybe_unfiltered( $preserved_notes );
}
if ( $preserved_single_event_format !== null ) {
- $event_data['event_single_event_format'] = eme_kses_maybe_unfiltered( $preserved_single_event_format );
+ $event_data['event_single_event_format'] = eme_kses_request_maybe_unfiltered( $preserved_single_event_format );
}
if ( $preserved_location_description !== null ) {
- $event_data['location_description'] = eme_kses_maybe_unfiltered( $preserved_location_description );
+ $event_data['location_description'] = eme_kses_request_maybe_unfiltered( $preserved_location_description );
}
}
// add in the event_attributes and properties
if (isset($_POST['event_attributes']) && !empty($_POST['event_attributes']) && is_array($_POST['event_attributes'])) {
- $event_data['event_attributes'] = eme_kses($_POST['event_attributes']);
+ $event_data['event_attributes'] = eme_kses_request($_POST['event_attributes']);
}
if (isset($_POST['event_properties']) && !empty($_POST['event_properties']) && is_array($_POST['event_properties'])) {
- $event_data['event_properties'] = eme_kses($_POST['event_properties']);
+ $event_data['event_properties'] = eme_kses_request($_POST['event_properties']);
// validate wp_page_template against the theme's allow-list
if ( ! empty( $event_data['event_properties']['wp_page_template'] ) ) {
$allowed_templates = array_values( wp_get_theme()->get_page_templates() );
@@ -800,7 +800,7 @@
if ($eme_fs_options['price']>0 && $pg_count>0) {
$event_data['event_status'] = EME_EVENT_STATUS_FS_DRAFT;
}
- $event_data = eme_sanitize_event($event_data);
+ $event_data = eme_normalize_event($event_data);
$validation_result = '';
if (has_filter('eme_fs_validate_event_filter')) {
$validation_result = apply_filters( 'eme_fs_validate_event_filter', $event_data );
@@ -883,7 +883,7 @@
if (empty($location['location_name']) && empty($location['location_address1']) && empty($location['location_latitude']) && empty($location['location_longitude'])) {
return 0;
}
- $location = eme_sanitize_location($location);
+ $location = eme_normalize_location($location);
$location_id=eme_get_identical_location_id($location);
if (!$location_id ) {
$validation_result = eme_validate_location ( $location );
--- a/events-made-easy/includes/eme-functions.php
+++ b/events-made-easy/includes/eme-functions.php
@@ -2590,7 +2590,141 @@
return $array;
}
-function _eme_kses_single( $value, $allow_unfiltered ) {
+function _eme_find_html_tag_end( $html, $start ) {
+ $length = strlen( $html );
+ if ( 0 === substr_compare( $html, '<!--', $start, 4 ) ) {
+ $end = strpos( $html, '-->', $start + 4 );
+ return false === $end ? false : $end + 2;
+ }
+ $quote = '';
+ for ( $i = $start + 1; $i < $length; ++$i ) {
+ $char = $html[ $i ];
+ if ( '' !== $quote ) {
+ if ( $char === $quote ) {
+ $quote = '';
+ }
+ continue;
+ }
+ if ( '"' === $char || "'" === $char ) {
+ $quote = $char;
+ continue;
+ }
+ if ( '>' === $char ) {
+ return $i;
+ }
+ }
+ return false;
+}
+
+// Best-effort removal of inline event handler attributes (on*) from a single tag.
+// This is defense-in-depth only, NOT a security boundary: it is a hand-rolled
+// tokenizer and is never the sole protection for untrusted input. The filtered
+// (non-unfiltered_html) path relies on wp_kses() instead; the unfiltered path
+// trusts the user by definition (WordPress grants them raw HTML).
+function _eme_strip_event_attributes_from_tag( $tag ) {
+ $length = strlen( $tag );
+ if ( $length < 2 || '<' !== $tag[0] || '/' === $tag[1] || '!' === $tag[1] || '?' === $tag[1] ) {
+ return $tag;
+ }
+ $i = 1;
+ while ( $i < $length && ! ctype_space( $tag[ $i ] ) && '/' !== $tag[ $i ] && '>' !== $tag[ $i ] ) {
+ ++$i;
+ }
+ $out = substr( $tag, 0, $i );
+ while ( $i < $length ) {
+ $whitespace_start = $i;
+ while ( $i < $length && ( ctype_space( $tag[ $i ] )
+ || ( '/' === $tag[ $i ] && ! ( $i + 1 < $length && '>' === $tag[ $i + 1 ] ) ) ) ) {
+ ++$i;
+ }
+ $whitespace = substr( $tag, $whitespace_start, $i - $whitespace_start );
+ if ( $i >= $length ) {
+ $out .= $whitespace;
+ break;
+ }
+ if ( '>' === $tag[ $i ] || ( '/' === $tag[ $i ] && $i + 1 < $length && '>' === $tag[ $i + 1 ] ) ) {
+ $out .= $whitespace . substr( $tag, $i );
+ break;
+ }
+ $attribute_start = $i;
+ while ( $i < $length ) {
+ $char = $tag[ $i ];
+ if ( ctype_space( $char ) || '=' === $char || '>' === $char || '/' === $char ) {
+ break;
+ }
+ ++$i;
+ }
+ $attribute_name = substr( $tag, $attribute_start, $i - $attribute_start );
+ if ( '' === $attribute_name ) {
+ $out .= $whitespace . $tag[ $i ];
+ ++$i;
+ continue;
+ }
+ while ( $i < $length && ctype_space( $tag[ $i ] ) ) {
+ ++$i;
+ }
+ if ( $i < $length && '=' === $tag[ $i ] ) {
+ ++$i;
+ while ( $i < $length && ctype_space( $tag[ $i ] ) ) {
+ ++$i;
+ }
+ if ( $i < $length ) {
+ $quote = $tag[ $i ];
+ if ( '"' === $quote || "'" === $quote ) {
+ ++$i;
+ while ( $i < $length && $tag[ $i ] !== $quote ) {
+ ++$i;
+ }
+ if ( $i < $length ) {
+ ++$i;
+ }
+ } else {
+ while ( $i < $length && ! ctype_space( $tag[ $i ] ) && '>' !== $tag[ $i ] ) {
+ if ( '/' === $tag[ $i ] && $i + 1 < $length && '>' === $tag[ $i + 1 ] ) {
+ break;
+ }
+ ++$i;
+ }
+ }
+ }
+ }
+ $attribute = substr( $tag, $attribute_start, $i - $attribute_start );
+ if ( strlen( $attribute_name ) <= 2 || 0 !== stripos( $attribute_name, 'on' ) ) {
+ $out .= $whitespace . $attribute;
+ }
+ }
+ return $out;
+}
+
+function _eme_strip_inline_event_handlers( $html ) {
+ $length = strlen( $html );
+ $out = '';
+ $offset = 0;
+ while ( $offset < $length ) {
+ $tag_start = strpos( $html, '<', $offset );
+ if ( false === $tag_start ) {
+ $out .= substr( $html, $offset );
+ break;
+ }
+ $out .= substr( $html, $offset, $tag_start - $offset );
+ $next = $tag_start + 1 < $length ? $html[ $tag_start + 1 ] : '';
+ if ( ! ctype_alpha( $next ) && '/' !== $next && '!' !== $next && '?' !== $next ) {
+ $out .= '<';
+ $offset = $tag_start + 1;
+ continue;
+ }
+ $tag_end = _eme_find_html_tag_end( $html, $tag_start );
+ if ( false === $tag_end ) {
+ $out .= _eme_strip_event_attributes_from_tag( substr( $html, $tag_start ) );
+ break;
+ }
+ $out .= _eme_strip_event_attributes_from_tag( substr( $html, $tag_start, $tag_end - $tag_start + 1 ) );
+ $offset = $tag_end + 1;
+ }
+ return $out;
+}
+
+function _eme_kses_single( $value, $allow_unfiltered, $unslash ) {
if ( empty( $value ) ) {
return $value;
}
@@ -2599,15 +2733,23 @@
// <img onerror=...> to sneak past wp_kses and reappear as live markup
// once the browser decodes it again on render
$value = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
+ // Only request data is slashed by WordPress; stored values must not be unslashed again.
+ if ( $unslash ) {
+ $value = wp_unslash( $value );
+ }
// To filter out JS, we should use domdocument, but the problem is that sometimes the
// html is intentional incomplete, which would cause issues with domdocument
// See https://codereview.stackexchange.com/questions/30045/regex-to-remove-inline-javascript-from-string
if ( $allow_unfiltered ) {
- // even for unfiltered: strip out javascript
- $res = preg_replace( '#<s*script.*?>.*?<s*/s*scripts*>#is', '', wp_unslash( $value ) );
- # also strip out inline javascript (onalert etc)
- $res = preg_replace_callback( '#<[^>]+>#', function( $m ) { return preg_replace( '#s+onw+s*=s*("[^"]*"|'[^']*'|[^s>]+)#i', '', $m[0] ); }, $res );
- return $res;
+ // The user has the unfiltered_html capability (WordPress would store their
+ // raw HTML), so this branch cannot be a real security boundary. We still do
+ // a best-effort cleanup (strip script elements and inline on* handlers).
+ // Untrusted input always goes through the wp_kses() branch below.
+ // Remove complete script elements first, then any stray opening/closing
+ // script tags (an unclosed <script src=...> would otherwise survive).
+ $res = preg_replace( '#<s*scriptb[^>]*>.*?<s*/s*scripts*>#is', '', $value );
+ $res = preg_replace( '#<s*/?s*scriptb[^>]*>#is', '', $res );
+ return _eme_strip_inline_event_handlers( $res );
}
$allowed_html = wp_kses_allowed_html( 'post' );
// this option is per line
@@ -2637,39 +2779,40 @@
add_filter( 'safe_style_css', 'eme_safe_css_attributes' );
add_filter( 'safecss_filter_attr_allow_css', 'eme_safe_css_allow_color_functions', 10, 2 );
// brute-force remove script tags, even if wp_kses wouldn't do it
- $res = preg_replace( '#<s*script(.*?)>(.*?)<s*/s*scripts*>#is', '', wp_kses( wp_unslash( $value ), $allowed_html ) );
- # also strip out inline javascript (onalert etc)
- $res = preg_replace( '#bonw+s*=s*S+(?=.*>)#', '', $res );
+ $res = preg_replace( '#<s*script(.*?)>(.*?)<s*/s*scripts*>#is', '', wp_kses( $value, $allowed_html ) );
+ $res = _eme_strip_inline_event_handlers( $res );
remove_filter( 'safecss_filter_attr_allow_css', 'eme_safe_css_allow_color_functions', 10, 2 );
remove_filter( 'safe_style_css', 'eme_safe_css_attributes' );
return $res;
}
-function eme_kses( $value ) {
- $allow_unfiltered = 0;
+function _eme_kses_value( $value, $allow_unfiltered, $unslash ) {
if ( is_array( $value ) ) {
- return array_map( 'eme_kses', $value );
- } else {
- return _eme_kses_single( $value, $allow_unfiltered );
+ return array_map( static function( $v ) use ( $allow_unfiltered, $unslash ) {
+ return _eme_kses_value( $v, $allow_unfiltered, $unslash );
+ }, $value );
}
+ return _eme_kses_single( $value, $allow_unfiltered, $unslash );
}
-function eme_kses_maybe_unfiltered( $value ) {
- $allow_unfiltered = 1;
+function eme_kses_request( $value ) {
+ return _eme_kses_value( $value, 0, true );
+}
+
+function eme_kses( $value ) {
+ return _eme_kses_value( $value, 0, false );
+}
+
+function eme_kses_request_maybe_unfiltered( $value ) {
// if allow_unfiltered is on: check if the user is actually allowed do it
- if ( ! current_user_can( 'unfiltered_html' ) ) {
- $allow_unfiltered = 0;
- }
- if ( is_array( $value ) ) {
- return array_map( 'eme_kses_maybe_unfiltered', $value );
- } else {
- return _eme_kses_single( $value, $allow_unfiltered );
- }
+ $allow_unfiltered = current_user_can( 'unfiltered_html' ) ? 1 : 0;
+ return _eme_kses_value( $value, $allow_unfiltered, true );
}
-// backwards compatible
-function eme_strip_js( $value ) {
- return eme_kses( $value );
+function eme_kses_maybe_unfiltered( $value ) {
+ // if allow_unfiltered is on: check if the user is actually allowed do it
+ $allow_unfiltered = current_user_can( 'unfiltered_html' ) ? 1 : 0;
+ return _eme_kses_value( $value, $allow_unfiltered, false );
}
function eme_strip_weird( $value ) {
@@ -4761,10 +4904,6 @@
return "<div class='notice notice-error $dismiss_class eme-message-admin'>" . wp_kses_post( $message ) . '</div>';
}
-// backwars compatible
-function eme_apply_output_filters( $replacement, $target, $esc_html = false ) {
- return eme_sanitize_placeholder_output( $replacement, $target, $esc_html, false );
-}
function eme_neutralize_template_syntax( $value, $target = 'html' ) {
if ( is_array( $value ) ) {
return array_map(
@@ -4791,7 +4930,7 @@
function eme_sanitize_placeholder_output( $replacement, $target, $esc_html = false, $neutralize = true ) {
if ( $target == 'html' || $target == 'htmlmail' ) {
- $replacement = eme_kses($replacement);
+ $replacement = eme_kses( $replacement );
if ( $esc_html ) {
$replacement = esc_html( $replacement );
}
--- a/events-made-easy/includes/eme-install.php
+++ b/events-made-easy/includes/eme-install.php
@@ -393,7 +393,7 @@
$event['event_start'] = "$in_one_week 16:00:00";
$event['event_end'] = "$in_one_week 18:00:00";
$event['location_id'] = 1;
- $event = eme_sanitize_event( $event );
+ $event = eme_normalize_event( $event );
// the fourth param is 1 to indicate we're in plugin install mode
// this will cause eme_db_insert_event to check the prefix itself
// since during install plugin globals are not available ...
@@ -404,7 +404,7 @@
$event['event_start'] = "$in_four_weeks 20:00:00";
$event['event_end'] = "$in_four_weeks 22:00:00";
$event['location_id'] = 2;
- $event = eme_sanitize_event( $event );
+ $event = eme_normalize_event( $event );
// the fourth param is 1 to indicate we're in plugin install mode
// this will cause eme_db_insert_event to check the prefix itself
// since during install plugin globals are not available ...
@@ -415,7 +415,7 @@
$event['event_start'] = "$in_one_year 22:00:00";
$event['event_end'] = "$in_one_year 23:59:59";
$event['location_id'] = 3;
- $event = eme_sanitize_event( $event );
+ $event = eme_normalize_event( $event );
// the fourth param is 1 to indicate we're in plugin install mode
// this will cause eme_db_insert_event to check the prefix itself
// since during install plugin globals are not available ...
--- a/events-made-easy/includes/eme-locations.php
+++ b/events-made-easy/includes/eme-locations.php
@@ -127,7 +127,7 @@
}
}
//switched to WP TinyMCE field
- $location['location_description'] = eme_kses_maybe_unfiltered( $_POST['location_description'] );
+ $location['location_description'] = eme_kses_request_maybe_unfiltered( $_POST['location_description'] );
if ( isset( $_POST['location_category_ids'] ) && eme_is_integer_array( $_POST['location_category_ids'] ) ) {
$location ['location_category_ids'] = join( ',', array_map( 'intval', $_POST['location_category_ids'] ) );
@@ -139,7 +139,7 @@
$i=1;
while (isset( $_POST[ "eme_attr_{$i}_ref" ] ) && !eme_is_empty_string( $_POST[ "eme_attr_{$i}_ref" ] ) ) {
if ( !eme_is_empty_string( $_POST[ "eme_attr_{$i}_name" ] ) ) {
- $location_attributes[ $_POST[ "eme_attr_{$i}_ref" ] ] = eme_kses( $_POST[ "eme_attr_{$i}_name" ] );
+ $location_attributes[ $_POST[ "eme_attr_{$i}_ref" ] ] = eme_kses_request( $_POST[ "eme_attr_{$i}_name" ] );
}
$i++;
}
@@ -152,13 +152,13 @@
if ( preg_match( '/password/', $found_key ) ) {
$location_properties[ $found_key ] = $value;
} else {
- $location_properties[ $found_key ] = eme_kses( $value );
+ $location_properties[ $found_key ] = eme_kses_request( $value );
}
}
}
$location['location_properties'] = eme_init_location_props( $location_properties );
- $location = eme_sanitize_location( $location );
+ $location = eme_normalize_location( $location );
$validation_result = eme_validate_location( $location );
if ( $validation_result == 'OK' ) {
if ( $action == 'do_addlocation' ) {
@@ -1368,7 +1368,15 @@
return $wpdb->get_var( $prepared_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
}
-function eme_sanitize_location( $location ) {
+// Normalizes a location array: removes unwanted fields, fixes URLs, coerces
+// lat/long and id fields, and derives the slug.
+//
+// It deliberately does NOT filter HTML. Free-text fields (e.g.
+// location_description) must be sanitized by the caller at input time using
+// eme_kses_request()/eme_kses_request_maybe_unfiltered(). Re-running kses here
+// would re-evaluate the *current* user's unfiltered_html capability against
+// already-stored data and could silently strip content on a later save.
+function eme_normalize_location( $location ) {
// remove possible unwanted fields
if ( isset( $location['location_id'] ) ) {
unset( $location['location_id'] );
@@ -1418,14 +1426,14 @@
}
}
- $preserved_description = $location['location_description'] ?? null;
- $location = eme_kses( $location );
- if ( $preserved_description !== null ) {
- $location['location_description'] = eme_kses_maybe_unfiltered($preserved_description);
- }
return $location;
}
+// backwards compatible
+function eme_sanitize_location( $location ) {
+ return eme_normalize_location( $location );
+}
+
function eme_validate_location( $location ) {
$location_required_fields = [
'location_name' => __( 'The location name', 'events-made-easy' ),
@@ -3403,7 +3411,7 @@
$field_id = intval( $matches[1] );
$formfield = eme_get_formfield( $field_id );
if ( ! empty( $formfield ) && $formfield['field_purpose'] == 'locations' ) {
- $value = eme_kses_maybe_unfiltered( $value );
+ $value = eme_kses_request_maybe_unfiltered( $value );
// for multivalue fields like checkbox, the value is in fact an array
// to store it, we make it a simple "multi" string using eme_convert_array2multi, so later on when we need to parse the values
// (when editing), we can re-convert it to an array with eme_convert_multi2array (see eme_formfields.php)
@@ -3493,6 +3501,9 @@
return [];
}
+ // let's not filter for more than 20 things
+ $val = array_slice( $val, 0, 20 );
+
$table = $wpdb->prefix . 'eme_answers';
// Build the query using proper prepared statements
--- a/events-made-easy/includes/eme-mailer.php
+++ b/events-made-easy/includes/eme-mailer.php
@@ -2495,7 +2495,7 @@
}
if ( ! empty( $_POST['generic_mail_message'] ) ) {
- $mail_message = eme_kses_maybe_unfiltered( $_POST['generic_mail_message'] );
+ $mail_message = eme_kses_request_maybe_unfiltered( $_POST['generic_mail_message'] );
} elseif ( isset( $_POST['generic_message_template'] ) && intval( $_POST['generic_message_template'] ) > 0 ) {
$mail_message = eme_get_template_format_plain( intval( $_POST['generic_message_template'] ) );
} else {
@@ -2554,7 +2554,7 @@
}
if ( ! empty( $_POST['event_mail_message'] ) ) {
- $mail_message = eme_kses_maybe_unfiltered( $_POST['event_mail_message'] );
+ $mail_message = eme_kses_request_maybe_unfiltered( $_POST['event_mail_message'] );
} elseif ( isset( $_POST['event_message_template'] ) && intval( $_POST['event_message_template'] ) > 0 ) {
$mail_message = eme_get_template_format_plain( intval( $_POST['event_message_template'] ) );
} else {
--- a/events-made-easy/includes/eme-members.php
+++ b/events-made-easy/includes/eme-members.php
@@ -1162,7 +1162,7 @@
}
}
if ( isset( $_POST['properties'] ) ) {
- $member['properties'] = eme_kses( $_POST['properties'] );
+ $member['properties'] = eme_kses_request( $_POST['properties'] );
}
// usage_count needs to be an int
if ( isset( $member['properties']['usage_count'] ) ) {
@@ -1570,7 +1570,7 @@
if ( preg_match( '/password/', $key ) ) {
$membership_properties[ $key ] = $value;
} else {
- $membership_properties[ $key ] = eme_kses( $value );
+ $membership_properties[ $key ] = eme_kses_request( $value );
}
}
$membership['properties'] = $membership_properties;
@@ -7685,7 +7685,7 @@
$field_id = intval( $matches[1] );
$formfield = eme_get_formfield( $field_id );
if ( ! empty( $formfield ) && $formfield['field_purpose'] == 'memberships' ) {
- $value = eme_kses_maybe_unfiltered( $value );
+ $value = eme_kses_request_maybe_unfiltered( $value );
// for multivalue fields like checkbox, the value is in fact an array
// to store it, we make it a simple "multi" string using eme_convert_array2multi, so later on when we need to parse the values
// (when editing), we can re-convert it to an array with eme_convert_multi2array (see eme_formfields.php)
--- a/events-made-easy/includes/eme-options.php
+++ b/events-made-easy/includes/eme-options.php
@@ -1308,7 +1308,7 @@
} elseif (in_array($key, $maybe_unfiltered)) {
$output[$key] = eme_kses_maybe_unfiltered($value);
} else {
- $output[$key] = eme_kses($value);
+ $output[$key] = eme_kses($value); // unslash already done, no need to do it again
}
if (array_key_exists($key,$numeric_options) && ! is_numeric( $output[$key] ) ) {
$output[$key] = $numeric_options[$key];
--- a/events-made-easy/includes/eme-payments.php
+++ b/events-made-easy/includes/eme-payments.php
@@ -706,12 +706,8 @@
return;
}
- $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
- $events_page_link = eme_get_events_page();
- $payment_id = $payment['id'];
- $success_link = eme_payment_return_url( $payment, 0 );
- $fail_link = eme_payment_return_url( $payment, 1 );
- $notification_link = add_query_arg( [ 'eme_eventAction' => "{$gateway}_notification" ], $events_page_link );
+ $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
+ $payment_id = $payment['id'];
$description = eme_get_payment_desc( $item_name, $payment, $gateway, $multi_booking );
@@ -727,27 +723,21 @@
$button_below = get_option( 'eme_' . $gateway . '_button_below' );
$button_img_url = get_option( 'eme_' . $gateway . '_button_img_url' );
- require_once EME_PLUGIN_DIR . 'payment_gateways/webmoney/webmoney.inc.php';
- $wm_request = new WM_Request();
- $wm_request->payment_amount = $price;
- $wm_request->payment_desc = $description;
- $wm_request->payment_no = $payment_id;
- $wm_request->payee_purse = $eme_webmoney_purse;
- $wm_request->success_method = WM_POST;
- $wm_request->result_url = $notification_link;
- $wm_request->success_url = $success_link;
- $wm_request->fail_url = $fail_link;
- if ( get_option( 'eme_webmoney_demo' ) ) {
- $wm_request->sim_mode = WM_ALL_SUCCESS;
- }
- $wm_request->btn_label = $button_label;
- $wm_request->form_id = 'eme_webmoney_form';
+ $form_html = $button_above;
+ $form_html .= "<form action='' method='post' name='eme_{$gateway}_form' id='eme_{$gateway}_form'>
+ <input type='hidden' name='payment_id' value='$payment_id'>
+ <input type='hidden' name='eme_eventAction' value='{$gateway}_charge'>
+ <input type='hidden' name='description' value='$description'>
+ <input type='hidden' name='price' value='$price'>
+ <input type='hidden' name='cur' value='$cur'>
+ ";
if ( ! empty( $button_img_url ) ) {
- $wm_request->btn_img_url = $button_img_url;
+ $form_html .= "<input type='image' src='$button_img_url' alt='$button_label' title='$button_label' class='button-primary eme_submit_button'><br>";
+ } else {
+ $form_html .= "<input type='submit' value='$button_label' class='button-primary eme_submit_button'><br>";
}
-
- $form_html = $button_above;
- $form_html .= $wm_request->SetForm( false );
+ $form_html .= wp_nonce_field( "eme_{$gateway}_{$payment_id}_{$price}_{$cur}", "eme_{$gateway}_nonce", false, false );
+ $form_html .= '</form>';
$form_html .= $button_below;
return $form_html;
}
@@ -760,22 +750,11 @@
return;
}
- $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
- $events_page_link = eme_get_events_page();
- $payment_id = $payment['id'];
- // $success_link = eme_payment_return_url($payment,0);
- // $fail_link = eme_payment_return_url($payment,1);
- $notification_link = add_query_arg( [ 'eme_eventAction' => "{$gateway}_notification" ], $events_page_link );
+ $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
+ $payment_id = $payment['id'];
$description = eme_get_payment_desc( $item_name, $payment, $gateway, $multi_booking );
- if ( get_option( 'eme_worldpay_demo' ) == 1 ) {
- $url = 'https://secure-test.worldpay.com/wcc/purchase';
- } else {
- $url = 'https://secure.worldpay.com/wcc/purchase';
- }
- $quantity = 1;
-
$description = esc_html( $description );
$button_above = get_option( 'eme_' . $gateway . '_button_above' );
@@ -788,31 +767,19 @@
$button_img_url = get_option( 'eme_' . $gateway . '_button_img_url' );
$form_html = $button_above;
- $form_html .= "<form action='$url' method='post' name='eme_worldpay_form' id='eme_worldpay_form'>";
- $form_html .= "<input type='hidden' name='instId' value='$worldpay_instid'>";
- $form_html .= "<input type='hidden' name='cartId' value='$payment_id'>";
- $form_html .= "<input type='hidden' name='desc' value='$description'>";
- $form_html .= "<input type='hidden' name='amount' value='$price'>";
- $form_html .= "<input type='hidden' name='currency' value='$cur'>";
- // for worldpay notifications to work: enable dynamic payment response in your worldpay setup, using the param MC_callback
- // also: set the Payment Response password and if wanted, the MD5 secret and field combo
- $form_html .= "<input type='hidden' name='MC_callback' value='" . esc_url( $notification_link ) . "'>";
-
- if ( $worldpay_md5_secret ) {
- require_once EME_PLUGIN_DIR . 'payment_gateways/worldpay/eme-worldpay.php';
- $params_arr = explode( ':', get_option( 'eme_worldpay_md5_parameters' ) );
- $signature = eme_generate_worldpay_signature( $worldpay_md5_secret, $params_arr, $worldpay_instid, $payment_id, $cur, $price );
- $form_html .= "<input type='hidden' name='signature' value='$signature'>";
- }
-
+ $form_html .= "<form action='' method='post' name='eme_{$gateway}_form' id='eme_{$gateway}_form'>
+ <input type='hidden' name='payment_id' value='$payment_id'>
+ <input type='hidden' name='eme_eventAction' value='{$gateway}_charge'>
+ <input type='hidden' name='description' value='$description'>
+ <input type='hidden' name='price' value='$price'>
+ <input type='hidden' name='cur' value='$cur'>
+ ";
if ( ! empty( $button_img_url ) ) {
- $form_html .= "<input type='image' alt='$button_label' title='$button_label' src='$button_img_url' class='button-primary eme_submit_button'><br>";
+ $form_html .= "<input type='image' src='$button_img_url' alt='$button_label' title='$button_label' class='button-primary eme_submit_button'><br>";
} else {
$form_html .= "<input type='submit' value='$button_label' class='button-primary eme_submit_button'><br>";
}
- if ( get_option( 'eme_worldpay_demo' ) == 1 ) {
- $form_html .= "<input type='hidden' name='testMode' value='100'>";
- }
+ $form_html .= wp_nonce_field( "eme_{$gateway}_{$payment_id}_{$price}_{$cur}", "eme_{$gateway}_nonce", false, false );
$form_html .= '</form>';
$form_html .= $button_below;
return $form_html;
@@ -825,28 +792,11 @@
return;
}
- $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
- $events_page_link = eme_get_events_page();
- $payment_id = $payment['id'];
- $success_link = eme_payment_return_url( $payment, 0 );
- $fail_link = eme_payment_return_url( $payment, 1 );
- // opayo doesn't use a notification url, but sends the status along as part of the return url
- // so we add the notification info to it too, so we can process paid info as usual
- $success_link = add_query_arg( [ 'eme_eventAction' => "{$gateway}_notification" ], $success_link );
- $fail_link = add_query_arg( [ 'eme_eventAction' => "{$gateway}_notification" ], $fail_link );
+ $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
+ $payment_id = $payment['id'];
$description = eme_get_payment_desc( $item_name, $payment, $gateway, $multi_booking );
- // the live or sandbox url
- $opayo_demo = get_option( 'eme_opayo_demo' );
- if ( $opayo_demo == 1 ) {
- $opayo_pwd = get_option( 'eme_opayo_test_pwd' );
- $url = 'https://test.sagepay.com/gateway/service/vspform-register.vsp';
- } else {
- $opayo_pwd = get_option( 'eme_opayo_live_pwd' );
- $url = 'https://live.sagepay.com/gateway/service/vspform-register.vsp';
- }
-
$button_above = get_option( 'eme_' . $gateway . '_button_above' );
$button_label = get_option( 'eme_' . $gateway . '_button_label' );
if ( empty( $button_label ) ) {
@@ -856,62 +806,20 @@
$button_below = get_option( 'eme_' . $gateway . '_button_below' );
$button_img_url = get_option( 'eme_' . $gateway . '_button_img_url' );
- $person = [];
- if ( $payment['target'] == 'member' ) {
- $member = eme_get_member_by_paymentid( $payment_id );
- if ( $member ) {
- $person = eme_get_person( $member['person_id'] );
- }
- } elseif ( $payment['target'] == 'fs_event' ) {
- $person = eme_new_person();
- } else {
- $booking_ids = eme_get_payment_booking_ids( $payment_id );
- if ( $booking_ids ) {
- $booking = eme_get_booking( $booking_ids[0] );
- $person = eme_get_person( $booking['person_id'] );
- }
- }
- if ( empty( $person ) ) {
- $person = eme_new_person();
- }
-
- $query = [
- 'VendorTxCode' => $payment_id,
- 'Amount' => number_format( $price, 2, '.', '' ),
- 'Currency' => $cur,
- 'Description' => $description,
- 'SuccessURL' => $success_link,
- 'FailureURL' => $fail_link,
- 'BillingSurname' => $person['lastname'],
- 'BillingFirstnames' => $person['firstname'],
- 'BillingAddress1' => $person['address1'],
- 'BillingCity' => $person['city'],
- 'BillingPostCode' => $person['zip'],
- 'BillingState' => $person['state_code'],
- 'BillingCountry' => $person['country_code'],
- 'DeliverySurname' => $person['lastname'],
- 'DeliveryFirstnames' => $person['firstname'],
- 'DeliveryAddress1' => $person['address1'],
- 'DeliveryCity' => $person['city'],
- 'DeliveryPostCode' => $person['zip'],
- 'DeliveryState' => $person['state_code'],
- 'DeliveryCountry' => $person['country_code'],
- ];
-
- require_once EME_PLUGIN_DIR . 'payment_gateways/opayo/eme-opayo-util.php';
- $crypt = SagepayUtil::encryptAes( SagepayUtil::arrayToQueryString( $query ), $opayo_pwd );
-
$form_html = $button_above;
- $form_html .= "<form action='$url' method='post' name='eme_opayo_form' id='eme_opayo_form'>";
- $form_html .= "<input type='hidden' name='VPSProtocol' value='3.00'>";
- $form_html .= "<input type='hidden' name='TxType' value='PAYMENT'>";
- $form_html .= "<input type='hidden' name='Vendor' value='$vendor_name'>";
- $form_html .= "<input type='hidden' name='Crypt' value='$crypt'>";
+ $form_html .= "<form action='' method='post' name='eme_{$gateway}_form' id='eme_{$gateway}_form'>
+ <input type='hidden' name='payment_id' value='$payment_id'>
+ <input type='hidden' name='eme_eventAction' value='{$gateway}_charge'>
+ <input type='hidden' name='description' value='$description'>
+ <input type='hidden' name='price' value='$price'>
+ <input type='hidden' name='cur' value='$cur'>
+ ";
if ( ! empty( $button_img_url ) ) {
$form_html .= "<input type='image' src='$button_img_url' alt='$button_label' title='$button_label' class='button-primary eme_submit_button'><br>";
} else {
$form_html .= "<input type='submit' value='$button_label' class='button-primary eme_submit_button'><br>";
}
+ $form_html .= wp_nonce_field( "eme_{$gateway}_{$payment_id}_{$price}_{$cur}", "eme_{$gateway}_nonce", false, false );
$form_html .= '</form>';
$form_html .= $button_below;
return $form_html;
@@ -1174,36 +1082,19 @@
}
function eme_payment_form_fdgg( $item_name, $payment, $baseprice, $cur, $multi_booking = 0 ) {
- $gateway = 'fdgg';
- $store_name = get_option( 'eme_fdgg_store_name' );
- $shared_secret = get_option( 'eme_fdgg_shared_secret' );
+ $gateway = 'fdgg';
+ $store_name = get_option( 'eme_fdgg_store_name' );
if ( ! $store_name ) {
return;
}
- $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
- $events_page_link = eme_get_events_page();
- $payment_id = $payment['id'];
- $success_link = eme_payment_return_url( $payment, 0 );
- $fail_link = eme_payment_return_url( $payment, 1 );
+ $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
+ $payment_id = $payment['id'];
// we add the next lines to be conform with the others, but fdgg ignores the description
$description = eme_get_payment_desc( $item_name, $payment, $gateway, $multi_booking );
$description = esc_html( $description );
- // the live or sandbox url
- $mode = get_option( 'eme_fdgg_url' );
- if ( preg_match( '/sandbox|merchanttest/', $mode ) ) {
- $url = 'https://connect.merchanttest.firstdataglobalgateway.com/IPGConnect/gateway/processing';
- } else {
- $url = 'https://connect.firstdataglobalgateway.com/IPGConnect/gateway/processing';
- }
-
- $quantity = 1;
- $datetime = eme_localized_date( $payment['creation_date'], EME_TIMEZONE, 'Y:m:d-H:i:s' );
- $cur_codes = eme_currency_codes();
- $cur_code = $cur_codes[ $cur ];
-
$button_above = get_option( 'eme_' . $gateway . '_button_above' );
$button_label = get_option( 'eme_' . $gateway . '_button_label' );
if ( empty( $button_label ) ) {
@@ -1213,31 +1104,20 @@
$button_below = get_option( 'eme_' . $gateway . '_button_below' );
$button_img_url = get_option( 'eme_' . $gateway . '_button_img_url' );
- require_once EME_PLUGIN_DIR . 'payment_gateways/fdgg/fdgg-util_sha2.php';
- $hash = fdgg_createHash( $store_name . $datetime . $price . $cur_code . $shared_secret );
$form_html = $button_above;
- $form_html .= "<form action='$url' method='post' name='eme_fdgg_form' id='eme_fdgg_form'>";
- $form_html .= "<input type='hidden' name='timezone' value='EME_TIMEZONE'>";
- $form_html .= "<input type='hidden' name='authenticateTransaction' value='false'>";
- $form_html .= "<input type='hidden' name='txntype' value='sale'>";
- $form_html .= "<input type='hidden' name='mode' value='payonly'>";
- $form_html .= "<input type='hidden' name='trxOrigin' value='ECI'>";
- $form_html .= "<input type='hidden' name='txndatetime' value='$datetime'>";
- $form_html .= "<input type='hidden' name='hash_algorithm' value='SHA512'>";
- $form_html .= "<input type='hidden' name='hash' value='$hash'>";
- $form_html .= "<input type='hidden' name='storename' value='$store_name'>";
- $form_html .= "<input type='hidden' name='chargetotal' value='$price'>";
- $form_html .= "<input type='hidden' name='subtotal' value='$price'>";
- $form_html .= "<input type='hidden' name='invoicenumber' value='$payment_id'>";
- $form_html .= "<input type='hidden' name='oid' value='$payment_id'>";
- $form_html .= "<input type='hidden' name='responseSuccessURL' value='$success_link'>";
- $form_html .= "<input type='hidden' name='responseFailURL' value='$fail_link'>";
- $form_html .= "<input type='hidden' name='eme_eventAction' value='{$gateway}_notification'>";
+ $form_html .= "<form action='' method='post' name='eme_{$gateway}_form' id='eme_{$gateway}_form'>
+ <input type='hidden' name='payment_id' value='$payment_id'>
+ <input type='hidden' name='eme_eventAction' value='{$gateway}_charge'>
+ <input type='hidden' name='description' value='$description'>
+ <input type='hidden' name='price' value='$price'>
+ <input type='hidden' name='cur' value='$cur'>
+ ";
if ( ! empty( $button_img_url ) ) {
$form_html .= "<input type='image' src='$button_img_url' alt='$button_label' title='$button_label' class='button-primary eme_submit_button'><br>";
} else {
$form_html .= "<input type='submit' value='$button_label' class='button-primary eme_submit_button'><br>";
}
+ $form_html .= wp_nonce_field( "eme_{$gateway}_{$payment_id}_{$price}_{$cur}", "eme_{$gateway}_nonce", false, false );
$form_html .= '</form>';
$form_html .= $button_below;
return $form_html;
@@ -1432,13 +1312,8 @@
return;
}
- $quantity = 1;
- $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
- $events_page_link = eme_get_events_page();
- $payment_id = $payment['id'];
- $success_link = eme_payment_return_url( $payment, 0 );
- $cancel_link = eme_payment_url( $payment );
- $notification_link = add_query_arg( [ 'eme_eventAction' => "{$gateway}_notification" ], $events_page_link );
+ $price = eme_payment_gateway_total( $baseprice, $cur, $gateway );
+ $payment_id = $payment['id'];
$description = eme_get_payment_desc( $item_name, $payment, $gateway, $multi_booking );
@@ -1453,54 +1328,21 @@
$button_below = get_option( 'eme_' . $gateway . '_button_below' );
$button_img_url = get_option( 'eme_' . $gateway . '_button_img_url' );
- require_once EME_PLUGIN_DIR . 'payment_gateways/paypal_legacy/Paypal.php';
- $p = new Paypal();
-
- // the paypal or paypal sandbox url
- $mode = get_option( 'eme_legacypaypal_url' );
- if ( preg_match( '/sandbox/', $mode ) ) {
- $p->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
- } else {
- $p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';
- }
-
- // the timeout in seconds before the button form is submitted to paypal
- // this needs the included addevent javascript function
- // 0 = no delay
- // false = disable auto submission
- $p->timeout = false;
-
- // the button label
- // false to disable button (if you want to rely only on the javascript auto-submission) not recommended
- $p->form_id = 'eme_legacypaypal_form';
- $p->button = $button_label;
+ $form_html = $button_above;
+ $form_html .= "<form action='' method='post' name='eme_{$gateway}_form' id='eme_{$gateway}_form'>
+ <input type='hidden' name='payment_id' value='$payment_id'>
+ <input type='hidden' name='eme_eventAction' value='{$gateway}_charge'>
+ <input type='hidden' name='description' value='$description'>
+ <input type='hidden' name='price' value='$price'>
+ <input type='hidden' name='cur' value='$cur'>
+ ";
if ( ! empty( $button_img_url ) ) {
- $p->button_img_url = $button_img_url;
- }
-
- // no encryption, use the new paypal for that
- $p->encrypt = false;
-
- // the actual button parameters
- // https://www.paypal.com/IntegrationCenter/ic_std-variable-reference.html
- $p->add_field( 'charset', 'utf-8' );
- $p->add_field( 'business', $eme_paypal_business );
- $p->add_field( 'return', $success_link );
- $p->add_field( 'cancel_return', $cancel_link );
- $p->add_field( 'notify_url', $notification_link );
- $p->add_field( 'item_name', $description );
- $p->add_field( 'item_number', $payment_id );
- $p->add_field( 'custom', $payment_id );
- $p->add_field( 'currency_code', $cur );
- $p->add_field( 'amount', $price );
- $p->add_field( 'quantity', $quantity );
- $p->add_field( 'no_shipping', 1 );
- if ( get_option( 'eme_legacypaypal_no_tax' ) ) {
- $p->add_field( 'tax', 0 );
+ $form_html .= "<input type='image' src='$button_img_url' alt='$button_label' title='$button_label' class='button-primary eme_submit_button'><br>";
+ } else {
+ $form_html .= "<input type='submit' value='$button_label' class='button-primary eme_submit_button'><br>";
}
-
- $form_html = $button_above;
- $form_html .= $p->get_button();
+ $form_html .= wp_nonce_field( "eme_{$gateway}_{$payment_id}_{$price}_{$cur}", "eme_{$gateway}_nonce", false, false );
+ $form_html .= '</form>';
$form_html .= $button_below;
return $form_html;
}
@@ -1664,7 +1506,7 @@
try {
$response = $api->paymentRequestPaymentStatus( $instamojo_requestid, $instamojo_paymentid );
if ( $response['payment']['status'] == 'Credit' ) {
- $expected_price = eme_get_payment_price( $payment['id'] );
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment['id'] ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
$amount_paid = floatval( $response['payment']['amount'] );
if ( $amount_paid < $expected_price - 0.01 ) {
error_log( "EME instamojo completion price mismatch for payment {$payment['id']}: paid $amount_paid, expected $expected_price" );
@@ -1692,7 +1534,7 @@
return false;
}
if ( $checkout->status == 'PAID' ) {
- $expected_price = eme_get_payment_price( $payment['id'] );
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment['id'] ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
$amount_paid = floatval( $checkout->amount );
if ( $amount_paid < $expected_price - 0.01 ) {
error_log( "EME sumup completion price mismatch for payment {$payment['id']}: paid $amount_paid, expected $expected_price" );
@@ -1721,9 +1563,9 @@
return false;
}
if ( $stripe_pi->status == 'succeeded' ) {
- $expected_price = eme_get_payment_price( $payment_id );
- $amount_paid = $stripe_session->amount_total / 100;
- if ( $amount_paid < $expected_price - 0.01 ) {
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment_id ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
+ $amount_paid = $stripe_session->amount_total;
+ if ( $amount_paid < $expected_price - 1 ) {
error_log( "EME stripe completion price mismatch for payment $payment_id: paid $amount_paid, expected $expected_price" );
}
// we store the payment intent id, so we can refund later
@@ -1745,7 +1587,7 @@
$response = $client->capture_order( $paypal_orderid );
if ( $response['status'] === 'COMPLETED' ) {
$capture_id = $response['purchase_units'][0]['payments']['captures'][0]['id'] ?? $paypal_orderid;
- $expected_price = eme_get_payment_price( $payment['id'] );
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment['id'] ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), 'paypal' );
$amount_paid = floatval( $response['purchase_units'][0]['payments']['captures'][0]['amount']['value'] );
if ( $amount_paid < $expected_price - 0.01 ) {
error_log( "EME paypal completion price mismatch for payment {$payment['id']}: paid $amount_paid, expected $expected_price" );
@@ -1830,9 +1672,9 @@
$order = $orderStatus->getData();
if ( $order['order_status'] == 'approved' ) {
- $expected_price = eme_get_payment_price( $payment['id'] );
- $amount_paid = $order['amount'] / 100;
- if ( $amount_paid < $expected_price - 0.01 ) {
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment['id'] ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
+ $amount_paid = $order['amount'];
+ if ( $amount_paid < $expected_price - 1 ) {
error_log( "EME fondy completion price mismatch for payment {$payment['id']}: paid $amount_paid, expected $expected_price" );
}
eme_mark_payment_paid( $payment['id'], 1, $gateway, $order_id );
@@ -1869,7 +1711,7 @@
$mac_calculated = hash_hmac( 'sha1', implode( '|', $data ), $instamojo_salt );
if ( $mac_provided == $mac_calculated ) {
if ( $data['status'] == 'Credit' ) {
- $expected_price = eme_get_payment_price( $payment['id'] );
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment['id'] ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
$instamojo_amount = floatval( $data['amount'] );
if ( $instamojo_amount < $expected_price - 0.01 ) {
error_log( "EME instamojo notification price mismatch for payment {$payment['id']}: paid $instamojo_amount, expected $expected_price" );
@@ -1927,8 +1769,8 @@
}
// If the payment's transaction amount is equal (or bigger) than the merchant_order's amount you can release your items
- $eme_price = eme_get_payment_price( $payment_id );
- if ( $paid_amount >= $merchant_order->total_amount && $paid_amount >= $eme_price ) {
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment_id ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
+ if ( $paid_amount >= $merchant_order->total_amount && $paid_amount >= $expected_price ) {
eme_mark_payment_paid( $payment_id, 1, $gateway, $mercadopago_paymentid );
http_response_code( 200 );
} else {
@@ -1952,8 +1794,8 @@
http_response_code( 400 );
return;
}
- $eme_price = eme_get_payment_price( $payment_id );
- if ( $paid_amount >= $eme_price ) {
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment_id ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
+ if ( $paid_amount >= $expected_price ) {
eme_mark_payment_paid( $payment_id, 1, $gateway, $mercadopago_paymentid );
http_response_code( 200 );
} else {
@@ -2026,7 +1868,7 @@
return;
}
// Verify amount meets expectation
- $expected_price = eme_get_payment_price( $payment_id );
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment_id ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
$received_amount = floatval( $ipn->ipn['mc_gross'] );
if ( $received_amount < $expected_price - 0.01 ) {
error_log( "EME paypal notification price mismatch for payment $payment_id: paid $received_amount, expected $expected_price" );
@@ -2049,7 +1891,9 @@
die( 'Not the webmoney purse it should be ...' );
}
$payment_id = intval( $wm_notif->payment_no );
- $expected_price = eme_get_payment_price( $payment_id );
+ $payment = eme_get_payment( $payment_id );
+ $cur = ( is_array( $payment ) && ! empty( $payment['currency'] ) ) ? $payment['currency'] : get_option( 'eme_default_currency' );
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment_id ), $cur, $gateway );
if ( $amount < $expected_price - 0.01 ) {
error_log( "EME webmoney notification price mismatch for payment $payment_id: paid $amount, expected $expected_price" );
}
@@ -2118,9 +1962,9 @@
wp_die( esc_html__( 'Hash Incorrect', 'events-made-easy' ) );
}
- $expected_price = eme_get_payment_price( $payment_id );
+ $expected_price = eme_payment_gateway_total( eme_get_payment_price( $payment['id'] ), ! empty( $payment['currency'] ) ? $payment['currency'] : get_option( 'eme_default_currency' ), $gateway );
if ( $charge_total < $expected_price - 0.01 ) {
- error_log( "EME mercadopago notification price mismatch for payment $payment_id: paid $charge_total, expe