Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/events-manager/classes/em-calendar.php
+++ b/events-manager/classes/em-calendar.php
@@ -16,8 +16,16 @@
$original_args = $args;
$args = self::get_default_search($args);
if( !empty($args['format']) ) {
- // escape the format if supplied via $_REQUEST, we are abundantly cautious here and won't test for a match, in case there's any kind of difference due to escaping, encoding etc.
if( !empty($_REQUEST['format']) ) {
+ // placeholders such as #_CONTACTMETA and #_ATTENDEESLIST expand server-side, so a request may only send back a format this site signed when it output the calendar
+ $args['format'] = wp_unslash( $args['format'] );
+ $format_sig = !empty($_REQUEST['format_sig']) && is_string($_REQUEST['format_sig']) ? $_REQUEST['format_sig'] : '';
+ if( !is_string($args['format']) || !hash_equals( static::get_format_signature($args['format']), $format_sig ) ) {
+ $args['format'] = '';
+ }
+ }
+ // escape a signed format too, we are abundantly cautious here in case there's any kind of difference due to escaping, encoding etc.
+ if( !empty($args['format']) && !empty($_REQUEST['format']) ) {
global $allowedposttags;
// for optimal performance, if you do not need to use HTML in your formats (for example, if just outputting #_EVENTIMAGE for example), we recommend you add this to your functions.php or similar:
// add_filter('em_calendar_allowed_format_html', '__return_empty_array');
@@ -32,6 +40,8 @@
$args['format'] = wp_kses( $args['format'], $allowed_format_html );
}
}
+ }
+ if( !empty($args['format']) ) {
$calendar_array['format'] = $args['format'];
} else {
// get the default format, future iterations will also deduce the format for different display styles.
@@ -608,6 +618,9 @@
$custom_args['calendar'][$name] = $value;
}
}
+ foreach( $custom_args as $group => $group_args ){
+ if( !empty($group_args['format']) ) $custom_args[$group]['format_sig'] = static::get_format_signature( $group_args['format'] );
+ }
?>
<form class="em-view-custom-data-search" id="em-view-custom-data-search-<?php echo absint($args['id']); ?>">
<?php foreach( array_merge($custom_args['search'], $custom_args['global']) as $name => $value ): ?>
@@ -628,6 +641,15 @@
}
+ /**
+ * Signs a calendar format so that it can be sent back by a request, such as when navigating months, without letting a request supply a format of its own.
+ * @param string $format
+ * @return string
+ */
+ public static function get_format_signature( $format ){
+ return wp_hash( 'em_calendar_format|' . $format );
+ }
+
public static function days_in_month($month, $year) {
return date('t', mktime(0,0,0,$month,1,$year));
}
--- a/events-manager/classes/em-event.php
+++ b/events-manager/classes/em-event.php
@@ -2608,6 +2608,17 @@
$format = $this->get_option( 'dbem_single_event_format' );
return apply_filters('em_event_output_single', $this->output($format, $target), $this, $target);
}
+
+ /**
+ * Whether #_CONTACTMETA may output a user meta key. Protected keys (leading underscore), keys prefixed with the database prefix such as capabilities, and session tokens are refused, since formats can reach visitors.
+ * @param string $meta_key
+ * @return bool
+ */
+ public static function is_contact_meta_key_allowed( $meta_key ){
+ global $wpdb;
+ $allowed = is_string($meta_key) && !is_protected_meta($meta_key, 'user') && strpos($meta_key, $wpdb->base_prefix) !== 0 && !in_array($meta_key, array('session_tokens', 'user_pass', 'user_activation_key', 'default_password_nag'), true);
+ return apply_filters('em_event_contact_meta_key_allowed', $allowed, $meta_key);
+ }
/**
* Will output a event in the format passed in $format by replacing placeholders within the format.
@@ -3306,8 +3317,9 @@
}
break;
case '#_CONTACTMETA':
- if( !empty($placeholders[3][$key]) ){
+ if( !empty($placeholders[3][$key]) && static::is_contact_meta_key_allowed($placeholders[3][$key]) ){
$replace = get_user_meta($this->event_owner, $placeholders[3][$key], true);
+ if( !is_scalar($replace) ) $replace = '';
}
break;
case '#_ATTENDEES':
--- a/events-manager/classes/em-object.php
+++ b/events-manager/classes/em-object.php
@@ -302,7 +302,7 @@
$is_location_status = $status_type == "location_status" && static::$context == 'location';
$is_event_status = $status_type == "event_status" && static::$context == 'event';
//$is_joined_status decides whether this status we're dealing with is part of a joined table or the main table
- $is_joined_status = (!$is_location_status || !$is_event_status) && $args[$status_type] !== false;
+ $is_joined_status = !$is_location_status && !$is_event_status && $args[$status_type] !== false;
//we add a status condition if this is the main status context or if joining a table and joined status arg is not exactly false
if( $is_location_status || $is_event_status || $args[$status_type] !== false ){
$condition_status = $is_joined_status ? $status_type : 'status'; //the key for this condition type
--- a/events-manager/classes/lib/wp-oauth-app-passwords/src/Scope_Guard.php
+++ b/events-manager/classes/lib/wp-oauth-app-passwords/src/Scope_Guard.php
@@ -20,6 +20,10 @@
public static function boot(): void {
add_action( 'application_password_did_authenticate', array( static::class, 'on_authenticated' ), 10, 2 );
add_filter( 'rest_pre_dispatch', array( static::class, 'enforce' ), 0, 3 );
+ // Scope can only be checked on the REST transport. WordPress also accepts Application Passwords over XML-RPC and any other non-REST surface, where no scope check runs, so a route-restricted credential is refused there outright rather than acting with the user's full capabilities.
+ add_filter( 'determine_current_user', array( static::class, 'enforce_non_rest' ), 30 );
+ // The XML-RPC login path authenticates through the `authenticate` filter rather than determine_current_user (e.g. the app password passed as the XML-RPC password argument), so it is refused there too.
+ add_filter( 'authenticate', array( static::class, 'enforce_authenticate' ), 30, 3 );
}
/**
@@ -43,6 +47,40 @@
}
/**
+ * Refuse a route-restricted credential of ours on any non-REST request. on_authenticated() has already run by this priority and set self::$allowed when one of our passwords authenticated; a restricted scope cannot be honoured off REST, so the request is left unauthenticated rather than granting the user's full capabilities (for example over XML-RPC).
+ *
+ * @param int|false|null $user_id
+ * @return int|false|null
+ */
+ public static function enforce_non_rest( $user_id ) {
+ if ( empty( $user_id ) || null === self::$allowed ) {
+ return $user_id;
+ }
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
+ return $user_id;
+ }
+ return null;
+ }
+
+ /**
+ * As enforce_non_rest(), but for the `authenticate` filter that the XML-RPC login path runs through. on_authenticated() fires during core's app-password check on this same filter, so by this priority self::$allowed reflects whether one of our route-restricted passwords just authenticated.
+ *
+ * @param null|WP_User|WP_Error $user
+ * @param string $username
+ * @param string $password
+ * @return null|WP_User|WP_Error
+ */
+ public static function enforce_authenticate( $user, $username, $password ) {
+ if ( ! $user instanceof WP_User || null === self::$allowed ) {
+ return $user;
+ }
+ if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
+ return $user;
+ }
+ return new WP_Error( 'insufficient_scope', __( 'This credential is limited to the features it was approved for and cannot be used here.', 'wp-oauth-app-passwords' ) );
+ }
+
+ /**
* @param mixed $result
* @param WP_REST_Server $server
* @param WP_REST_Request $request
--- a/events-manager/classes/uploads/em-uploads-uploader.php
+++ b/events-manager/classes/uploads/em-uploads-uploader.php
@@ -302,9 +302,9 @@
// Use mime_content_type to guess the MIME type; you may use other libraries for more reliability.
$file_type = mime_content_type( $stored_file );
- if ( !empty($REQUEST[$file_key.'--names'][$file_id]) ) {
- $file_name = $REQUEST[$file_key.'--names'][$file_id];
- } else {
+ // the display name comes from the submitter and is shown to admins, so it is stored as plain text
+ $file_name = !empty($REQUEST[$file_key.'--names'][$file_id]) && is_string($REQUEST[$file_key.'--names'][$file_id]) ? sanitize_text_field( $REQUEST[$file_key.'--names'][$file_id] ) : '';
+ if ( $file_name === '' ) {
$file_name = $file_id;
}
--- a/events-manager/em-actions.php
+++ b/events-manager/em-actions.php
@@ -356,9 +356,13 @@
//ADD/EDIT Booking
ob_start();
em_verify_booking_nonce('booking_add');
+ // Authorise against the booking's persisted event before get_post() re-assigns event_id from the request. Otherwise a user could pass another user's booking_id together with an event they manage and have that booking re-saved onto their event, the same substitution already guarded in booking_form_summary. A new booking (no booking_id) is unaffected.
+ $can_edit_booking = empty($EM_Booking->booking_id) || $EM_Booking->can_manage('manage_bookings','manage_others_bookings') || ( is_user_logged_in() && !empty($EM_Booking->person->ID) && $EM_Booking->person->ID == get_current_user_id() );
if( !is_user_logged_in() || $EM_Booking->get_option('dbem_bookings_double') || !$EM_Event->get_bookings()->has_booking(get_current_user_id()) ){
if ( $EM_Event->event_status != 1 || $EM_Event->event_active_status != 1 ) {
$EM_Notices->add_error( __('This event is not available or has been cancelled', 'events-manager') ); // uncommon, not needed for custom error.
+ } elseif ( !$can_edit_booking ) {
+ $EM_Notices->add_error( __('You do not have permission to manage this booking.', 'events-manager') );
} else {
$EM_Booking->get_post();
$post_validation = $EM_Booking->validate();
--- a/events-manager/events-manager.php
+++ b/events-manager/events-manager.php
@@ -1,7 +1,7 @@
<?php
/*
Plugin Name: Events Manager
-Version: 7.4.10
+Version: 7.4.11
Plugin URI: https://wp-events-plugin.com
Description: Event registration and booking management for WordPress. Recurring events, locations, webinars, google maps, rss, ical, booking registration and more!
Author: Pixelite
@@ -30,7 +30,7 @@
// Setting constants
use EMArchetypes;
-define('EM_VERSION', '7.4.10'); //self expanatory, although version currently may not correspond directly with published version number. until 6.0 we're stuck updating 5.999.x
+define('EM_VERSION', '7.4.11'); //self expanatory, although version currently may not correspond directly with published version number. until 6.0 we're stuck updating 5.999.x
define('EM_PRO_MIN_VERSION', '3.9'); //self expanatory
define('EM_PRO_MIN_VERSION_CRITICAL', '3.6.0.2'); //self expanatory
define('EM_FILE', __FILE__); //an absolute path to this directory