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