Make WordPress Core

Changeset 63663


Ignore:
Timestamp:
09/17/2026 05:32:43 PM (2 months ago)
Author:
adamsilverstein
Message:

Editor: Constrain block template file resolution to the template directory.

Props xknown, ramonopoly, jonsurrell.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-template-utils.php

    r63542 r63663  
    343343        foreach ( $themes as $theme_slug => $theme_dir ) {
    344344                $template_base_paths = get_block_theme_folders( $theme_slug );
    345                 $file_path           = $theme_dir . '/' . $template_base_paths[ $template_type ] . '/' . $slug . '.html';
    346                 if ( file_exists( $file_path ) ) {
     345                $template_dir        = $theme_dir . '/' . $template_base_paths[ $template_type ];
     346                $file_path           = $template_dir . '/' . $slug . '.html';
     347                $template_file       = realpath( $file_path );
     348                $template_root       = realpath( $template_dir );
     349
     350                if (
     351                        false !== $template_file &&
     352                        false !== $template_root &&
     353                        str_starts_with(
     354                                wp_normalize_path( $template_file ),
     355                                trailingslashit( wp_normalize_path( $template_root ) )
     356                        )
     357                ) {
    347358                        $new_template_item = array(
    348359                                'slug'  => $slug,
    349                                 'path'  => $file_path,
     360                                'path'  => $template_file,
    350361                                'theme' => $theme_slug,
    351362                                'type'  => $template_type,
Note: See TracChangeset for help on using the changeset viewer.