Make WordPress Core

Changeset 44156


Ignore:
Timestamp:
12/14/2018 03:27:55 AM (8 years ago)
Author:
pento
Message:

KSES: Allow the download attribute on <a> tags.

To avoid this being a vector for bypassing the filetypes that are allowed to be uploaded, this attribute is only allowed to be added without a value.

Merges [43813] from the 5.0 branch to trunk.

Props kalpshit, arshidkv12, welcher, peterwilsoncc, marina_wp, pento.
Fixes #44724.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/kses.php

    r44136 r44156  
    6262                'address'    => array(),
    6363                'a'          => array(
    64                         'href'   => true,
    65                         'rel'    => true,
    66                         'rev'    => true,
    67                         'name'   => true,
    68                         'target' => true,
     64                        'href'     => true,
     65                        'rel'      => true,
     66                        'rev'      => true,
     67                        'name'     => true,
     68                        'target'   => true,
     69                        'download' => array(
     70                                'valueless' => 'y',
     71                        ),
    6972                ),
    7073                'abbr'       => array(),
  • trunk/tests/phpunit/tests/kses.php

    r44136 r44156  
    3838
    3939                $attributes = array(
    40                         'class'  => 'classname',
    41                         'id'     => 'id',
    42                         'style'  => 'color: red;',
    43                         'title'  => 'title',
    44                         'href'   => 'http://example.com',
    45                         'rel'    => 'related',
    46                         'rev'    => 'revision',
    47                         'name'   => 'name',
    48                         'target' => '_blank',
     40                        'class'    => 'classname',
     41                        'id'       => 'id',
     42                        'style'    => 'color: red;',
     43                        'title'    => 'title',
     44                        'href'     => 'http://example.com',
     45                        'rel'      => 'related',
     46                        'rev'      => 'revision',
     47                        'name'     => 'name',
     48                        'target'   => '_blank',
     49                        'download' => '',
    4950                );
    5051
    5152                foreach ( $attributes as $name => $value ) {
    52                         $string        = "<a $name='$value'>I link this</a>";
    53                         $expect_string = "<a $name='" . trim( $value, ';' ) . "'>I link this</a>";
     53                        if ( $value ) {
     54                                $attr          = "$name='$value'";
     55                                $expected_attr = "$name='" . trim( $value, ';' ) . "'";
     56                        } else {
     57                                $attr = $expected_attr = $name;
     58                        }
     59                        $string        = "<a $attr>I link this</a>";
     60                        $expect_string = "<a $expected_attr>I link this</a>";
    5461                        $this->assertEquals( $expect_string, wp_kses( $string, $allowedposttags ) );
    5562                }
Note: See TracChangeset for help on using the changeset viewer.