@@ -423,7 +423,7 @@ public function get_taxonomy_args( $post, $escape_labels = true ) {
423423 $ meta_box = isset ( $ post ['meta_box ' ] ) ? (string ) $ post ['meta_box ' ] : 'default ' ;
424424
425425 if ( 'custom ' === $ meta_box && ! empty ( $ post ['meta_box_cb ' ] ) ) {
426- $ args ['meta_box_cb ' ] = ( string ) $ post [ ' meta_box_cb ' ] ;
426+ $ args ['meta_box_cb ' ] = array ( $ this , ' build_safe_context_for_metabox_cb ' ) ;
427427
428428 if ( ! empty ( $ post ['meta_box_sanitize_cb ' ] ) ) {
429429 $ args ['meta_box_sanitize_cb ' ] = (string ) $ post ['meta_box_sanitize_cb ' ];
@@ -504,6 +504,46 @@ public function get_taxonomy_args( $post, $escape_labels = true ) {
504504 return apply_filters ( 'acf/taxonomy/registration_args ' , $ args , $ post );
505505 }
506506
507+ /**
508+ * Ensure the metabox being called does not perform any unsafe operations.
509+ *
510+ * @since 6.3.8
511+ *
512+ * @param WP_Post $post The post being rendered.
513+ * @param array $tax The provided taxonomy information required for callback render.
514+ * @return mixed The callback result.
515+ */
516+ public function build_safe_context_for_metabox_cb ( $ post , $ tax ) {
517+ $ taxonomies = $ this ->get_posts ();
518+ $ this_tax = array_filter (
519+ $ taxonomies ,
520+ function ( $ taxonomy ) use ( $ tax ) {
521+ return $ taxonomy ['taxonomy ' ] === $ tax ['args ' ]['taxonomy ' ];
522+ }
523+ );
524+ if ( empty ( $ this_tax ) || ! is_array ( $ this_tax ) ) {
525+ // Unable to find the ACF taxonomy. Don't do anything.
526+ return ;
527+ }
528+ $ acf_taxonomy = array_shift ( $ this_tax );
529+ $ original_cb = isset ( $ acf_taxonomy ['meta_box_cb ' ] ) ? $ acf_taxonomy ['meta_box_cb ' ] : false ;
530+
531+ // Prevent access to any wp_ prefixed functions in a callback.
532+ if ( apply_filters ( 'acf/taxonomy/prevent_access_to_wp_functions_in_meta_box_cb ' , true ) && substr ( strtolower ( $ original_cb ), 0 , 3 ) === 'wp_ ' ) {
533+ // Don't execute register meta box callbacks if an internal wp function by default.
534+ return ;
535+ }
536+
537+ $ original_post = $ _POST ; //phpcs:ignore -- Only used as temporary storage to prevent CSRFs in callbacks.
538+ $ _POST = array ();
539+ $ return = false ;
540+ if ( is_callable ( $ original_cb ) ) {
541+ $ return = call_user_func ( $ original_cb , $ post , $ tax );
542+ }
543+ $ _POST = $ original_post ;
544+ return $ return ;
545+ }
546+
507547 /**
508548 * Returns a string that can be used to create a taxonomy in PHP.
509549 *
0 commit comments