Changeset 63830
- Timestamp:
- 09/22/2026 03:29:23 PM (2 months ago)
- Location:
- branches/4.7
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/wp-includes/template.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.7
-
branches/4.7/src/wp-includes/template.php
r38951 r63830 416 416 if ( $pagename ) { 417 417 $pagename_decoded = urldecode( $pagename ); 418 if ( $pagename_decoded !== $pagename ) {418 if ( $pagename_decoded !== $pagename && 0 === validate_file( $pagename_decoded ) ) { 419 419 $templates[] = "page-{$pagename_decoded}.php"; 420 420 } … … 611 611 612 612 /** 613 * Determines whether a template found by locate_template() may be loaded. 614 * 615 * @since 7.1.2 616 * @access private 617 * 618 * @param string $path Path to an existing template file. 619 * @return bool Whether the template may be loaded. 620 */ 621 function _wp_is_template_path_allowed( $path ) { 622 // A file path that exists and does not contain `..` is allowed. 623 if ( 0 === preg_match( '#(?:^|/)\.\.[. ]*(?:/|$)#', wp_normalize_path( $path ) ) ) { 624 return true; 625 } 626 627 // Resolve the true location of the requested file for later comparison. 628 $real_path = realpath( $path ); 629 630 if ( false === $real_path ) { 631 return false; 632 } 633 634 $real_path = trailingslashit( wp_normalize_path( $real_path ) ); 635 636 $directories = array( 637 STYLESHEETPATH, 638 TEMPLATEPATH, 639 ABSPATH . WPINC . '/theme-compat', 640 ); 641 642 // If a theme is in a subdirectory, accept templates from its direct parent directory. 643 if ( false !== strpos( get_stylesheet(), '/' ) ) { 644 $directories[] = dirname( STYLESHEETPATH ); 645 } 646 647 // If a parent theme is in a subdirectory, accept templates from its direct parent directory. 648 if ( false !== strpos( get_template(), '/' ) ) { 649 $directories[] = dirname( TEMPLATEPATH ); 650 } 651 652 foreach ( $directories as $directory ) { 653 $real_directory = realpath( $directory ); 654 655 if ( false === $real_directory ) { 656 continue; 657 } 658 659 // The true location of the requested file must be inside one of the allowed directories. 660 if ( 0 === strpos( $real_path, trailingslashit( wp_normalize_path( $real_directory ) ) ) ) { 661 return true; 662 } 663 } 664 665 return false; 666 } 667 668 /** 613 669 * Retrieve the name of the highest priority template file that exists. 614 670 * … … 617 673 * 618 674 * @since 2.7.0 675 * @since 7.1.2 A template name containing `..` is only located if it resolves inside the theme. 619 676 * 620 677 * @param string|array $template_names Template file(s) to search for, in order. … … 629 686 continue; 630 687 if ( file_exists(STYLESHEETPATH . '/' . $template_name)) { 631 $located = STYLESHEETPATH . '/' . $template_name; 632 break; 688 $candidate = STYLESHEETPATH . '/' . $template_name; 633 689 } elseif ( file_exists(TEMPLATEPATH . '/' . $template_name) ) { 634 $located = TEMPLATEPATH . '/' . $template_name; 635 break; 690 $candidate = TEMPLATEPATH . '/' . $template_name; 636 691 } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) { 637 $located = ABSPATH . WPINC . '/theme-compat/' . $template_name; 692 $candidate = ABSPATH . WPINC . '/theme-compat/' . $template_name; 693 } else { 694 continue; 695 } 696 697 if ( _wp_is_template_path_allowed( $candidate ) ) { 698 $located = $candidate; 638 699 break; 639 700 }
Note:
See TracChangeset
for help on using the changeset viewer.