Make WordPress Core


Ignore:
Timestamp:
02/02/2021 12:38:40 AM (5 years ago)
Author:
peterwilsoncc
Message:

Canonical: Prevent ID enumeration of private post slugs.

Add check to redirect_canonical() to ensure private posts only redirect for logged in users.

Modifies the read_post mata capability to user get_post_status() rather than the post's post_status property to allow attachments to redirect based on the inherited post status.

Introduces wp_force_ugly_post_permalink() to unify the check to determine if an ugly link should be displayed in each of the functions used for determining permalinks: get_permalink(), get_post_permalink(), _get_page_link() and get_attachment_link().

Improves logic of get_attachment_link() to validate parent post and resolution of inherited post status. This is an incomplete fix of #52373 to prevent the function returning links resulting in a file not found error. Required to unblock this ticket.

Props peterwilsoncc, TimothyBlynJacobs.
See #52373.
Fixes #5272.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r49974 r50132  
    31233123     *
    31243124     * @param string $post_key     Post as keyed in the shared fixture array.
    3125      * @param string $expected     Expected result.
     3125     * @param string $expected_url Expected permalink.
    31263126     * @param bool   $expected_404 Whether the page is expected to return a 404 result.
    31273127     *
    31283128     */
    3129     function test_attachment_permalinks_based_on_parent_status( $post_key, $expected, $expected_404 ) {
     3129    function test_attachment_permalinks_based_on_parent_status( $post_key, $expected_url, $expected_404 ) {
    31303130        $this->set_permalink_structure( '/%postname%' );
    31313131        $post = get_post( self::$post_ids[ $post_key ] );
     
    31353135         * post object IDs are placeholders that needs to be replaced.
    31363136         */
    3137         $expected = home_url( str_replace( '%ID%', $post->ID, $expected ) );
    3138 
    3139         $this->assertSame( $expected, get_permalink( $post ) );
     3137        $expected_url = home_url( str_replace( '%ID%', $post->ID, $expected_url ) );
     3138
    31403139        $this->go_to( get_permalink( $post ) );
    3141         $this->assertSame( $expected_404, is_404() );
     3140        $this->assertSame( $expected_url, get_permalink( $post ) );
     3141        if ( $expected_404 ) {
     3142            $this->assertQueryTrue( 'is_404' );
     3143        } else {
     3144            $this->assertQueryTrue( 'is_attachment', 'is_single', 'is_singular' );
     3145        }
     3146        $this->assertSame( 'attachment', $post->post_type );
    31423147    }
    31433148
     
    31473152     * @return array[] {
    31483153     *     @type string $post_key     Post as keyed in the shared fixture array.
    3149      *     @type string $expected     Expected result.
     3154     *     @type string $expected_url Expected permalink.
    31503155     *     $type bool   $expected_404 Whether the page is expected to return a 404 result.
    31513156     * }
Note: See TracChangeset for help on using the changeset viewer.