Make WordPress Core


Ignore:
Timestamp:
12/03/2021 02:42:17 AM (5 years ago)
Author:
peterwilsoncc
Message:

KSES: Accept port number in PDF upload paths.

Improves the URL validation in _wp_kses_allow_pdf_objects() to account for sites using an upload path that contains a port, for example wp.org:8080.

Follow up to [51963], [52304].

Props ocean90, ramonopoly, talldanwp.
See #54261.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/kses.php

    r52304 r52309  
    25922592 * @return bool True if the URL is safe, false otherwise.
    25932593 */
    2594 function _wp_kses_allow_pdf_objects( $value ) {
     2594function _wp_kses_allow_pdf_objects( $url ) {
    25952595        // We're not interested in URLs that contain query strings or fragments.
    2596         if ( strpos( $value, '?' ) !== false || strpos( $value, '#' ) !== false ) {
     2596        if ( strpos( $url, '?' ) !== false || strpos( $url, '#' ) !== false ) {
    25972597                return false;
    25982598        }
    25992599
    26002600        // If it doesn't have a PDF extension, it's not safe.
    2601         if ( 0 !== substr_compare( $value, '.pdf', -4, 4, true ) ) {
     2601        if ( 0 !== substr_compare( $url, '.pdf', -4, 4, true ) ) {
    26022602                return false;
    26032603        }
     
    26052605        // If the URL host matches the current site's media URL, it's safe.
    26062606        $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/" ) ) {
     2607        $parsed_url  = wp_parse_url( $upload_info['url'] );
     2608        $upload_host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
     2609        $upload_port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
     2610        if ( 0 === strpos( $url, "http://$upload_host$upload_port/" ) || 0 === strpos( $url, "https://$upload_host$upload_port/" ) ) {
    26092611                return true;
    26102612        }
Note: See TracChangeset for help on using the changeset viewer.