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