From 51bd6cee6d322a48719ca2b0aad6c3b5975bfd85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Fri, 20 Nov 2026 23:29:06 +0200 Subject: [PATCH 01/10] fix: block protected post meta in dynamic content, conditions and Atomic Wind The dynamic-content `acf` tag, the `postMeta`/`acf` dynamic image, the `postMeta` block condition and the Atomic Wind `custom_field` read post meta by a request-supplied key and surface the value, without the protected-key check the text, author and user-meta getters already apply. A Contributor could read a protected `_`-prefixed key of a published post (e.g. a product's `_purchase_note`, or `_`-meta holding tokens) through an editor preview. - Dynamic_Content: guard `get_acf()`, `evaluate_content_media_server()` and `evaluate_content_media_content()` with `is_protected_meta_key()`, and add `is_protected_acf_field()` so an ACF field key that resolves to a protected name is rejected too. - Block_Conditions::has_meta(): never read a protected key, so its value cannot leak through the comparison result. - Atomic Wind `custom_field`: skip protected keys, including the ACF-resolved field name. - Tests for each path; the shared ACF test fixture also stubs get_field/ get_field_object. --- inc/plugins/class-atomic-wind-blocks.php | 30 ++++++--- .../inc/plugins/class-block-conditions.php | 5 ++ .../inc/plugins/class-dynamic-content.php | 32 +++++++-- tests/php/acf-parent-cycle.php | 28 ++++++++ tests/test-atomic-wind-blocks.php | 67 +++++++++++++++++++ tests/test-block-conditions.php | 26 +++++++ tests/test-dynamic-content.php | 51 ++++++++++++++ 7 files changed, 225 insertions(+), 14 deletions(-) diff --git a/inc/plugins/class-atomic-wind-blocks.php b/inc/plugins/class-atomic-wind-blocks.php index b6de8b43d..ca751ebc8 100644 --- a/inc/plugins/class-atomic-wind-blocks.php +++ b/inc/plugins/class-atomic-wind-blocks.php @@ -1392,17 +1392,29 @@ public function render_post_fields( $block_content, $block ) { case 'custom_field': $meta_key = isset( $block['attrs']['customFieldKey'] ) ? sanitize_text_field( $block['attrs']['customFieldKey'] ) : ''; if ( $meta_key ) { - $value = ''; - if ( function_exists( 'get_field' ) ) { - $acf = get_field( $meta_key, get_the_ID() ); - if ( is_string( $acf ) ) { - $value = $acf; + // An ACF field key (e.g. `field_abc123`) resolves to a meta name that may be protected, + // so check the resolved name as well, not only the selector the block stores. + $resolved_key = $meta_key; + if ( function_exists( 'get_field_object' ) ) { + $field_object = get_field_object( $meta_key, get_the_ID(), false ); + if ( is_array( $field_object ) && ! empty( $field_object['name'] ) ) { + $resolved_key = (string) $field_object['name']; } } - if ( ! $value ) { - $raw = get_post_meta( get_the_ID(), $meta_key, true ); - if ( is_string( $raw ) ) { - $value = $raw; + // Never print a protected meta key (e.g. a `_`-prefixed field holding a form submitter's data). + if ( ! is_protected_meta( $meta_key, 'post' ) && ! is_protected_meta( $resolved_key, 'post' ) ) { + $value = ''; + if ( function_exists( 'get_field' ) ) { + $acf = get_field( $meta_key, get_the_ID() ); + if ( is_string( $acf ) ) { + $value = $acf; + } + } + if ( ! $value ) { + $raw = get_post_meta( get_the_ID(), $meta_key, true ); + if ( is_string( $raw ) ) { + $value = $raw; + } } } } diff --git a/plugins/otter-pro/inc/plugins/class-block-conditions.php b/plugins/otter-pro/inc/plugins/class-block-conditions.php index 89f2baf58..c5acc06e3 100644 --- a/plugins/otter-pro/inc/plugins/class-block-conditions.php +++ b/plugins/otter-pro/inc/plugins/class-block-conditions.php @@ -133,6 +133,11 @@ public function has_meta( $condition, $type = 'post' ) { $id = ''; $meta = ''; + // A protected key is never read, so its value cannot leak through the comparison result. + if ( Dynamic_Content::is_protected_meta_key( $condition['meta_key'] ) ) { + return false; + } + if ( 'post' === $type ) { $id = get_the_ID(); $meta = get_post_meta( $id, $condition['meta_key'], true ); diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index 111e594df..9d093a3f3 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -208,6 +208,25 @@ public static function is_protected_meta_key( $key ) { return in_array( strtolower( $key ), $protected, true ); } + /** + * Whether an ACF selector resolves to a protected meta key. + * + * An ACF field key (e.g. `field_abc123`) is harmless on its own, but ACF resolves it to the field's + * meta name, which can be a protected `_`-prefixed key. + * + * @param string $selector ACF field key or name. + * @return bool + */ + public static function is_protected_acf_field( $selector ) { + if ( ! function_exists( 'acf_get_field' ) ) { + return false; + } + + $field = acf_get_field( $selector ); + + return is_array( $field ) && isset( $field['name'] ) && self::is_protected_meta_key( $field['name'] ); + } + /** * Get Post Meta. * @@ -246,7 +265,10 @@ public function get_acf( $data ) { } $field_key = sanitize_text_field( $data['metaKey'] ); - $meta = get_field( $field_key, $data['context'] ); + if ( self::is_protected_meta_key( $field_key ) || self::is_protected_acf_field( $field_key ) ) { + return $default; + } + $meta = get_field( $field_key, $data['context'] ); // Get the ACF repeater's sub-field value. if ( ( null === $meta || false === $meta || '' === $meta ) && function_exists( 'acf_get_field' ) ) { @@ -683,7 +705,7 @@ public function evaluate_content_media_server( $path, $request ) { $id = $request->get_param( 'id' ); $meta = $request->get_param( 'meta' ); - if ( 'postMeta' === $type && ! empty( $meta ) ) { + if ( 'postMeta' === $type && ! empty( $meta ) && ! self::is_protected_meta_key( $meta ) ) { $value = get_post_meta( $context, $meta, true ); if ( ! empty( $value ) ) { @@ -706,7 +728,7 @@ public function evaluate_content_media_server( $path, $request ) { } } - if ( 'acf' === $type && ! empty( $meta ) && class_exists( 'ACF' ) ) { + if ( 'acf' === $type && ! empty( $meta ) && class_exists( 'ACF' ) && ! self::is_protected_meta_key( $meta ) && ! self::is_protected_acf_field( $meta ) ) { $field = get_field( $meta, $context ); // Fall back to repeater sub-field traversal when the field is a @@ -752,7 +774,7 @@ public function evaluate_content_media_server( $path, $request ) { * @return string|string[] */ public function evaluate_content_media_content( $value, $data ) { - if ( 'postMeta' === $data['type'] && isset( $data['meta'] ) && ! empty( $data['meta'] ) ) { + if ( 'postMeta' === $data['type'] && isset( $data['meta'] ) && ! empty( $data['meta'] ) && ! self::is_protected_meta_key( $data['meta'] ) ) { $meta = get_post_meta( $data['context'], $data['meta'], true ); if ( ! empty( $meta ) ) { @@ -775,7 +797,7 @@ public function evaluate_content_media_content( $value, $data ) { } } - if ( 'acf' === $data['type'] && ! empty( $data['meta'] ) && class_exists( 'ACF' ) ) { + if ( 'acf' === $data['type'] && ! empty( $data['meta'] ) && class_exists( 'ACF' ) && ! self::is_protected_meta_key( $data['meta'] ) && ! self::is_protected_acf_field( $data['meta'] ) ) { $field = get_field( $data['meta'], $data['context'] ); // Fall back to repeater sub-field traversal when the field is a diff --git a/tests/php/acf-parent-cycle.php b/tests/php/acf-parent-cycle.php index 88bd9f7de..dbba6fd07 100644 --- a/tests/php/acf-parent-cycle.php +++ b/tests/php/acf-parent-cycle.php @@ -15,4 +15,32 @@ function acf_get_field( $selector ) { return isset( $GLOBALS['otter_test_acf_fields'][ $selector ] ) ? $GLOBALS['otter_test_acf_fields'][ $selector ] : false; } +if ( ! function_exists( 'get_field_object' ) ) { + /** + * Return a field object from the test-controlled ACF map. + * + * @param int|string $selector Field selector. + * @param mixed $post_id Unused. + * @param bool $format Unused. + * @return array|false + */ + function get_field_object( $selector, $post_id = false, $format = true ) { + return isset( $GLOBALS['otter_test_acf_fields'][ $selector ] ) ? $GLOBALS['otter_test_acf_fields'][ $selector ] : false; + } +} + +if ( ! function_exists( 'get_field' ) ) { + /** + * Return a field value from the test-controlled ACF map. + * + * @param int|string $selector Field selector. + * @param mixed $post_id Unused. + * @param bool $format Unused. + * @return mixed + */ + function get_field( $selector, $post_id = false, $format = true ) { + return isset( $GLOBALS['otter_test_acf_fields'][ $selector ]['value'] ) ? $GLOBALS['otter_test_acf_fields'][ $selector ]['value'] : null; + } +} + define( 'OTTER_TEST_ACF_GET_FIELD_STUB', true ); diff --git a/tests/test-atomic-wind-blocks.php b/tests/test-atomic-wind-blocks.php index eec14bc58..8283cff5e 100644 --- a/tests/test-atomic-wind-blocks.php +++ b/tests/test-atomic-wind-blocks.php @@ -9,6 +9,10 @@ require_once dirname( __FILE__ ) . '/php/migration-test-helper.php'; +if ( ! function_exists( 'get_field' ) ) { + require_once __DIR__ . '/php/acf-parent-cycle.php'; +} + /** * Atomic Wind Blocks test case. */ @@ -2597,4 +2601,67 @@ public function test_enqueue_base_css_registers_frontend_style_without_enqueuing $this->inline_style_for( 'atomic-wind-base' ) ); } + + // ------------------------------------------------------- + // render_post_fields — protected custom field (otter-internals#320) + // ------------------------------------------------------- + + public function test_custom_field_skips_protected_meta() { + update_post_meta( $this->post_id, '_protected', 'Protected Meta Value' ); + + $this->reset_in_query( true ); + global $post; + $post = get_post( $this->post_id ); + setup_postdata( $post ); + + $block = $this->make_block( 'atomic-wind/text', array( 'postField' => 'custom_field', 'customFieldKey' => '_protected' ) ); + $content = '

Placeholder

'; + + $result = $this->instance->render_post_fields( $content, $block ); + + $this->assertStringNotContainsString( 'Protected Meta Value', $result ); + $this->assertStringContainsString( 'Placeholder', $result ); + + wp_reset_postdata(); + } + + public function test_custom_field_skips_acf_field_with_protected_name() { + $GLOBALS['otter_test_acf_fields'] = array( + 'field_secret' => array( 'name' => '_acf_protected', 'value' => 'ACF Secret Value' ), + ); + + $this->reset_in_query( true ); + global $post; + $post = get_post( $this->post_id ); + setup_postdata( $post ); + + $block = $this->make_block( 'atomic-wind/text', array( 'postField' => 'custom_field', 'customFieldKey' => 'field_secret' ) ); + $content = '

Placeholder

'; + + $result = $this->instance->render_post_fields( $content, $block ); + + $this->assertStringNotContainsString( 'ACF Secret Value', $result ); + $this->assertStringContainsString( 'Placeholder', $result ); + + wp_reset_postdata(); + unset( $GLOBALS['otter_test_acf_fields'] ); + } + + public function test_custom_field_renders_a_public_meta_key() { + update_post_meta( $this->post_id, 'otter_public_field', 'Public Meta Value' ); + + $this->reset_in_query( true ); + global $post; + $post = get_post( $this->post_id ); + setup_postdata( $post ); + + $block = $this->make_block( 'atomic-wind/text', array( 'postField' => 'custom_field', 'customFieldKey' => 'otter_public_field' ) ); + $content = '

Placeholder

'; + + $result = $this->instance->render_post_fields( $content, $block ); + + $this->assertStringContainsString( 'Public Meta Value', $result ); + + wp_reset_postdata(); + } } diff --git a/tests/test-block-conditions.php b/tests/test-block-conditions.php index 6f2beb2bb..2af8cca86 100644 --- a/tests/test-block-conditions.php +++ b/tests/test-block-conditions.php @@ -659,4 +659,30 @@ public function test_screen_size_condition_enqueues_hide_styles_for_head(): void $this->assertMatchesRegularExpression( '/id=["\']o-condition-hide-inline-css["\']/', $head_styles ); $this->assertStringContainsString( '.o-hide-on-mobile:is(.o-hide-on-mobile,#_){display:none!important}', $head_styles ); } + + /** + * A protected meta key cannot be used as a value oracle through a block condition (otter-internals#320). + */ + public function test_post_meta_condition_ignores_protected_key() { + $post_id = $this->factory()->post->create(); + update_post_meta( $post_id, '_secret', 'leaked-value' ); + + $this->go_to( get_permalink( $post_id ) ); + global $post; + $post = get_post( $post_id ); + setup_postdata( $post ); + + $condition = array( + 'type' => 'postMeta', + 'meta_key' => '_secret', + 'meta_compare' => 'if_contains', + 'meta_value' => 'leaked', + ); + + $result = $this->block_conditions->evaluate_condition( $condition ); + + $this->assertFalse( $result ); + + wp_reset_postdata(); + } } diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index d3c2bddcc..075020979 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2710,4 +2710,55 @@ function ( int $errno, string $errstr ) use ( &$captured ): bool { $this->assertSame( '

Example

', $result, $label ); } } + + /** + * The ACF dynamic tag does not read a protected meta key (otter-internals#320). + */ + public function test_get_acf_blocks_a_protected_meta_key() { + $GLOBALS['otter_test_acf_fields'] = array( '_secret' => array( 'value' => 'ACF Secret' ) ); + + $result = $this->dynamic_content_pro->get_acf( array( + 'metaKey' => '_secret', + 'context' => $this->post_id, + 'default' => 'KEPT', + ) ); + + $this->assertSame( 'KEPT', $result ); + $this->assertStringNotContainsString( 'ACF Secret', $result ); + + unset( $GLOBALS['otter_test_acf_fields'] ); + } + + /** + * An ACF field key that resolves to a protected name is blocked too. + */ + public function test_get_acf_blocks_an_acf_field_with_a_protected_name() { + $GLOBALS['otter_test_acf_fields'] = array( 'field_x' => array( 'name' => '_secret', 'value' => 'ACF Secret' ) ); + + $result = $this->dynamic_content_pro->get_acf( array( + 'metaKey' => 'field_x', + 'context' => $this->post_id, + 'default' => 'KEPT', + ) ); + + $this->assertSame( 'KEPT', $result ); + $this->assertStringNotContainsString( 'ACF Secret', $result ); + + unset( $GLOBALS['otter_test_acf_fields'] ); + } + + /** + * The dynamic image does not put a protected meta value into the src. + */ + public function test_media_content_blocks_protected_post_meta() { + update_post_meta( $this->post_id, '_img', 'https://evil.example/x.png' ); + + $result = $this->dynamic_content_pro->evaluate_content_media_content( 'ORIGINAL', array( + 'type' => 'postMeta', + 'meta' => '_img', + 'context' => $this->post_id, + ) ); + + $this->assertSame( 'ORIGINAL', $result ); + } } From a0cb17ecb7ea299839bf2aa925ee8f08b226a875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Fri, 20 Nov 2026 23:59:41 +0200 Subject: [PATCH 02/10] fix: close ACF repeater-parent and Posts Grid ACF protected-meta gaps - is_protected_acf_field(): walk the ACF parent chain, so a sub-field under a protected repeater (reached through the repeater fallback) is rejected too. - Posts_ACF_Integration::render_acf_fields(): skip a protected field selector or resolved field name, matching the dynamic-content guards. - Tests: a sub-field under a `_secret` repeater returns the default; the Posts Grid ACF field prints nothing for a protected field; the dynamic image blocks a protected postMeta. --- .../inc/plugins/class-dynamic-content.php | 17 ++++++- .../plugins/class-posts-acf-integration.php | 3 +- tests/test-dynamic-content-server.php | 17 +++++++ tests/test-dynamic-content.php | 44 +++++++++++++++++++ 4 files changed, 79 insertions(+), 2 deletions(-) diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index 9d093a3f3..3ca4310e2 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -222,9 +222,24 @@ public static function is_protected_acf_field( $selector ) { return false; } + $seen = array(); $field = acf_get_field( $selector ); - return is_array( $field ) && isset( $field['name'] ) && self::is_protected_meta_key( $field['name'] ); + // Walk the parent chain: a sub-field under a protected repeater is reachable through the repeater fallback. + while ( is_array( $field ) ) { + if ( isset( $field['name'] ) && self::is_protected_meta_key( $field['name'] ) ) { + return true; + } + + $parent = isset( $field['parent'] ) ? $field['parent'] : ''; + if ( empty( $parent ) || isset( $seen[ $parent ] ) ) { + break; + } + $seen[ $parent ] = true; + $field = acf_get_field( $parent ); + } + + return false; } /** diff --git a/plugins/otter-pro/inc/plugins/class-posts-acf-integration.php b/plugins/otter-pro/inc/plugins/class-posts-acf-integration.php index aca2283bf..801084820 100644 --- a/plugins/otter-pro/inc/plugins/class-posts-acf-integration.php +++ b/plugins/otter-pro/inc/plugins/class-posts-acf-integration.php @@ -55,7 +55,8 @@ public function render_acf_fields( $data, $attributes, $id, $element ) { } } - if ( ( ! isset( $custom_meta_field['display'] ) || true === $custom_meta_field['display'] ) && isset( $custom_meta_field['field'] ) && function_exists( 'get_field_object' ) ) { + if ( ( ! isset( $custom_meta_field['display'] ) || true === $custom_meta_field['display'] ) && isset( $custom_meta_field['field'] ) && function_exists( 'get_field_object' ) + && ! Dynamic_Content::is_protected_meta_key( $custom_meta_field['field'] ) && ! Dynamic_Content::is_protected_acf_field( $custom_meta_field['field'] ) ) { $field = get_field_object( $custom_meta_field['field'], $id ); if ( false !== $field ) { $data .= '
'; diff --git a/tests/test-dynamic-content-server.php b/tests/test-dynamic-content-server.php index a595d69ab..47e401a02 100644 --- a/tests/test-dynamic-content-server.php +++ b/tests/test-dynamic-content-server.php @@ -147,4 +147,21 @@ private function can_request( string $route, array $params ): bool { return true === call_user_func( $handler['permission_callback'], $request ); } + + /** + * The dynamic image does not put a protected post meta value into the path (otter-internals#320). + */ + public function test_media_server_blocks_protected_post_meta(): void { + $post_id = self::factory()->post->create(); + update_post_meta( $post_id, '_img', 'https://evil.example/x.png' ); + + $request = new WP_REST_Request( 'GET', '/otter/v1/dynamic' ); + $request->set_param( 'type', 'postMeta' ); + $request->set_param( 'meta', '_img' ); + $request->set_param( 'context', $post_id ); + + $path = ( new \ThemeIsle\OtterPro\Plugins\Dynamic_Content() )->evaluate_content_media_server( 'fallback.jpg', $request ); + + $this->assertSame( 'fallback.jpg', $path ); + } } diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index 075020979..d6136b8aa 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2761,4 +2761,48 @@ public function test_media_content_blocks_protected_post_meta() { $this->assertSame( 'ORIGINAL', $result ); } + + /** + * A sub-field under a protected ACF repeater is blocked through the parent chain. + */ + public function test_get_acf_blocks_a_sub_field_under_a_protected_repeater() { + $GLOBALS['otter_test_acf_fields'] = array( + 'field_leaf' => array( 'key' => 'field_leaf', 'name' => 'leaf', 'parent' => 'field_repeater', 'value' => 'ACF Secret' ), + 'field_repeater' => array( 'key' => 'field_repeater', 'name' => '_secret', 'parent' => 0 ), + ); + + $result = $this->dynamic_content_pro->get_acf( array( + 'metaKey' => 'field_leaf', + 'context' => $this->post_id, + 'default' => 'KEPT', + ) ); + + $this->assertSame( 'KEPT', $result ); + $this->assertStringNotContainsString( 'ACF Secret', $result ); + + unset( $GLOBALS['otter_test_acf_fields'] ); + } + + /** + * The Posts Grid ACF custom field does not print a protected field (otter-internals#320). + */ + public function test_posts_acf_integration_blocks_a_protected_field() { + $GLOBALS['otter_test_acf_fields'] = array( + 'field_secret' => array( 'name' => '_secret', 'value' => 'ACF Secret Value' ), + ); + + $integration = new \ThemeIsle\OtterPro\Plugins\Posts_ACF_Integration(); + $attributes = array( + 'customMetas' => array( + array( 'id' => 'custom_1', 'field' => 'field_secret', 'display' => true ), + ), + ); + + $result = $integration->render_acf_fields( 'BASE', $attributes, $this->post_id, 'custom_1' ); + + $this->assertSame( 'BASE', $result ); + $this->assertStringNotContainsString( 'ACF Secret Value', $result ); + + unset( $GLOBALS['otter_test_acf_fields'] ); + } } From cb09d2195c4e0d123c4164053479a91eb10fa21c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Sat, 21 Nov 2026 00:26:10 +0200 Subject: [PATCH 03/10] test: cover the ACF image branches and the parent-chain cycle guard - Add a guarded `ACF` stub class to the shared fixture so the `class_exists( 'ACF' )`-gated image branches run under tests. - Test the ACF branch of evaluate_content_media_server() and evaluate_content_media_content() blocks a field resolving to a protected name. - Test is_protected_acf_field() returns false on a cyclic parent chain (and terminates), so the cycle guard is covered. --- tests/php/acf-parent-cycle.php | 5 +++++ tests/test-dynamic-content-server.php | 22 ++++++++++++++++++++ tests/test-dynamic-content.php | 29 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/tests/php/acf-parent-cycle.php b/tests/php/acf-parent-cycle.php index dbba6fd07..5b306dbfc 100644 --- a/tests/php/acf-parent-cycle.php +++ b/tests/php/acf-parent-cycle.php @@ -43,4 +43,9 @@ function get_field( $selector, $post_id = false, $format = true ) { } } +// Minimal marker so `class_exists( 'ACF' )`-gated branches run under tests; no behavior of its own. +if ( ! class_exists( 'ACF' ) ) { + class ACF {} // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound +} + define( 'OTTER_TEST_ACF_GET_FIELD_STUB', true ); diff --git a/tests/test-dynamic-content-server.php b/tests/test-dynamic-content-server.php index 47e401a02..ddb2b71b2 100644 --- a/tests/test-dynamic-content-server.php +++ b/tests/test-dynamic-content-server.php @@ -5,6 +5,10 @@ * @package gutenberg-blocks */ +if ( ! function_exists( 'acf_get_field' ) ) { + require_once __DIR__ . '/php/acf-parent-cycle.php'; +} + /** * Access rules of the otter/v1/dynamic routes for visitors and editors. */ @@ -164,4 +168,22 @@ public function test_media_server_blocks_protected_post_meta(): void { $this->assertSame( 'fallback.jpg', $path ); } + + /** + * The dynamic image ACF branch does not put a protected field value into the path (otter-internals#320). + */ + public function test_media_server_blocks_protected_acf_field(): void { + $GLOBALS['otter_test_acf_fields'] = array( 'field_secret' => array( 'name' => '_secret', 'value' => 'https://evil.example/x.png' ) ); + + $request = new WP_REST_Request( 'GET', '/otter/v1/dynamic' ); + $request->set_param( 'type', 'acf' ); + $request->set_param( 'meta', 'field_secret' ); + $request->set_param( 'context', self::factory()->post->create() ); + + $path = ( new \ThemeIsle\OtterPro\Plugins\Dynamic_Content() )->evaluate_content_media_server( 'fallback.jpg', $request ); + + $this->assertStringNotContainsString( 'evil.example', $path ); + + unset( $GLOBALS['otter_test_acf_fields'] ); + } } diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index d6136b8aa..6460074f7 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2805,4 +2805,33 @@ public function test_posts_acf_integration_blocks_a_protected_field() { unset( $GLOBALS['otter_test_acf_fields'] ); } + + /** + * The dynamic image ACF branch does not surface a protected field value. + */ + public function test_media_content_blocks_protected_acf_field() { + $GLOBALS['otter_test_acf_fields'] = array( 'field_secret' => array( 'name' => '_secret', 'value' => 'https://evil.example/x.png' ) ); + + $result = $this->dynamic_content_pro->evaluate_content_media_content( 'ORIGINAL', array( + 'type' => 'acf', + 'meta' => 'field_secret', + 'context' => $this->post_id, + ) ); + + $flat = is_array( $result ) ? implode( ' ', $result ) : (string) $result; + $this->assertStringNotContainsString( 'evil.example', $flat ); + + unset( $GLOBALS['otter_test_acf_fields'] ); + } + + /** + * is_protected_acf_field() terminates on a cyclic parent chain. + */ + public function test_is_protected_acf_field_handles_a_cyclic_parent_chain() { + $GLOBALS['otter_test_acf_fields'] = $this->cyclic_acf_fields(); + + $this->assertFalse( \ThemeIsle\OtterPro\Plugins\Dynamic_Content::is_protected_acf_field( 10 ) ); + + unset( $GLOBALS['otter_test_acf_fields'] ); + } } From 02d81e6889355f3e7d45c94f49e46357bc234fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Sat, 21 Nov 2026 00:52:52 +0200 Subject: [PATCH 04/10] fix: honor the is_protected_meta filter in the shared protected-key check is_protected_meta_key() only matched a `_` prefix and three named keys, so a key another plugin protects through the `is_protected_meta` filter without a `_` prefix (e.g. NextScripts SNAP's keys) still leaked through get_acf(), has_meta() and the postMeta/acf getters. Fall back to is_protected_meta() so those are caught too, matching the Atomic Wind custom field. Add a test that filters a non-prefixed key as protected and expects the fallback. --- .../inc/plugins/class-dynamic-content.php | 7 +++++- tests/test-dynamic-content.php | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index 3ca4310e2..9fc871b67 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -205,7 +205,12 @@ public static function is_protected_meta_key( $key ) { $protected = array( 'user_pass', 'user_activation_key', 'session_tokens' ); - return in_array( strtolower( $key ), $protected, true ); + if ( in_array( strtolower( $key ), $protected, true ) ) { + return true; + } + + // Honor the `is_protected_meta` filter, so a key another plugin protects without a `_` prefix is caught too. + return is_protected_meta( $key, 'post' ); } /** diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index 6460074f7..19cd99760 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2834,4 +2834,26 @@ public function test_is_protected_acf_field_handles_a_cyclic_parent_chain() { unset( $GLOBALS['otter_test_acf_fields'] ); } + + /** + * A key another plugin protects via the is_protected_meta filter (without a `_` prefix) is blocked too. + */ + public function test_blocks_a_filter_protected_meta_key() { + update_post_meta( $this->post_id, 'snap_x', 'https://evil.example/x.png' ); + + $filter = static function ( $protected, $meta_key ) { + return 'snap_x' === $meta_key ? true : $protected; + }; + add_filter( 'is_protected_meta', $filter, 10, 2 ); + + $result = $this->dynamic_content_pro->evaluate_content_media_content( 'ORIGINAL', array( + 'type' => 'postMeta', + 'meta' => 'snap_x', + 'context' => $this->post_id, + ) ); + + remove_filter( 'is_protected_meta', $filter, 10 ); + + $this->assertSame( 'ORIGINAL', $result ); + } } From 034bf182634db8b9da88cd5cf95960e4289e7ca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Sat, 21 Nov 2026 10:04:24 +0200 Subject: [PATCH 05/10] fix: check the right meta type when a key is protected only for user meta is_protected_meta_key() always passed 'post' to is_protected_meta(), so a key a plugin protects only for 'user' meta leaked through get_author_meta(), get_loggedin_meta() and the user branch of has_meta(). Add a $meta_type parameter and pass 'user' from those callers. --- .../inc/plugins/class-block-conditions.php | 2 +- .../inc/plugins/class-dynamic-content.php | 11 ++++---- tests/test-dynamic-content.php | 25 +++++++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/plugins/otter-pro/inc/plugins/class-block-conditions.php b/plugins/otter-pro/inc/plugins/class-block-conditions.php index c5acc06e3..c36ae2a82 100644 --- a/plugins/otter-pro/inc/plugins/class-block-conditions.php +++ b/plugins/otter-pro/inc/plugins/class-block-conditions.php @@ -134,7 +134,7 @@ public function has_meta( $condition, $type = 'post' ) { $meta = ''; // A protected key is never read, so its value cannot leak through the comparison result. - if ( Dynamic_Content::is_protected_meta_key( $condition['meta_key'] ) ) { + if ( Dynamic_Content::is_protected_meta_key( $condition['meta_key'], $type ) ) { return false; } diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index 9fc871b67..e300d3ed0 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -192,11 +192,12 @@ public function get_terms( $data ) { * Blocks WordPress protected (underscore-prefixed) meta and sensitive user fields, * since these getters can be reached for any published post without authentication. * - * @param string $key Meta key. + * @param string $key Meta key. + * @param string $meta_type Meta type the key is read from ('post' or 'user'), for the is_protected_meta filter. * * @return bool */ - public static function is_protected_meta_key( $key ) { + public static function is_protected_meta_key( $key, $meta_type = 'post' ) { $key = (string) $key; if ( '' === $key || '_' === $key[0] ) { @@ -210,7 +211,7 @@ public static function is_protected_meta_key( $key ) { } // Honor the `is_protected_meta` filter, so a key another plugin protects without a `_` prefix is caught too. - return is_protected_meta( $key, 'post' ); + return is_protected_meta( $key, $meta_type ); } /** @@ -527,7 +528,7 @@ public function get_author_meta( $data ) { $default = isset( $data['default'] ) ? esc_html( $data['default'] ) : ''; $meta = ''; - if ( isset( $data['metaKey'] ) && ! self::is_protected_meta_key( $data['metaKey'] ) ) { + if ( isset( $data['metaKey'] ) && ! self::is_protected_meta_key( $data['metaKey'], 'user' ) ) { $meta = get_the_author_meta( esc_html( $data['metaKey'] ), intval( get_post_field( 'post_author', $data['context'] ) ) ); } @@ -550,7 +551,7 @@ public function get_loggedin_meta( $data ) { $default = isset( $data['default'] ) ? esc_html( $data['default'] ) : ''; $meta = ''; - if ( isset( $data['metaKey'] ) && ! self::is_protected_meta_key( $data['metaKey'] ) ) { + if ( isset( $data['metaKey'] ) && ! self::is_protected_meta_key( $data['metaKey'], 'user' ) ) { $meta = get_user_meta( $user_id, esc_html( $data['metaKey'] ), true ); } diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index 19cd99760..a2105061e 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2856,4 +2856,29 @@ public function test_blocks_a_filter_protected_meta_key() { $this->assertSame( 'ORIGINAL', $result ); } + + /** + * Author meta honors a filter that protects a key only for user meta. + */ + public function test_author_meta_blocks_a_user_only_filter_protected_key() { + $author_id = self::factory()->user->create(); + $post_id = self::factory()->post->create( array( 'post_author' => $author_id ) ); + update_user_meta( $author_id, 'nick_x', 'secret-nick' ); + + $filter = static function ( $protected, $meta_key, $meta_type ) { + return ( 'nick_x' === $meta_key && 'user' === $meta_type ) ? true : $protected; + }; + add_filter( 'is_protected_meta', $filter, 10, 3 ); + + $result = $this->dynamic_content_pro->get_author_meta( array( + 'metaKey' => 'nick_x', + 'context' => $post_id, + 'default' => 'DEF', + ) ); + + remove_filter( 'is_protected_meta', $filter, 10 ); + + $this->assertSame( 'DEF', $result ); + $this->assertStringNotContainsString( 'secret-nick', $result ); + } } From d5fdf56172ac4a2e69f065aafcac8c251021f03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Sat, 21 Nov 2026 10:32:35 +0200 Subject: [PATCH 06/10] fix: normalize core user-field aliases so author `pass` can't leak the hash get_the_author_meta() maps aliases like `pass` and `activation_key` to `user_pass`/`user_activation_key`, but is_protected_meta_key() matched only the full names, so metaKey `pass` returned the author's password hash. Normalize the user-field aliases to their `user_*` form before the check. Add tests: author meta blocks `pass`/`activation_key`; and user-only is_protected_meta filters are honored for get_loggedin_meta() and the loggedInUserMeta block condition. --- .../inc/plugins/class-dynamic-content.php | 8 ++++ tests/test-block-conditions.php | 25 +++++++++++ tests/test-dynamic-content.php | 41 +++++++++++++++++++ 3 files changed, 74 insertions(+) diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index e300d3ed0..eb7a68bba 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -200,6 +200,14 @@ public function get_terms( $data ) { public static function is_protected_meta_key( $key, $meta_type = 'post' ) { $key = (string) $key; + // get_the_author_meta() maps these aliases to the user_* fields, so check the real field (e.g. pass -> user_pass). + if ( 'user' === $meta_type ) { + $aliases = array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ); + if ( in_array( strtolower( $key ), $aliases, true ) ) { + $key = 'user_' . strtolower( $key ); + } + } + if ( '' === $key || '_' === $key[0] ) { return true; } diff --git a/tests/test-block-conditions.php b/tests/test-block-conditions.php index 2af8cca86..44adaea5f 100644 --- a/tests/test-block-conditions.php +++ b/tests/test-block-conditions.php @@ -685,4 +685,29 @@ public function test_post_meta_condition_ignores_protected_key() { wp_reset_postdata(); } + + /** + * A logged-in-user-meta condition honors a filter that protects a key only for user meta (otter-internals#320). + */ + public function test_logged_in_user_meta_ignores_user_only_filter_protected_key() { + wp_set_current_user( $this->user_id ); + update_user_meta( $this->user_id, 'nick_x', '1' ); + + $filter = static function ( $protected, $meta_key, $meta_type ) { + return ( 'nick_x' === $meta_key && 'user' === $meta_type ) ? true : $protected; + }; + add_filter( 'is_protected_meta', $filter, 10, 3 ); + + $condition = array( + 'type' => 'loggedInUserMeta', + 'meta_key' => 'nick_x', + 'meta_compare' => 'is_true', + ); + + $result = $this->block_conditions->evaluate_condition( $condition ); + + remove_filter( 'is_protected_meta', $filter, 10 ); + + $this->assertFalse( $result ); + } } diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index a2105061e..e2fa77992 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2881,4 +2881,45 @@ public function test_author_meta_blocks_a_user_only_filter_protected_key() { $this->assertSame( 'DEF', $result ); $this->assertStringNotContainsString( 'secret-nick', $result ); } + + /** + * Author meta blocks the core user-field aliases, so `pass` cannot return the password hash. + */ + public function test_author_meta_blocks_core_user_aliases() { + $author_id = self::factory()->user->create(); + $post_id = self::factory()->post->create( array( 'post_author' => $author_id ) ); + + foreach ( array( 'pass', 'activation_key' ) as $alias ) { + $result = $this->dynamic_content_pro->get_author_meta( array( + 'metaKey' => $alias, + 'context' => $post_id, + 'default' => 'DEF', + ) ); + + $this->assertSame( 'DEF', $result, "The '$alias' alias must be blocked." ); + } + } + + /** + * Logged-in user meta honors a filter that protects a key only for user meta. + */ + public function test_loggedin_meta_blocks_a_user_only_filter_protected_key() { + $uid = self::factory()->user->create(); + wp_set_current_user( $uid ); + update_user_meta( $uid, 'nick_x', 'secret-nick' ); + + $filter = static function ( $protected, $meta_key, $meta_type ) { + return ( 'nick_x' === $meta_key && 'user' === $meta_type ) ? true : $protected; + }; + add_filter( 'is_protected_meta', $filter, 10, 3 ); + + $result = $this->dynamic_content_pro->get_loggedin_meta( array( + 'metaKey' => 'nick_x', + 'default' => 'DEF', + ) ); + + remove_filter( 'is_protected_meta', $filter, 10 ); + + $this->assertSame( 'DEF', $result ); + } } From 697b6aea5dd83840578d4320bd3845fb3a0d0d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Sat, 21 Nov 2026 11:03:13 +0200 Subject: [PATCH 07/10] fix: check both the raw key and the resolved alias against the filter The alias rewrite replaced the key before the is_protected_meta filter ran, so a plugin protecting a raw user meta key named like a core alias (e.g. `email`) was missed on the get_user_meta paths. Check the raw key verbatim first, then also the resolved `user_*` alias for the get_the_author_meta mapping. Add tests: a filter on the raw `email` user key is honored by get_loggedin_meta() and the loggedInUserMeta condition. --- .../inc/plugins/class-dynamic-content.php | 21 ++++++++++++++-- tests/test-block-conditions.php | 25 +++++++++++++++++++ tests/test-dynamic-content.php | 23 +++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index eb7a68bba..f1dd56176 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -200,14 +200,31 @@ public function get_terms( $data ) { public static function is_protected_meta_key( $key, $meta_type = 'post' ) { $key = (string) $key; - // get_the_author_meta() maps these aliases to the user_* fields, so check the real field (e.g. pass -> user_pass). + if ( self::is_protected_meta_name( $key, $meta_type ) ) { + return true; + } + + // get_the_author_meta() also maps these aliases to the user_* fields, so check the resolved field too + // (e.g. pass -> user_pass), while still checking the raw key above for get_user_meta reads. if ( 'user' === $meta_type ) { $aliases = array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ); if ( in_array( strtolower( $key ), $aliases, true ) ) { - $key = 'user_' . strtolower( $key ); + return self::is_protected_meta_name( 'user_' . strtolower( $key ), $meta_type ); } } + return false; + } + + /** + * Whether a single meta key (checked verbatim) is protected. + * + * @param string $key Meta key. + * @param string $meta_type Meta type the key is read from ('post' or 'user'). + * + * @return bool + */ + private static function is_protected_meta_name( $key, $meta_type ) { if ( '' === $key || '_' === $key[0] ) { return true; } diff --git a/tests/test-block-conditions.php b/tests/test-block-conditions.php index 44adaea5f..04ddf2317 100644 --- a/tests/test-block-conditions.php +++ b/tests/test-block-conditions.php @@ -710,4 +710,29 @@ public function test_logged_in_user_meta_ignores_user_only_filter_protected_key( $this->assertFalse( $result ); } + + /** + * A user meta key named like a core alias is still checked verbatim against the filter. + */ + public function test_logged_in_user_meta_checks_an_alias_named_key_verbatim() { + wp_set_current_user( $this->user_id ); + update_user_meta( $this->user_id, 'email', '1' ); + + $filter = static function ( $protected, $meta_key, $meta_type ) { + return ( 'email' === $meta_key && 'user' === $meta_type ) ? true : $protected; + }; + add_filter( 'is_protected_meta', $filter, 10, 3 ); + + $condition = array( + 'type' => 'loggedInUserMeta', + 'meta_key' => 'email', + 'meta_compare' => 'is_true', + ); + + $result = $this->block_conditions->evaluate_condition( $condition ); + + remove_filter( 'is_protected_meta', $filter, 10 ); + + $this->assertFalse( $result ); + } } diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index e2fa77992..15cab5bd9 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2922,4 +2922,27 @@ public function test_loggedin_meta_blocks_a_user_only_filter_protected_key() { $this->assertSame( 'DEF', $result ); } + + /** + * A user meta key named like a core alias is still checked verbatim against the filter. + */ + public function test_loggedin_meta_checks_an_alias_named_key_verbatim() { + $uid = self::factory()->user->create(); + wp_set_current_user( $uid ); + update_user_meta( $uid, 'email', 'secret-mail' ); + + $filter = static function ( $protected, $meta_key, $meta_type ) { + return ( 'email' === $meta_key && 'user' === $meta_type ) ? true : $protected; + }; + add_filter( 'is_protected_meta', $filter, 10, 3 ); + + $result = $this->dynamic_content_pro->get_loggedin_meta( array( + 'metaKey' => 'email', + 'default' => 'DEF', + ) ); + + remove_filter( 'is_protected_meta', $filter, 10 ); + + $this->assertSame( 'DEF', $result ); + } } From 0a4ffcc90e3454bb24034f58d40d41b7b48dfb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Sat, 21 Nov 2026 11:26:37 +0200 Subject: [PATCH 08/10] fix: resolve WordPress back-compat author fields before the protected check get_the_author_meta() reads user_firstname/user_lastname/user_description via WP_User::__get, which maps them to the first_name/last_name/description meta keys. is_protected_meta_key() checked only the raw name, so a filter on first_name was missed. Resolve those back-compat fields to their real meta key. Also seed user_activation_key in the alias test so the activation_key case fails without the fix, and add a first_name back-compat author-meta test. --- .../inc/plugins/class-dynamic-content.php | 21 ++++++++++--- tests/test-dynamic-content.php | 31 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index f1dd56176..530825a8d 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -204,12 +204,25 @@ public static function is_protected_meta_key( $key, $meta_type = 'post' ) { return true; } - // get_the_author_meta() also maps these aliases to the user_* fields, so check the resolved field too - // (e.g. pass -> user_pass), while still checking the raw key above for get_user_meta reads. + // get_the_author_meta() -> WP_User::__get resolves field names to real user-meta keys, so check the + // resolved key too, while still checking the raw key above for get_user_meta reads. if ( 'user' === $meta_type ) { + $lower = strtolower( $key ); + + // Forward aliases, e.g. pass -> user_pass. $aliases = array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ); - if ( in_array( strtolower( $key ), $aliases, true ) ) { - return self::is_protected_meta_name( 'user_' . strtolower( $key ), $meta_type ); + if ( in_array( $lower, $aliases, true ) ) { + return self::is_protected_meta_name( 'user_' . $lower, $meta_type ); + } + + // Back-compat fields, e.g. user_firstname -> first_name. + $back_compat = array( + 'user_firstname' => 'first_name', + 'user_lastname' => 'last_name', + 'user_description' => 'description', + ); + if ( isset( $back_compat[ $lower ] ) ) { + return self::is_protected_meta_name( $back_compat[ $lower ], $meta_type ); } } diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index 15cab5bd9..7325184dd 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2886,9 +2886,15 @@ public function test_author_meta_blocks_a_user_only_filter_protected_key() { * Author meta blocks the core user-field aliases, so `pass` cannot return the password hash. */ public function test_author_meta_blocks_core_user_aliases() { + global $wpdb; + $author_id = self::factory()->user->create(); $post_id = self::factory()->post->create( array( 'post_author' => $author_id ) ); + // Seed the reset key so the activation_key alias has a value to leak without the fix. + $wpdb->update( $wpdb->users, array( 'user_activation_key' => 'secret-key' ), array( 'ID' => $author_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery + clean_user_cache( $author_id ); + foreach ( array( 'pass', 'activation_key' ) as $alias ) { $result = $this->dynamic_content_pro->get_author_meta( array( 'metaKey' => $alias, @@ -2923,6 +2929,31 @@ public function test_loggedin_meta_blocks_a_user_only_filter_protected_key() { $this->assertSame( 'DEF', $result ); } + /** + * Author meta resolves a back-compat field to its real meta key before the filter check. + */ + public function test_author_meta_blocks_a_filter_protected_back_compat_field() { + $author_id = self::factory()->user->create(); + $post_id = self::factory()->post->create( array( 'post_author' => $author_id ) ); + update_user_meta( $author_id, 'first_name', 'secret-first' ); + + $filter = static function ( $protected, $meta_key, $meta_type ) { + return ( 'first_name' === $meta_key && 'user' === $meta_type ) ? true : $protected; + }; + add_filter( 'is_protected_meta', $filter, 10, 3 ); + + $result = $this->dynamic_content_pro->get_author_meta( array( + 'metaKey' => 'user_firstname', + 'context' => $post_id, + 'default' => 'DEF', + ) ); + + remove_filter( 'is_protected_meta', $filter, 10 ); + + $this->assertSame( 'DEF', $result ); + $this->assertStringNotContainsString( 'secret-first', $result ); + } + /** * A user meta key named like a core alias is still checked verbatim against the filter. */ From 1a433334d63ac57a8350d97ff3af4b03bec92996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Mon, 23 Nov 2026 13:49:28 +0200 Subject: [PATCH 09/10] fix: block the legacy user_level key in author and user meta get_the_author_meta('user_level') returns the author's capability level (0-10) via WP_User, and user_level is neither underscore-prefixed nor a core alias, so is_protected_meta_key() let it through. Add it to the protected list so dynamic content, block conditions and Atomic Wind cannot expose it. Add a test: author meta blocks user_level for an administrator author. --- .../inc/plugins/class-dynamic-content.php | 2 +- tests/test-dynamic-content.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index 530825a8d..ef6f9f34e 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -242,7 +242,7 @@ private static function is_protected_meta_name( $key, $meta_type ) { return true; } - $protected = array( 'user_pass', 'user_activation_key', 'session_tokens' ); + $protected = array( 'user_pass', 'user_activation_key', 'session_tokens', 'user_level' ); if ( in_array( strtolower( $key ), $protected, true ) ) { return true; diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index 7325184dd..3399e704a 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2906,6 +2906,22 @@ public function test_author_meta_blocks_core_user_aliases() { } } + /** + * Author meta blocks the legacy user_level key, so a visitor cannot read the author's capability level. + */ + public function test_author_meta_blocks_user_level() { + $author_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); + $post_id = self::factory()->post->create( array( 'post_author' => $author_id ) ); + + $result = $this->dynamic_content_pro->get_author_meta( array( + 'metaKey' => 'user_level', + 'context' => $post_id, + 'default' => 'DEF', + ) ); + + $this->assertSame( 'DEF', $result ); + } + /** * Logged-in user meta honors a filter that protects a key only for user meta. */ From cf11b5e10e15380ce859f884a89d257e92dc6584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Mon, 23 Nov 2026 13:54:41 +0200 Subject: [PATCH 10/10] fix: scope the user_level block to user meta so a post field still renders The previous commit added user_level to the shared protected-name list, which also blocked post and ACF meta. A public post field literally named user_level (e.g. a course level) stopped rendering. Move the guard to the user-meta branch of is_protected_meta_key, so only author and logged-in user reads are blocked. Add a test: a post field named user_level is still returned. --- .../inc/plugins/class-dynamic-content.php | 7 ++++++- tests/test-dynamic-content.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/otter-pro/inc/plugins/class-dynamic-content.php b/plugins/otter-pro/inc/plugins/class-dynamic-content.php index ef6f9f34e..8d031d172 100644 --- a/plugins/otter-pro/inc/plugins/class-dynamic-content.php +++ b/plugins/otter-pro/inc/plugins/class-dynamic-content.php @@ -209,6 +209,11 @@ public static function is_protected_meta_key( $key, $meta_type = 'post' ) { if ( 'user' === $meta_type ) { $lower = strtolower( $key ); + // Legacy capability level; user-only, so a post field named user_level stays allowed. + if ( 'user_level' === $lower ) { + return true; + } + // Forward aliases, e.g. pass -> user_pass. $aliases = array( 'login', 'pass', 'nicename', 'email', 'url', 'registered', 'activation_key', 'status' ); if ( in_array( $lower, $aliases, true ) ) { @@ -242,7 +247,7 @@ private static function is_protected_meta_name( $key, $meta_type ) { return true; } - $protected = array( 'user_pass', 'user_activation_key', 'session_tokens', 'user_level' ); + $protected = array( 'user_pass', 'user_activation_key', 'session_tokens' ); if ( in_array( strtolower( $key ), $protected, true ) ) { return true; diff --git a/tests/test-dynamic-content.php b/tests/test-dynamic-content.php index 3399e704a..fefcf64e4 100644 --- a/tests/test-dynamic-content.php +++ b/tests/test-dynamic-content.php @@ -2922,6 +2922,22 @@ public function test_author_meta_blocks_user_level() { $this->assertSame( 'DEF', $result ); } + /** + * A post field literally named user_level is not user meta, so it stays readable. + */ + public function test_post_meta_allows_a_field_named_user_level() { + $post_id = self::factory()->post->create(); + update_post_meta( $post_id, 'user_level', 'Beginner' ); + + $result = $this->dynamic_content_pro->get_post_meta( array( + 'metaKey' => 'user_level', + 'context' => $post_id, + 'default' => 'DEF', + ) ); + + $this->assertSame( 'Beginner', $result ); + } + /** * Logged-in user meta honors a filter that protects a key only for user meta. */