From 81bc26179932cc3667f649f5a6cda5d3e0a91c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Fri, 20 Nov 2026 18:08:13 +0200 Subject: [PATCH 1/4] fix: query only publicly viewable post types in Posts Grid and Atomic Wind Posts Grid passed its `postTypes` attribute, and the Atomic Wind box passed its `queryPostType` attribute, straight into WP_Query without checking that the post type is public. A Contributor could point either block at a non-public post type whose entries use the `publish` status (a contact-form inbox, store coupons) and read their titles and excerpts in the preview. - Posts Grid: keep only `is_post_type_viewable()` types; an explicit list of only non-public types returns nothing instead of falling back to posts. - Atomic Wind box: skip the query loop when `queryPostType` is not viewable. - Atomic Wind custom field: skip protected (`_`-prefixed) meta keys, so a Contributor cannot print a submitter's stored contact data either. This extends the `is_post_type_viewable()` check added for the `/otter/v1/dynamic` REST routes to these two block renderers. Reported-by: Deus Rex research team --- inc/plugins/class-atomic-wind-blocks.php | 12 +++- inc/render/class-posts-grid-block.php | 14 +++- tests/test-atomic-wind-blocks.php | 85 ++++++++++++++++++++++++ tests/test-post-grid-block.php | 69 +++++++++++++++++++ 4 files changed, 176 insertions(+), 4 deletions(-) diff --git a/inc/plugins/class-atomic-wind-blocks.php b/inc/plugins/class-atomic-wind-blocks.php index b6de8b43d..9478ad484 100644 --- a/inc/plugins/class-atomic-wind-blocks.php +++ b/inc/plugins/class-atomic-wind-blocks.php @@ -1253,11 +1253,18 @@ public function render_query_loop( $block_content, $block ) { return $block_content; } + // The post type comes from the request. Only loop over a publicly viewable one, so a non-public + // type (e.g. a contact-form inbox) whose entries are stored as `publish` cannot be exposed. + $post_type = sanitize_key( $post_type ); + if ( ! is_post_type_viewable( $post_type ) ) { + return ''; + } + global $post; $saved_post = $post; $args = array( - 'post_type' => sanitize_key( $post_type ), + 'post_type' => $post_type, 'posts_per_page' => isset( $block['attrs']['queryCount'] ) ? min( absint( $block['attrs']['queryCount'] ), 100 ) : 3, 'orderby' => isset( $block['attrs']['queryOrderBy'] ) ? sanitize_key( $block['attrs']['queryOrderBy'] ) : sanitize_key( 'date' ), 'order' => isset( $block['attrs']['queryOrder'] ) && strtoupper( $block['attrs']['queryOrder'] ) === 'ASC' ? 'ASC' : 'DESC', @@ -1391,7 +1398,8 @@ public function render_post_fields( $block_content, $block ) { break; case 'custom_field': $meta_key = isset( $block['attrs']['customFieldKey'] ) ? sanitize_text_field( $block['attrs']['customFieldKey'] ) : ''; - if ( $meta_key ) { + // Never print a protected meta key (e.g. a `_`-prefixed field holding a form submitter's data). + if ( $meta_key && ! is_protected_meta( $meta_key, 'post' ) ) { $value = ''; if ( function_exists( 'get_field' ) ) { $acf = get_field( $meta_key, get_the_ID() ); diff --git a/inc/render/class-posts-grid-block.php b/inc/render/class-posts-grid-block.php index 623109101..3ccdbbfba 100644 --- a/inc/render/class-posts-grid-block.php +++ b/inc/render/class-posts-grid-block.php @@ -359,8 +359,18 @@ protected function retrieve_posts( $attributes, $count_posts, $page_number, &$to $categories = join( ', ', $cats ); } + // Only query publicly viewable post types; the attribute comes from the request and could name + // a non-public type (e.g. a contact-form inbox) whose entries are stored with the `publish` status. + $requested_post_types = (array) $attributes['postTypes']; + $post_types = array_values( array_filter( $requested_post_types, 'is_post_type_viewable' ) ); + + // An explicit list of only non-viewable types returns nothing, instead of falling back to posts. + if ( ! empty( $requested_post_types ) && empty( $post_types ) ) { + return array(); + } + $args = array( - 'post_type' => $attributes['postTypes'], + 'post_type' => $post_types, 'posts_per_page' => $attributes['postsToShow'], 'post_status' => 'publish', 'order' => isset( $attributes['order'] ) ? $attributes['order'] : 'DESC', @@ -378,7 +388,7 @@ protected function retrieve_posts( $attributes, $count_posts, $page_number, &$to } // Handle the case when the post type is a WooCommerce product. - if ( isset( $args['post_type'] ) && in_array( 'product', $args['post_type'] ) && function_exists( 'wc_get_products' ) ) { + if ( in_array( 'product', $args['post_type'], true ) && function_exists( 'wc_get_products' ) ) { if ( isset( $attributes['categories'] ) ) { diff --git a/tests/test-atomic-wind-blocks.php b/tests/test-atomic-wind-blocks.php index eec14bc58..f3ac7677e 100644 --- a/tests/test-atomic-wind-blocks.php +++ b/tests/test-atomic-wind-blocks.php @@ -2597,4 +2597,89 @@ public function test_enqueue_base_css_registers_frontend_style_without_enqueuing $this->inline_style_for( 'atomic-wind-base' ) ); } + + // ------------------------------------------------------- + // render_query_loop — post type visibility (otter-internals#319) + // ------------------------------------------------------- + + public function test_query_loop_skips_non_viewable_post_type() { + register_post_type( + 'otter_secret', + array( + 'public' => false, + 'publicly_queryable' => false, + 'exclude_from_search' => true, + ) + ); + $this->factory()->post->create( + array( + 'post_type' => 'otter_secret', + 'post_status' => 'publish', + 'post_title' => 'Secret Record Title', + ) + ); + + $block = $this->make_block( 'atomic-wind/box', array( 'queryPostType' => 'otter_secret' ) ); + $content = '
INNER
'; + + $result = $this->instance->render_query_loop( $content, $block ); + + $this->assertSame( '', $result ); + $this->assertStringNotContainsString( 'Secret Record Title', $result ); + + unregister_post_type( 'otter_secret' ); + } + + public function test_query_loop_renders_a_viewable_post_type() { + $block = $this->make_block( 'atomic-wind/box', array( 'queryPostType' => 'post' ) ); + $content = '
INNER
'; + + $result = $this->instance->render_query_loop( $content, $block ); + + // The post created in set_up() is a viewable match, so the wrapper is emitted. + $this->assertNotSame( '', $result ); + $this->assertStringContainsString( 'wp-block-atomic-wind-box', $result ); + } + + // ------------------------------------------------------- + // render_post_fields — protected custom field (otter-internals#319) + // ------------------------------------------------------- + + 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_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 ); + $this->assertStringNotContainsString( 'Placeholder', $result ); + + wp_reset_postdata(); + } } diff --git a/tests/test-post-grid-block.php b/tests/test-post-grid-block.php index 5ddec6774..2b1b1291a 100644 --- a/tests/test-post-grid-block.php +++ b/tests/test-post-grid-block.php @@ -125,4 +125,73 @@ public function test_render_sanitization() { $this->assertEquals( $expected, $output ); } + + /** + * Render the block for the given post types and return its HTML. + * + * @param string[] $post_types Post types to query. + * @return string + */ + private function render_for_post_types( $post_types ) { + $this->post_grid_block = new Posts_Grid_Block(); + WP_Block_Supports::init(); + WP_Block_Supports::$block_to_render = array( 'blockName' => 'themeisle-blocks/posts-grid' ); + + $attributes = unserialize( serialize( $this->attributes ) ); + $attributes['postTypes'] = $post_types; + + return $this->post_grid_block->render( $attributes ); + } + + /** + * A non-public post type is never queried, so its records cannot be exposed + * through the block (otter-internals#319). + */ + public function test_render_skips_non_public_post_types() { + register_post_type( + 'otter_secret', + array( + 'public' => false, + 'publicly_queryable' => false, + 'exclude_from_search' => true, + ) + ); + $this->factory()->post->create( + array( + 'post_type' => 'otter_secret', + 'post_status' => 'publish', + 'post_title' => 'Secret Record Title', + ) + ); + $this->factory()->post->create( + array( + 'post_type' => 'post', + 'post_status' => 'publish', + 'post_title' => 'Public Blog Title', + ) + ); + + $this->assertStringNotContainsString( 'Secret Record Title', $this->render_for_post_types( array( 'otter_secret' ) ) ); + + $mixed = $this->render_for_post_types( array( 'otter_secret', 'post' ) ); + $this->assertStringNotContainsString( 'Secret Record Title', $mixed ); + $this->assertStringContainsString( 'Public Blog Title', $mixed ); + + unregister_post_type( 'otter_secret' ); + } + + /** + * A public post type still renders, so the filter does not block normal use. + */ + public function test_render_keeps_public_post_types() { + $this->factory()->post->create( + array( + 'post_type' => 'post', + 'post_status' => 'publish', + 'post_title' => 'Public Blog Title', + ) + ); + + $this->assertStringContainsString( 'Public Blog Title', $this->render_for_post_types( array( 'post' ) ) ); + } } From 3449d0874cf40e1d3c1e553e28142b6148ce4022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Fri, 20 Nov 2026 18:52:46 +0200 Subject: [PATCH 2/4] fix: also check the ACF-resolved meta name in the Atomic Wind custom field The custom field gate checked the selector, not the meta key ACF reads. When ACF is active, an ACF field key (e.g. `field_abc123`) passes is_protected_meta(), but ACF resolves it to the field's name, which can be a `_`-prefixed protected key holding a form submitter's data. - Resolve the field with get_field_object() and run is_protected_meta() on the field name too, before reading the value. - Add tests with a field key whose field name is protected (skipped) and public (read), backed by minimal ACF stubs. - Posts Grid: assert an all-non-viewable list renders nothing, instead of falling back to posts (covers the early return). --- inc/plugins/class-atomic-wind-blocks.php | 33 +++++++---- tests/test-atomic-wind-blocks.php | 70 ++++++++++++++++++++++++ tests/test-post-grid-block.php | 5 +- 3 files changed, 96 insertions(+), 12 deletions(-) diff --git a/inc/plugins/class-atomic-wind-blocks.php b/inc/plugins/class-atomic-wind-blocks.php index 9478ad484..a6f67617b 100644 --- a/inc/plugins/class-atomic-wind-blocks.php +++ b/inc/plugins/class-atomic-wind-blocks.php @@ -1398,19 +1398,30 @@ public function render_post_fields( $block_content, $block ) { break; case 'custom_field': $meta_key = isset( $block['attrs']['customFieldKey'] ) ? sanitize_text_field( $block['attrs']['customFieldKey'] ) : ''; - // Never print a protected meta key (e.g. a `_`-prefixed field holding a form submitter's data). - if ( $meta_key && ! is_protected_meta( $meta_key, 'post' ) ) { - $value = ''; - if ( function_exists( 'get_field' ) ) { - $acf = get_field( $meta_key, get_the_ID() ); - if ( is_string( $acf ) ) { - $value = $acf; + if ( $meta_key ) { + // 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/tests/test-atomic-wind-blocks.php b/tests/test-atomic-wind-blocks.php index f3ac7677e..447af71c9 100644 --- a/tests/test-atomic-wind-blocks.php +++ b/tests/test-atomic-wind-blocks.php @@ -9,6 +9,32 @@ require_once dirname( __FILE__ ) . '/php/migration-test-helper.php'; +// Minimal ACF stubs, backed by $GLOBALS['otter_test_acf_fields']. With the global unset they return +// null/false, so they behave as if ACF is inactive and do not affect other tests. +if ( ! function_exists( 'get_field' ) ) { + /** + * @param string $selector Field key or name. + * @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; + } +} + +if ( ! function_exists( 'get_field_object' ) ) { + /** + * @param string $selector Field key or name. + * @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; + } +} + /** * Atomic Wind Blocks test case. */ @@ -2682,4 +2708,48 @@ public function test_custom_field_renders_a_public_meta_key() { wp_reset_postdata(); } + + public function test_custom_field_skips_acf_field_with_protected_name() { + // ACF resolves the field key to a `_`-prefixed meta name that holds submitter data. + $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_reads_acf_field_with_public_name() { + $GLOBALS['otter_test_acf_fields'] = array( + 'field_public' => array( 'name' => 'otter_public_acf', 'value' => 'ACF Public 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_public' ) ); + $content = '

Placeholder

'; + + $result = $this->instance->render_post_fields( $content, $block ); + + $this->assertStringContainsString( 'ACF Public Value', $result ); + + wp_reset_postdata(); + unset( $GLOBALS['otter_test_acf_fields'] ); + } } diff --git a/tests/test-post-grid-block.php b/tests/test-post-grid-block.php index 2b1b1291a..a2584ffd0 100644 --- a/tests/test-post-grid-block.php +++ b/tests/test-post-grid-block.php @@ -171,7 +171,10 @@ public function test_render_skips_non_public_post_types() { ) ); - $this->assertStringNotContainsString( 'Secret Record Title', $this->render_for_post_types( array( 'otter_secret' ) ) ); + $only_secret = $this->render_for_post_types( array( 'otter_secret' ) ); + $this->assertStringNotContainsString( 'Secret Record Title', $only_secret ); + // The early return shows nothing for an all-non-viewable list, rather than falling back to posts. + $this->assertStringNotContainsString( 'Public Blog Title', $only_secret ); $mixed = $this->render_for_post_types( array( 'otter_secret', 'post' ) ); $this->assertStringNotContainsString( 'Secret Record Title', $mixed ); From 80e14bfb980f66891dcbfbb2f1560e406c5ece15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Fri, 20 Nov 2026 23:17:58 +0200 Subject: [PATCH 3/4] refactor: scope PR to the reported non-public post type fix Move the protected custom-field meta hardening out of this PR. That guard was the issue's out-of-scope note, and extending it correctly (Atomic Wind plus the Otter Pro dynamic-content and block-conditions paths, at the permission layer so front-end meta display is unaffected) is a separate security issue. This PR now only restricts Posts Grid and the Atomic Wind box query loop to publicly viewable post types, which is the reported bug. --- inc/plugins/class-atomic-wind-blocks.php | 30 ++---- tests/test-atomic-wind-blocks.php | 112 ----------------------- 2 files changed, 9 insertions(+), 133 deletions(-) diff --git a/inc/plugins/class-atomic-wind-blocks.php b/inc/plugins/class-atomic-wind-blocks.php index a6f67617b..e0924c025 100644 --- a/inc/plugins/class-atomic-wind-blocks.php +++ b/inc/plugins/class-atomic-wind-blocks.php @@ -1399,29 +1399,17 @@ 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 ) { - // 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']; + $value = ''; + if ( function_exists( 'get_field' ) ) { + $acf = get_field( $meta_key, get_the_ID() ); + if ( is_string( $acf ) ) { + $value = $acf; } } - // 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; - } + if ( ! $value ) { + $raw = get_post_meta( get_the_ID(), $meta_key, true ); + if ( is_string( $raw ) ) { + $value = $raw; } } } diff --git a/tests/test-atomic-wind-blocks.php b/tests/test-atomic-wind-blocks.php index 447af71c9..83abea7c8 100644 --- a/tests/test-atomic-wind-blocks.php +++ b/tests/test-atomic-wind-blocks.php @@ -9,32 +9,6 @@ require_once dirname( __FILE__ ) . '/php/migration-test-helper.php'; -// Minimal ACF stubs, backed by $GLOBALS['otter_test_acf_fields']. With the global unset they return -// null/false, so they behave as if ACF is inactive and do not affect other tests. -if ( ! function_exists( 'get_field' ) ) { - /** - * @param string $selector Field key or name. - * @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; - } -} - -if ( ! function_exists( 'get_field_object' ) ) { - /** - * @param string $selector Field key or name. - * @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; - } -} - /** * Atomic Wind Blocks test case. */ @@ -2666,90 +2640,4 @@ public function test_query_loop_renders_a_viewable_post_type() { $this->assertNotSame( '', $result ); $this->assertStringContainsString( 'wp-block-atomic-wind-box', $result ); } - - // ------------------------------------------------------- - // render_post_fields — protected custom field (otter-internals#319) - // ------------------------------------------------------- - - 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_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 ); - $this->assertStringNotContainsString( 'Placeholder', $result ); - - wp_reset_postdata(); - } - - public function test_custom_field_skips_acf_field_with_protected_name() { - // ACF resolves the field key to a `_`-prefixed meta name that holds submitter data. - $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_reads_acf_field_with_public_name() { - $GLOBALS['otter_test_acf_fields'] = array( - 'field_public' => array( 'name' => 'otter_public_acf', 'value' => 'ACF Public 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_public' ) ); - $content = '

Placeholder

'; - - $result = $this->instance->render_post_fields( $content, $block ); - - $this->assertStringContainsString( 'ACF Public Value', $result ); - - wp_reset_postdata(); - unset( $GLOBALS['otter_test_acf_fields'] ); - } } From 047cdc42ee04400bea4c435857df3b259d2115d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Fri, 20 Nov 2026 23:55:24 +0200 Subject: [PATCH 4/4] fix: drop non-viewable post types from the live search main query Otter Pro live search copied `?o_post_type=` straight into the main search query, so an anonymous visitor could query a non-public post type whose entries are `publish` (e.g. a contact-form inbox) and read their titles and excerpts. The REST `prepare_search_query()` path already filters these; the main-query `parse_query()` path did not. Filter the requested types through `is_post_type_viewable()` and skip the override when none remain. --- .../inc/server/class-live-search-server.php | 7 ++++- tests/test-live-search.php | 31 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plugins/otter-pro/inc/server/class-live-search-server.php b/plugins/otter-pro/inc/server/class-live-search-server.php index e90d954ef..19d567e36 100644 --- a/plugins/otter-pro/inc/server/class-live-search-server.php +++ b/plugins/otter-pro/inc/server/class-live-search-server.php @@ -74,7 +74,12 @@ public function add_query_vars( $query_vars ) { */ public function parse_query( $query ) { if ( $query->is_main_query() && $query->is_search() && $query->get( 'o_post_type' ) ) { - $query->set( 'post_type', explode( ',', $query->get( 'o_post_type' ) ) ); + // Only publicly viewable types; a non-public type (e.g. a contact-form inbox) whose entries are + // `publish` must not be queryable by an anonymous visitor through `?o_post_type=`. + $post_types = array_values( array_filter( explode( ',', $query->get( 'o_post_type' ) ), 'is_post_type_viewable' ) ); + if ( ! empty( $post_types ) ) { + $query->set( 'post_type', $post_types ); + } } return $query; diff --git a/tests/test-live-search.php b/tests/test-live-search.php index 4b2b07209..198d6cfbb 100644 --- a/tests/test-live-search.php +++ b/tests/test-live-search.php @@ -108,4 +108,35 @@ public function test_o_post_type_ignored_on_secondary_query() { $this->assertNotEquals( array( 'otter_shop_product' ), $secondary->get( 'post_type' ) ); } + + /** + * A non-viewable type passed via o_post_type is dropped, so an anonymous visitor + * cannot query it through the main search query (otter-internals#319). + */ + public function test_o_post_type_skips_non_viewable_type() { + $live_search = new Live_Search_Server(); + + $this->go_to( home_url( '/?s=test' ) ); + global $wp_query; + $wp_query->set( 'o_post_type', 'otter_shop_coupon' ); + + $live_search->parse_query( $wp_query ); + + $this->assertNotEquals( array( 'otter_shop_coupon' ), $wp_query->get( 'post_type' ) ); + } + + /** + * A mixed list keeps the viewable types and drops the non-viewable one. + */ + public function test_o_post_type_keeps_only_viewable_types() { + $live_search = new Live_Search_Server(); + + $this->go_to( home_url( '/?s=test' ) ); + global $wp_query; + $wp_query->set( 'o_post_type', 'otter_shop_product,otter_shop_coupon' ); + + $live_search->parse_query( $wp_query ); + + $this->assertEquals( array( 'otter_shop_product' ), $wp_query->get( 'post_type' ) ); + } } \ No newline at end of file