Make WordPress Core

Changeset 49563

Timestamp:
11/12/2020 04:14:44 AM (4 years ago)
Author:
peterwilsoncc
Message:

Canonical: Prevent ID enumeration of private post slugs.

Add check to redirect_canonical() to ensure the destination post is not using a private post status.

Props dd32, Denis-de-Bernardy, donmhico, helen, nacin, peterwilsoncc, pishmishy, TimothyBlynJacobs, tzafrir, Viper007Bond, whyisjake.
Fixes #5272.

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r49200 r49563  
    7878    $redirect     = $original;
    7979    $redirect_url = false;
     80
    8081
    8182    // Notice fixing.
     
    103104    if ( is_feed() && $post_id ) {
    104105        $redirect_url = get_post_comments_feed_link( $post_id, get_query_var( 'feed' ) );
     106
    105107
    106108        if ( $redirect_url ) {
     
    127129
    128130            $redirect_url = get_permalink( $post_id );
     131
    129132
    130133            if ( $redirect_url ) {
     
    151154            if ( $post_type_obj->public && 'auto-draft' !== $redirect_post->post_status ) {
    152155                $redirect_url = get_permalink( $redirect_post );
     156
    153157
    154158                $redirect['query'] = _remove_qs_args_if_not_in_url(
     
    198202            if ( $post_id ) {
    199203                $redirect_url = get_permalink( $post_id );
     204
    200205
    201206                $redirect['path']  = rtrim( $redirect['path'], (int) get_query_var( 'page' ) . '/' );
     
    224229            if ( ! empty( $_GET['attachment_id'] ) ) {
    225230                $redirect_url = get_attachment_link( get_query_var( 'attachment_id' ) );
     231
    226232
    227233                if ( $redirect_url ) {
     
    230236            } else {
    231237                $redirect_url = get_attachment_link();
     238
    232239            }
    233240        } elseif ( is_single() && ! empty( $_GET['p'] ) && ! $redirect_url ) {
    234241            $redirect_url = get_permalink( get_query_var( 'p' ) );
     242
    235243
    236244            if ( $redirect_url ) {
     
    239247        } elseif ( is_single() && ! empty( $_GET['name'] ) && ! $redirect_url ) {
    240248            $redirect_url = get_permalink( $wp_query->get_queried_object_id() );
     249
    241250
    242251            if ( $redirect_url ) {
     
    245254        } elseif ( is_page() && ! empty( $_GET['page_id'] ) && ! $redirect_url ) {
    246255            $redirect_url = get_permalink( get_query_var( 'page_id' ) );
     256
    247257
    248258            if ( $redirect_url ) {
     
    257267        ) {
    258268            $redirect_url = get_permalink( get_option( 'page_for_posts' ) );
     269
    259270
    260271            if ( $redirect_url ) {
     
    311322            ) {
    312323                $redirect_url = get_author_posts_url( $author->ID, $author->user_nicename );
     324
    313325
    314326                if ( $redirect_url ) {
     
    386398                ) {
    387399                    $redirect_url = get_permalink( $wp_query->get_queried_object_id() );
     400
    388401                }
    389402            }
     
    396409            if ( ! $redirect_url ) {
    397410                $redirect_url = get_permalink( get_queried_object_id() );
     411
    398412            }
    399413
     
    741755    }
    742756
     757
     758
     759
     760
     761
     762
     763
     764
     765
     766
     767
     768
     769
     770
     771
     772
     773
     774
     775
     776
     777
     778
     779
     780
     781
     782
    743783    /**
    744784     * Filters the canonical redirect URL.
  • trunk/src/wp-includes/link-template.php

    r49222 r49563  
    419419    if ( $parent && ! in_array( $parent->post_type, get_post_types(), true ) ) {
    420420        $parent = false;
     421
     422
     423
     424
     425
     426
     427
     428
     429
     430
     431
    421432    }
    422433
Note: See TracChangeset for help on using the changeset viewer.