Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/meta-box/inc/fields/file-input.php
+++ b/meta-box/inc/fields/file-input.php
@@ -41,7 +41,7 @@
<a href="#" class="rwmb-file-input-remove button %s">%s</a>
</div>',
in_array( $file_ext, $extensions, true ) ? '' : 'rwmb-file-input-hidden',
- $meta,
+ esc_url( $meta ),
self::render_attributes( $attributes ),
esc_html__( 'Select', 'meta-box' ),
$meta ? '' : 'hidden',
--- a/meta-box/inc/fields/map.php
+++ b/meta-box/inc/fields/map.php
@@ -193,6 +193,9 @@
'openInfoWindow' => false,
] );
+ // Google Maps renders the info window as HTML.
+ $args['info_window'] = is_string( $args['info_window'] ) ? wp_kses_post( $args['info_window'] ) : '';
+
$output = sprintf(
'<div class="rwmb-map-canvas" data-map_options="%s" style="width:%s;height:%s"></div>',
esc_attr( wp_json_encode( $args ) ),
--- a/meta-box/inc/fields/object-choice.php
+++ b/meta-box/inc/fields/object-choice.php
@@ -86,6 +86,10 @@
/**
* Set ajax parameters.
*
+ * For core Ajax actions, `field` is a JSON string and the nonce is made from it.
+ * If a visitor changes a value, the nonce is not correct.
+ * Custom Ajax actions keep the old array format. They must check the request themselves.
+ *
* @param array $field Field settings.
*/
protected static function set_ajax_params( &$field ) {
@@ -96,24 +100,17 @@
if ( empty( $field['js_options']['ajax'] ) ) {
$field['js_options']['ajax'] = [];
}
- $field['js_options']['ajax'] = wp_parse_args(
+ $field['js_options']['ajax'] = wp_parse_args(
[
'url' => admin_url( 'admin-ajax.php' ),
],
$field['js_options']['ajax']
);
- $field_data = [
- 'id' => $field['id'],
- 'type' => $field['type'],
- 'query_args' => $field['query_args'],
- ];
- // Keep ajax_action inside field (not top-level ajax_data): select-advanced.js
- // strips data.action from the cache key, so two fields with the same type +
- // query_args but different ajax_action would otherwise share a cache entry.
+
$ajax_action = $field['ajax_action'] ?? '';
$ajax_action = is_string( $ajax_action ) ? sanitize_key( $ajax_action ) : '';
if ( ! $ajax_action ) {
- $actions = [
+ $actions = [
'post' => 'rwmb_get_posts',
'taxonomy' => 'rwmb_get_terms',
'taxonomy_advanced' => 'rwmb_get_terms',
@@ -121,9 +118,34 @@
];
$ajax_action = $actions[ $field['type'] ] ?? '';
}
+
+ $field_data = [
+ 'id' => $field['id'],
+ 'type' => $field['type'],
+ 'query_args' => $field['query_args'],
+ ];
+ // Keep ajax_action inside field (not top-level ajax_data): select-advanced.js
+ // strips data.action from the cache key, so two fields with the same type +
+ // query_args but different ajax_action would otherwise share a cache entry.
if ( $ajax_action ) {
$field_data['ajax_action'] = $ajax_action;
}
+ if ( array_key_exists( 'display_field', $field ) ) {
+ $field_data['display_field'] = $field['display_field'];
+ }
+ if ( array_key_exists( 'show_thumbnail', $field ) ) {
+ $field_data['show_thumbnail'] = (bool) $field['show_thumbnail'];
+ }
+
+ if ( in_array( $ajax_action, [ 'rwmb_get_posts', 'rwmb_get_terms', 'rwmb_get_users' ], true ) ) {
+ $payload = wp_json_encode( $field_data );
+ $field['js_options']['ajax_data'] = [
+ 'field' => $payload,
+ '_wpnonce' => wp_create_nonce( 'rwmb-query-' . $payload ),
+ ];
+ return;
+ }
+
$field['js_options']['ajax_data'] = [
'field' => $field_data,
'_wpnonce' => wp_create_nonce( 'query' ),
@@ -131,6 +153,30 @@
}
/**
+ * Get the field settings from a core Ajax request.
+ * Stop the request if the nonce or the action is not correct.
+ *
+ * @return array
+ */
+ protected static function get_ajax_field(): array {
+ $request = rwmb_request();
+ $payload = $request->post( 'field' );
+ $payload = is_string( $payload ) ? wp_unslash( $payload ) : '';
+
+ check_ajax_referer( 'rwmb-query-' . $payload );
+
+ $field = json_decode( $payload, true );
+ if ( $field['ajax_action'] !== $request->post( 'action' ) ) {
+ wp_die( -1, 403 );
+ }
+
+ $field['clone'] = false;
+ $field['_original_id'] = $field['id'];
+
+ return $field;
+ }
+
+ /**
* Get the attributes for a field.
*
* @param array $field Field parameters.
--- a/meta-box/inc/fields/osm.php
+++ b/meta-box/inc/fields/osm.php
@@ -157,6 +157,9 @@
'zoom' => $args['zoom'],
] );
+ // Leaflet renders the info window as HTML.
+ $args['info_window'] = is_string( $args['info_window'] ) ? wp_kses_post( $args['info_window'] ) : '';
+
$output = sprintf(
'<div class="rwmb-osm-canvas" data-osm_options="%s" style="width:%s;height:%s"></div>',
esc_attr( wp_json_encode( $args ) ),
--- a/meta-box/inc/fields/post.php
+++ b/meta-box/inc/fields/post.php
@@ -20,15 +20,8 @@
}
public static function ajax_get_posts() {
- check_ajax_referer( 'query' );
-
$request = rwmb_request();
-
- $field = $request->filter_post( 'field', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
-
- // Required for 'choice_label' filter. See self::filter().
- $field['clone'] = false;
- $field['_original_id'] = $field['id'];
+ $field = self::get_ajax_field();
// Search.
$field['query_args']['s'] = $request->filter_post( 'term' );
@@ -47,7 +40,7 @@
$data = [ 'items' => $items ];
// More items for pagination.
- $limit = (int) $field['query_args']['posts_per_page'];
+ $limit = (int) ( $field['query_args']['posts_per_page'] ?? -1 );
if ( -1 !== $limit && count( $items ) === $limit ) {
$data['more'] = true;
}
@@ -105,8 +98,6 @@
'posts_per_page' => $posts_per_page,
] );
- parent::set_ajax_params( $field );
-
if ( 'select_advanced' === $field['field_type'] ) {
$supports = false;
foreach ( $field['post_type'] as $pt ) {
@@ -118,11 +109,10 @@
$field['show_thumbnail'] = $supports;
$field['js_options']['show_thumbnail'] = $supports;
- if ( $supports && ! empty( $field['js_options']['ajax_data']['field'] ) ) {
- $field['js_options']['ajax_data']['field']['show_thumbnail'] = true;
- }
}
+ parent::set_ajax_params( $field );
+
return $field;
}
--- a/meta-box/inc/fields/range.php
+++ b/meta-box/inc/fields/range.php
@@ -19,7 +19,7 @@
<span class="rwmb-range-output">%s</span>
</div>',
parent::html( $meta, $field ),
- $meta
+ esc_html( $meta )
);
}
--- a/meta-box/inc/fields/slider.php
+++ b/meta-box/inc/fields/slider.php
@@ -39,10 +39,10 @@
</div>',
esc_attr( $field['id'] ),
esc_attr( wp_json_encode( $field['js_options'] ) ),
- $field['prefix'],
- $meta,
- $field['suffix'],
- $meta,
+ wp_kses_post( $field['prefix'] ),
+ esc_html( $meta ),
+ wp_kses_post( $field['suffix'] ),
+ esc_attr( $meta ),
self::render_attributes( $attributes )
);
}
--- a/meta-box/inc/fields/taxonomy.php
+++ b/meta-box/inc/fields/taxonomy.php
@@ -11,15 +11,8 @@
}
public static function ajax_get_terms() {
- check_ajax_referer( 'query' );
-
$request = rwmb_request();
-
- $field = $request->filter_post( 'field', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
-
- // Required for 'choice_label' filter. See self::filter().
- $field['clone'] = false;
- $field['_original_id'] = $field['id'];
+ $field = self::get_ajax_field();
// Search.
$field['query_args']['name__like'] = $request->filter_post( 'term' );
--- a/meta-box/inc/fields/user.php
+++ b/meta-box/inc/fields/user.php
@@ -21,15 +21,8 @@
}
public static function ajax_get_users() {
- check_ajax_referer( 'query' );
-
$request = rwmb_request();
-
- $field = $request->filter_post( 'field', FILTER_DEFAULT, FILTER_FORCE_ARRAY );
-
- // Required for 'choice_label' filter. See self::filter().
- $field['clone'] = false;
- $field['_original_id'] = $field['id'];
+ $field = self::get_ajax_field();
// Search.
$term = (string) $request->filter_post( 'term' );
@@ -95,20 +88,13 @@
'number' => $limit,
] );
- parent::set_ajax_params( $field );
-
- if ( $field['ajax'] ) {
- $field['js_options']['ajax_data']['field']['display_field'] = $field['display_field'];
- }
-
if ( 'select_advanced' === $field['field_type'] ) {
$field['show_thumbnail'] = true;
$field['js_options']['show_thumbnail'] = true;
- if ( ! empty( $field['js_options']['ajax_data']['field'] ) ) {
- $field['js_options']['ajax_data']['field']['show_thumbnail'] = true;
- }
}
+ parent::set_ajax_params( $field );
+
return $field;
}
@@ -116,8 +102,10 @@
$display_field = $field['display_field'];
$args = wp_parse_args( $field['query_args'], [
- 'orderby' => $display_field,
- 'order' => 'asc',
+ 'orderby' => $display_field,
+ 'order' => 'asc',
+ // If the search term has "@", WordPress also searches user_email. This lets visitors find emails.
+ 'search_columns' => [ 'user_login', 'user_nicename', 'display_name' ],
] );
$args['fields'] = [
--- a/meta-box/inc/fields/wysiwyg.php
+++ b/meta-box/inc/fields/wysiwyg.php
@@ -67,8 +67,16 @@
$field['options'] = wp_parse_args( $field['options'], [
'editor_class' => 'rwmb-wysiwyg',
'dfw' => true, // Use default WordPress full screen UI.
+ 'tinymce' => [],
] );
+ // TinyMCE unwraps <span> without attributes. Re-declare it first, so user-defined span rules still win.
+ if ( is_array( $field['options']['tinymce'] ) ) {
+ $span = 'span[id|accesskey|class|dir|lang|style|tabindex|title|role|contenteditable|contextmenu|draggable|dropzone|hidden|spellcheck|translate]';
+
+ $field['options']['tinymce']['extended_valid_elements'] = trim( $span . ',' . ( $field['options']['tinymce']['extended_valid_elements'] ?? '' ), ',' );
+ }
+
// Keep the filter to be compatible with previous versions.
$field['options'] = apply_filters( 'rwmb_wysiwyg_settings', $field['options'] );
--- a/meta-box/inc/loader.php
+++ b/meta-box/inc/loader.php
@@ -7,7 +7,7 @@
class RWMB_Loader {
protected function constants() {
// Script version, used to add version for scripts and styles.
- define( 'RWMB_VER', '5.15.3' );
+ define( 'RWMB_VER', '5.15.4' );
list( $path, $url ) = self::get_path( dirname( __DIR__ ) );
--- a/meta-box/meta-box.php
+++ b/meta-box/meta-box.php
@@ -3,7 +3,7 @@
* Plugin Name: Meta Box
* Plugin URI: https://metabox.io
* Description: Create custom meta boxes and custom fields in WordPress.
- * Version: 5.15.3
+ * Version: 5.15.4
* Author: MetaBox.io
* Author URI: https://metabox.io
* License: GPL2+
--- a/meta-box/src/Abilities.php
+++ b/meta-box/src/Abilities.php
@@ -95,12 +95,13 @@
'additionalProperties' => false,
],
'meta' => [
- 'annotations' => [
+ 'show_in_rest' => true,
+ 'annotations' => [
'readonly' => true,
'destructive' => false,
'openWorldHint' => false,
],
- 'mcp' => [
+ 'mcp' => [
'public' => true,
'type' => 'tool',
],
@@ -137,12 +138,13 @@
'additionalProperties' => false,
],
'meta' => [
- 'annotations' => [
+ 'show_in_rest' => true,
+ 'annotations' => [
'readonly' => true,
'destructive' => false,
'openWorldHint' => false,
],
- 'mcp' => [
+ 'mcp' => [
'public' => true,
'type' => 'tool',
],
@@ -169,13 +171,14 @@
'additionalProperties' => false,
],
'meta' => [
- 'annotations' => [
+ 'show_in_rest' => true,
+ 'annotations' => [
'readonly' => false,
'destructive' => false,
'idempotent' => true,
'openWorldHint' => false,
],
- 'mcp' => [
+ 'mcp' => [
'public' => true,
'type' => 'tool',
],
@@ -202,12 +205,13 @@
'additionalProperties' => false,
],
'meta' => [
- 'annotations' => [
+ 'show_in_rest' => true,
+ 'annotations' => [
'readonly' => false,
'destructive' => true,
'openWorldHint' => false,
],
- 'mcp' => [
+ 'mcp' => [
'public' => true,
'type' => 'tool',
],
--- a/meta-box/vendor/composer/installed.php
+++ b/meta-box/vendor/composer/installed.php
@@ -1,9 +1,9 @@
<?php return array(
'root' => array(
'name' => 'wpmetabox/meta-box',
- 'pretty_version' => '5.15.3',
- 'version' => '5.15.3.0',
- 'reference' => 'cff65939cdc6e65aea04aa4f2f214f7de8224f12',
+ 'pretty_version' => '5.15.4',
+ 'version' => '5.15.4.0',
+ 'reference' => '6d5b6e7c0acdeb2c4a708ef9b0a54a6b11c61504',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -11,9 +11,9 @@
),
'versions' => array(
'wpmetabox/meta-box' => array(
- 'pretty_version' => '5.15.3',
- 'version' => '5.15.3.0',
- 'reference' => 'cff65939cdc6e65aea04aa4f2f214f7de8224f12',
+ 'pretty_version' => '5.15.4',
+ 'version' => '5.15.4.0',
+ 'reference' => '6d5b6e7c0acdeb2c4a708ef9b0a54a6b11c61504',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),