Changeset 52304 for trunk/src/wp-includes/kses.php
- Timestamp:
- 12/02/2021 12:54:03 AM (4 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/kses.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/kses.php
r52234 r52304 273 273 ), 274 274 'object' => array( 275 'data' => true, 275 'data' => array( 276 'required' => true, 277 'value_callback' => '_wp_kses_allow_pdf_objects', 278 ), 276 279 'type' => array( 277 280 'required' => true, … … 1662 1665 } 1663 1666 break; 1667 1668 case 'value_callback': 1669 /* 1670 * The value_callback check is used when you want to make sure that the attribute 1671 * value is accepted by the callback function. 1672 */ 1673 1674 if ( ! call_user_func( $checkvalue, $value ) ) { 1675 $ok = false; 1676 } 1677 break; 1664 1678 } // End switch. 1665 1679 … … 2567 2581 return $value; 2568 2582 } 2583 2584 /** 2585 * Helper function to check if this is a safe PDF URL. 2586 * 2587 * @since 5.9.0 2588 * @access private 2589 * @ignore 2590 * 2591 * @param string $url The URL to check. 2592 * @return bool True if the URL is safe, false otherwise. 2593 */ 2594 function _wp_kses_allow_pdf_objects( $value ) { 2595 // We're not interested in URLs that contain query strings or fragments. 2596 if ( strpos( $value, '?' ) !== false || strpos( $value, '#' ) !== false ) { 2597 return false; 2598 } 2599 2600 // If it doesn't have a PDF extension, it's not safe. 2601 if ( 0 !== substr_compare( $value, '.pdf', -4, 4, true ) ) { 2602 return false; 2603 } 2604 2605 // If the URL host matches the current site's media URL, it's safe. 2606 $upload_info = wp_upload_dir( null, false ); 2607 $upload_host = wp_parse_url( $upload_info['url'], PHP_URL_HOST ); 2608 if ( 0 === strpos( $value, "http://$upload_host/" ) || 0 === strpos( $value, "https://$upload_host/" ) ) { 2609 return true; 2610 } 2611 2612 return false; 2613 }
Note: See TracChangeset
for help on using the changeset viewer.