Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/integromat-connector/class/class-api-permissions.php
+++ b/integromat-connector/class/class-api-permissions.php
@@ -59,9 +59,10 @@
*
* @param string $endpoint The REST endpoint being accessed
* @param string $method HTTP method
+ * @param bool $allow_discovery Pass false when authorizing custom meta. The route itself stays allowed.
* @return bool
*/
- public static function check_permission( $endpoint, $method ) {
+ public static function check_permission( $endpoint, $method, $allow_discovery = true ) {
// Only apply API permissions to requests from Make (those with IWC-API-KEY header)
if ( ! isset( $_SERVER['HTTP_IWC_API_KEY'] ) || empty( $_SERVER['HTTP_IWC_API_KEY'] ) ) {
// If no IWC-API-KEY header, this is not a Make request - use standard WordPress permissions
@@ -69,12 +70,12 @@
}
// Allow /users/me endpoint without granular permissions for API key verification
- if ( $method === 'GET' && preg_match( '#^/?wp/v2/users/me/?$#', $endpoint ) ) {
+ if ( $allow_discovery && $method === 'GET' && preg_match( '#^/?wp/v2/users/me/?$#', $endpoint ) ) {
return true; // Always allow this endpoint for API key verification
}
// Allow discovery endpoints without granular permissions for content type and taxonomy discovery
- if ( $method === 'GET' && preg_match( '#^/?wp/v2/(types|tags|categories)/?$#', $endpoint ) ) {
+ if ( $allow_discovery && $method === 'GET' && preg_match( '#^/?wp/v2/(types|tags|categories)/?$#', $endpoint ) ) {
return true; // Always allow these endpoints for content/taxonomy discovery
}
--- a/integromat-connector/class/class-rest-request.php
+++ b/integromat-connector/class/class-rest-request.php
@@ -323,7 +323,20 @@
// Get appropriate functions for this content type
$functions = isset( $meta_functions[ $content_type ] ) ? $meta_functions[ $content_type ] : $meta_functions['default'];
+ $object_type = 'post';
+ if ( 'users' === $content_type ) {
+ $object_type = 'user';
+ } elseif ( 'comments' === $content_type ) {
+ $object_type = 'comment';
+ } elseif ( 'tags' === $content_type || 'categories' === $content_type ) {
+ $object_type = 'term';
+ }
+
foreach ( $meta_fields as $meta_key => $meta_value ) {
+ if ( Meta_Object::is_blocked_meta_key( $meta_key, $object_type ) ) {
+ continue;
+ }
+
if ( $meta_value === 'IMT.REMOVE' ) {
$functions['delete']( $content_id, $meta_key );
} else {
--- a/integromat-connector/class/class-rest-response.php
+++ b/integromat-connector/class/class-rest-response.php
@@ -9,6 +9,11 @@
* Includes users Custom fields into the REST API response payload
*/
public static function include_custom_fields() {
+ // rest_api_init runs before the API user exists, so only the token is checked here.
+ if ( ! self::has_valid_api_key() ) {
+ return;
+ }
+
$content_types = array( 'post', 'comment', 'user', 'term' );
$args = array(
'show_in_rest' => true,
@@ -27,30 +32,18 @@
$meta_key = str_replace( IWC_FIELD_PREFIX, '', $option );
- if ( 'post' === $object_type ) {
- foreach ( $post_types as $post_type ) {
- register_rest_field(
- $post_type,
- $meta_key,
- array(
- 'get_callback' => function ( $object, $field_name ) use ( $object_type ) {
- $post_meta_keys = get_post_meta( $object['id'] );
- // see if the field to register belongs to the post type.
- if ( ! isset( $post_meta_keys[ $field_name ] ) ) {
- return;
- }
- return get_metadata( $object_type, $object['id'], $field_name, true );
- },
- )
- );
- }
- } else {
+ if ( Meta_Object::is_blocked_meta_key( $meta_key, $object_type ) ) {
+ continue;
+ }
+
+ $types = ( 'post' === $object_type ) ? $post_types : array( $object_type );
+ foreach ( $types as $type ) {
register_rest_field(
- $object_type,
+ $type,
$meta_key,
array(
- 'get_callback' => function ( $object, $field_name ) use ( $object_type ) {
- return get_metadata( $object_type, $object['id'], $field_name, true );
+ 'get_callback' => function ( $object, $field_name, $request ) use ( $object_type ) {
+ return self::get_custom_field_value( $object, $field_name, $object_type, $request );
},
)
);
@@ -60,6 +53,97 @@
}
/**
+ * Permission result per route and method. The token does not change mid-request; the route can, via embed or batch.
+ *
+ * @var array
+ */
+ private static $may_read_custom_meta = array();
+
+ /**
+ * Read one opted-in meta value for a Make API request.
+ *
+ * A null return is written onto the REST object, so a refused read keeps a core field that shares the name.
+ *
+ * @param array $object
+ * @param string $field_name
+ * @param string $object_type post, user, comment, or term.
+ * @param object $request REST request. Route and method come from here.
+ * @return mixed|null
+ */
+ private static function get_custom_field_value( $object, $field_name, $object_type, $request ) {
+ $keep = ( is_array( $object ) && array_key_exists( $field_name, $object ) ) ? $object[ $field_name ] : null;
+
+ if ( Meta_Object::is_blocked_meta_key( $field_name, $object_type ) ) {
+ return $keep;
+ }
+
+ if ( ! self::request_may_read_custom_meta( $request ) ) {
+ return $keep;
+ }
+
+ if ( empty( $object['id'] ) ) {
+ return $keep;
+ }
+
+ if ( 'post' === $object_type ) {
+ $post_meta_keys = get_post_meta( $object['id'] );
+ // see if the field to register belongs to the post type.
+ if ( ! isset( $post_meta_keys[ $field_name ] ) ) {
+ return $keep;
+ }
+ }
+
+ return get_metadata( $object_type, $object['id'], $field_name, true );
+ }
+
+ /**
+ * Token check only. Safe to call from rest_api_init, before the API user is set.
+ *
+ * @return bool
+ */
+ private static function has_valid_api_key() {
+ if ( ! isset( $_SERVER['HTTP_IWC_API_KEY'] ) || empty( $_SERVER['HTTP_IWC_API_KEY'] ) ) {
+ return false;
+ }
+
+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Token is hashed before comparison in is_valid()
+ $token = $_SERVER['HTTP_IWC_API_KEY'];
+
+ return is_string( $token ) && strlen( $token ) === Api_Token::API_TOKEN_LENGTH && Api_Token::is_valid( $token );
+ }
+
+ /**
+ * Custom meta is readable only when this request carries a valid Make API key
+ * and the API permission check for the current route passes.
+ *
+ * @param object $request REST request.
+ * @return bool
+ */
+ private static function request_may_read_custom_meta( $request ) {
+ $endpoint = '';
+ $method = 'GET';
+ if ( is_object( $request ) && method_exists( $request, 'get_route' ) ) {
+ $endpoint = (string) $request->get_route();
+ if ( method_exists( $request, 'get_method' ) ) {
+ $method = (string) $request->get_method();
+ }
+ }
+
+ $cache_key = $method . ' ' . $endpoint;
+ if ( array_key_exists( $cache_key, self::$may_read_custom_meta ) ) {
+ return self::$may_read_custom_meta[ $cache_key ];
+ }
+
+ if ( ! self::has_valid_api_key() ) {
+ self::$may_read_custom_meta[ $cache_key ] = false;
+ return false;
+ }
+
+ self::$may_read_custom_meta[ $cache_key ] = (bool) Api_Permissions::check_permission( $endpoint, $method, false );
+ return self::$may_read_custom_meta[ $cache_key ];
+ }
+
+ /**
* @param int $status_code
* @param string $error_message
* @param string $error_code
--- a/integromat-connector/index.php
+++ b/integromat-connector/index.php
@@ -2,7 +2,7 @@
/**
* @package Integromat_Connector
- * @version 1.6.6
+ * @version 1.6.7
*/
/**
@@ -10,7 +10,7 @@
Description: Safely connect your site to make.com, work with custom meta fields through the REST API.
Author: Celonis s.r.o.
Author URI: https://www.make.com/en?utm_source=wordpress&utm_medium=partner&utm_campaign=wordpress-partner-make
-Version: 1.6.6
+Version: 1.6.7
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
@@ -18,7 +18,7 @@
define('IWC_FIELD_PREFIX', 'integromat_api_field_');
define('IWC_PLUGIN_NAME_SAFE', 'integromat-wordpress-connector');
define('IWC_MENUITEM_IDENTIFIER', 'integromat_custom_fields');
-define('IWC_PLUGIN_VERSION', '1.6.6');
+define('IWC_PLUGIN_VERSION', '1.6.7');
require __DIR__ . '/class/class-user.php';
require __DIR__ . '/class/class-rest-request.php';
@@ -37,8 +37,8 @@
require __DIR__ . '/settings/class-meta-object.php';
require __DIR__ . '/settings/events.php';
-$controller = new IntegromatController();
-$controller->init();
+$integromat_connector_controller = new IntegromatController();
+$integromat_connector_controller->init();
// Initialize API permissions
IntegromatApi_Permissions::init();
@@ -180,18 +180,18 @@
// Activation and deactivation hooks for API permissions
register_activation_hook( __FILE__, function() {
IntegromatApi_Permissions::add_api_capabilities();
- iwc_set_default_settings();
+ integromat_connector_set_default_settings();
});
register_deactivation_hook( __FILE__, function() {
IntegromatApi_Permissions::remove_api_capabilities();
- iwc_cleanup_on_deactivation();
+ integromat_connector_cleanup_on_deactivation();
});
/**
* Cleanup when plugin is deactivated
*/
-function iwc_cleanup_on_deactivation() {
+function integromat_connector_cleanup_on_deactivation() {
// Remove version tracking
delete_option('iwc_plugin_version');
@@ -202,7 +202,7 @@
/**
* Set default settings when plugin is activated
*/
-function iwc_set_default_settings() {
+function integromat_connector_set_default_settings() {
// Check if this is a fresh installation or upgrade
$current_version = get_option('iwc_plugin_version');
--- a/integromat-connector/settings/class-meta-object.php
+++ b/integromat-connector/settings/class-meta-object.php
@@ -27,12 +27,133 @@
return array();
}
- // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared -- No WordPress function exists to get distinct meta keys from meta tables, one-time admin query, table name validated against whitelist
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter -- No WordPress function exists to get distinct meta keys from meta tables, one-time admin query, table name validated against whitelist and passed through esc_sql
$query = "SELECT DISTINCT(meta_key) FROM `" . esc_sql( $table ) . "` ORDER BY meta_key";
$result = $wpdb->get_col( $query );
- // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared
-
- return is_array( $result ) ? $result : array();
+ // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter
+
+ if ( ! is_array( $result ) ) {
+ return array();
+ }
+
+ $object_type = self::object_type_for_table( $table );
+ $exposed = array();
+ foreach ( $result as $meta_key ) {
+ if ( ! self::is_blocked_meta_key( $meta_key, $object_type ) ) {
+ $exposed[] = $meta_key;
+ }
+ }
+
+ return $exposed;
+ }
+
+ /**
+ * Session tokens, application password hashes, and role keys are never offered, returned, or written.
+ *
+ * Other names that start with an underscore stay available. A valid API key is still required to read them.
+ *
+ * @param mixed $meta_key
+ * @param string $object_type post, user, comment, or term. Unused. Callers still pass it.
+ * @return bool
+ */
+ public static function is_blocked_meta_key( $meta_key, $object_type = '' ) {
+ unset( $object_type );
+
+ if ( ! is_string( $meta_key ) || '' === $meta_key ) {
+ return true;
+ }
+
+ $key = strtolower( $meta_key );
+
+ if ( in_array( $key, array( 'session_tokens', 'use_ssl', 'default_password_nag', '_application_passwords' ), true ) ) {
+ return true;
+ }
+
+ return self::is_role_meta_key( $key );
+ }
+
+ /**
+ * Capability and user_level keys use the site's table prefix, not only wp_.
+ *
+ * @param string $key Lowercased meta key.
+ * @return bool
+ */
+ private static function is_role_meta_key( $key ) {
+ $prefixes = array( 'wp_' );
+ global $wpdb;
+
+ if ( is_object( $wpdb ) && isset( $wpdb->base_prefix ) && is_string( $wpdb->base_prefix ) && '' !== $wpdb->base_prefix ) {
+ $prefixes[] = strtolower( $wpdb->base_prefix );
+ }
+
+ foreach ( array_unique( $prefixes ) as $prefix ) {
+ $pattern = '/^' . preg_quote( $prefix, '/' ) . '(d+_)?(capabilities|user_level)$/';
+ if ( preg_match( $pattern, $key ) ) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Drop blocked keys from a Custom API Fields option save.
+ *
+ * Option keys are stored as integromat_api_field_{meta_key}.
+ *
+ * @param mixed $input
+ * @param string $object_type
+ * @return array
+ */
+ public static function sanitize_exposed_meta_options( $input, $object_type = '' ) {
+ if ( ! is_array( $input ) ) {
+ return array();
+ }
+
+ $sanitized = array();
+ $prefix = IWC_FIELD_PREFIX;
+ foreach ( $input as $key => $value ) {
+ $clean_key = sanitize_key( $key );
+ if ( '' === $clean_key ) {
+ continue;
+ }
+
+ $meta_key = $clean_key;
+ if ( 0 === strpos( $clean_key, $prefix ) ) {
+ $meta_key = substr( $clean_key, strlen( $prefix ) );
+ }
+
+ if ( self::is_blocked_meta_key( $meta_key, $object_type ) ) {
+ continue;
+ }
+
+ $sanitized[ $clean_key ] = sanitize_text_field( $value );
+ }
+
+ return $sanitized;
+ }
+
+ /**
+ * @param string $table
+ * @return string
+ */
+ private static function object_type_for_table( $table ) {
+ global $wpdb;
+
+ if ( $table === $wpdb->usermeta ) {
+ return 'user';
+ }
+ if ( $table === $wpdb->commentmeta ) {
+ return 'comment';
+ }
+ if ( $table === $wpdb->termmeta ) {
+ return 'term';
+ }
+ if ( $table === $wpdb->postmeta ) {
+ return 'post';
+ }
+
+ return '';
}
}
--- a/integromat-connector/settings/object-types/class-comments-meta.php
+++ b/integromat-connector/settings/object-types/class-comments-meta.php
@@ -61,16 +61,7 @@
* @return array
*/
public function sanitize_comment_options( $input ) {
- if ( ! is_array( $input ) ) {
- return array();
- }
-
- $sanitized = array();
- foreach ( $input as $key => $value ) {
- $sanitized[ sanitize_key( $key ) ] = sanitize_text_field( $value );
- }
-
- return $sanitized;
+ return self::sanitize_exposed_meta_options( $input, 'comment' );
}
}
--- a/integromat-connector/settings/object-types/class-post-meta.php
+++ b/integromat-connector/settings/object-types/class-post-meta.php
@@ -150,14 +150,25 @@
public function get_post_meta_items() {
global $wpdb;
- // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared -- No WordPress function exists for JOIN queries to get distinct meta keys with post types, one-time admin query, table names validated
+ // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter -- No WordPress function exists for JOIN queries to get distinct meta keys with post types, one-time admin query, table names are core $wpdb properties passed through esc_sql
$query = "SELECT DISTINCT(m.meta_key), p.post_type
FROM `" . esc_sql( $wpdb->postmeta ) . "` m
INNER JOIN `" . esc_sql( $wpdb->posts ) . "` p ON p.ID = m.post_id";
$meta_keys = $wpdb->get_results( $query );
- // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared
+ // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.PreparedSQL.NotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter
- return is_array( $meta_keys ) ? $meta_keys : array();
+ if ( ! is_array( $meta_keys ) ) {
+ return array();
+ }
+
+ $exposed = array();
+ foreach ( $meta_keys as $row ) {
+ if ( isset( $row->meta_key ) && ! self::is_blocked_meta_key( $row->meta_key, 'post' ) ) {
+ $exposed[] = $row;
+ }
+ }
+
+ return $exposed;
}
/**
@@ -167,16 +178,7 @@
* @return array
*/
public function sanitize_post_options( $input ) {
- if ( ! is_array( $input ) ) {
- return array();
- }
-
- $sanitized = array();
- foreach ( $input as $key => $value ) {
- $sanitized[ sanitize_key( $key ) ] = sanitize_text_field( $value );
- }
-
- return $sanitized;
+ return self::sanitize_exposed_meta_options( $input, 'post' );
}
}
--- a/integromat-connector/settings/object-types/class-term-meta.php
+++ b/integromat-connector/settings/object-types/class-term-meta.php
@@ -56,15 +56,6 @@
* @return array
*/
public function sanitize_term_options( $input ) {
- if ( ! is_array( $input ) ) {
- return array();
- }
-
- $sanitized = array();
- foreach ( $input as $key => $value ) {
- $sanitized[ sanitize_key( $key ) ] = sanitize_text_field( $value );
- }
-
- return $sanitized;
+ return self::sanitize_exposed_meta_options( $input, 'term' );
}
}
--- a/integromat-connector/settings/object-types/class-user-meta.php
+++ b/integromat-connector/settings/object-types/class-user-meta.php
@@ -60,16 +60,7 @@
* @return array
*/
public function sanitize_user_options( $input ) {
- if ( ! is_array( $input ) ) {
- return array();
- }
-
- $sanitized = array();
- foreach ( $input as $key => $value ) {
- $sanitized[ sanitize_key( $key ) ] = sanitize_text_field( $value );
- }
-
- return $sanitized;
+ return self::sanitize_exposed_meta_options( $input, 'user' );
}
}