Changeset 63824
- Timestamp:
- 09/22/2026 03:27:54 PM (2 months ago)
- Location:
- branches/5.3
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/template.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/5.3
-
branches/5.3/src/wp-includes/template.php
r46391 r63824 442 442 if ( $pagename ) { 443 443 $pagename_decoded = urldecode( $pagename ); 444 if ( $pagename_decoded !== $pagename ) {444 if ( $pagename_decoded !== $pagename && 0 === validate_file( $pagename_decoded ) ) { 445 445 $templates[] = "page-{$pagename_decoded}.php"; 446 446 } … … 638 638 639 639 /** 640 * Determines whether a template found by locate_template() may be loaded. 641 * 642 * @since 7.1.2 643 * @access private 644 * 645 * @param string $path Path to an existing template file. 646 * @return bool Whether the template may be loaded. 647 */ 648 function _wp_is_template_path_allowed( $path ) { 649 // A file path that exists and does not contain `..` is allowed. 650 if ( 0 === preg_match( '#(?:^|/)\.\.[. ]*(?:/|$)#', wp_normalize_path( $path ) ) ) { 651 return true; 652 } 653 654 // Resolve the true location of the requested file for later comparison. 655 $real_path = realpath( $path ); 656 657 if ( false === $real_path ) { 658 return false; 659 } 660 661 $real_path = trailingslashit( wp_normalize_path( $real_path ) ); 662 663 $directories = array( 664 STYLESHEETPATH, 665 TEMPLATEPATH, 666 ABSPATH . WPINC . '/theme-compat', 667 ); 668 669 // If a theme is in a subdirectory, accept templates from its direct parent directory. 670 if ( false !== strpos( get_stylesheet(), '/' ) ) { 671 $directories[] = dirname( STYLESHEETPATH ); 672 } 673 674 // If a parent theme is in a subdirectory, accept templates from its direct parent directory. 675 if ( false !== strpos( get_template(), '/' ) ) { 676 $directories[] = dirname( TEMPLATEPATH ); 677 } 678 679 foreach ( $directories as $directory ) { 680 $real_directory = realpath( $directory ); 681 682 if ( false === $real_directory ) { 683 continue; 684 } 685 686 // The true location of the requested file must be inside one of the allowed directories. 687 if ( str_starts_with( $real_path, trailingslashit( wp_normalize_path( $real_directory ) ) ) ) { 688 return true; 689 } 690 } 691 692 return false; 693 } 694 695 /** 640 696 * Retrieve the name of the highest priority template file that exists. 641 697 * … … 644 700 * 645 701 * @since 2.7.0 702 * @since 7.1.2 A template name containing `..` is only located if it resolves inside the theme. 646 703 * 647 704 * @param string|array $template_names Template file(s) to search for, in order. … … 657 714 } 658 715 if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { 659 $located = STYLESHEETPATH . '/' . $template_name; 660 break; 716 $candidate = STYLESHEETPATH . '/' . $template_name; 661 717 } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { 662 $located = TEMPLATEPATH . '/' . $template_name; 663 break; 718 $candidate = TEMPLATEPATH . '/' . $template_name; 664 719 } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { 665 $located = ABSPATH . WPINC . '/theme-compat/' . $template_name; 720 $candidate = ABSPATH . WPINC . '/theme-compat/' . $template_name; 721 } else { 722 continue; 723 } 724 725 if ( _wp_is_template_path_allowed( $candidate ) ) { 726 $located = $candidate; 666 727 break; 667 728 }
Note:
See TracChangeset
for help on using the changeset viewer.