Skip to:
Content

bbPress.org


Ignore:
Timestamp:
03/17/2017 02:51:45 PM (7 years ago)
Author:
johnjamesjacoby
Message:

Tests: Add XSS tests for topic titles.

These are in addition to post-title tests already present in WordPress core, for cases where theme-side, user-generated content is more likely to be targeted by less-trustworthy users than Editors or Administrators.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/testcases/topics/template/topic.php

    r5947 r6379  
    9292
    9393    /**
     94     * @covers ::bbp_topic_title
     95     * @covers ::bbp_get_topic_title
     96     * @group  bbp_xss
     97     */
     98    public function test_bbp_get_topic_title_with_script_and_quotes() {
     99        $f = $this->factory->forum->create();
     100        $t = $this->factory->topic->create( array(
     101            'post_title'  => '<script src="https://bbpress.org">Script</script> Topic',
     102            'post_parent' => $f,
     103            'topic_meta'  => array(
     104                'forum_id' => $f,
     105            ),
     106        ) );
     107
     108        $topic_title = bbp_get_topic_title( $t );
     109        $this->assertSame( 'Script Topic', $topic_title );
     110    }
     111
     112    /**
     113     * @covers ::bbp_topic_title
     114     * @covers ::bbp_get_topic_title
     115     * @group  bbp_xss
     116     */
     117    public function test_bbp_get_topic_title_with_script_no_quotes() {
     118        $f = $this->factory->forum->create();
     119        $t = $this->factory->topic->create( array(
     120            'post_title'  => '<script src=https://bbpress.org>Script</script> Topic',
     121            'post_parent' => $f,
     122            'topic_meta'  => array(
     123                'forum_id' => $f,
     124            ),
     125        ) );
     126
     127        $topic_title = bbp_get_topic_title( $t );
     128        $this->assertSame( 'Script Topic', $topic_title );
     129    }
     130
     131    /**
     132     * @covers ::bbp_topic_title
     133     * @covers ::bbp_get_topic_title
     134     * @group  bbp_xss
     135     */
     136    public function test_bbp_get_topic_title_with_quotes() {
     137        $f = $this->factory->forum->create();
     138        $t = $this->factory->topic->create( array(
     139            'post_title'  => '"Quoted" Topic',
     140            'post_parent' => $f,
     141            'topic_meta'  => array(
     142                'forum_id' => $f,
     143            ),
     144        ) );
     145
     146        $topic_title = bbp_get_topic_title( $t );
     147        $this->assertSame( '&#8220;Quoted&#8221; Topic', $topic_title );
     148    }
     149
     150    /**
     151     * @covers ::bbp_topic_title
     152     * @covers ::bbp_get_topic_title
     153     * @group  bbp_xss
     154     */
     155    public function test_bbp_get_topic_title_with_js_as_img_src() {
     156        $f = $this->factory->forum->create();
     157        $t = $this->factory->topic->create( array(
     158            'post_title'  => '<img src="javascript:alert(\'Oh, bother!\');">Topic 1',
     159            'post_parent' => $f,
     160            'topic_meta'  => array(
     161                'forum_id' => $f,
     162            ),
     163        ) );
     164
     165        $topic_title = bbp_get_topic_title( $t );
     166        $this->assertSame( 'Topic 1', $topic_title );
     167    }
     168
     169    /**
     170     * @covers ::bbp_topic_title
     171     * @covers ::bbp_get_topic_title
     172     * @group  bbp_xss
     173     */
     174    public function test_bbp_get_topic_title_with_extra_open_brackets() {
     175        $f = $this->factory->forum->create();
     176        $t = $this->factory->topic->create( array(
     177            'post_title'  => '<<script>alert("XSS");//<</script>',
     178            'post_parent' => $f,
     179            'topic_meta'  => array(
     180                'forum_id' => $f,
     181            ),
     182        ) );
     183
     184        $topic_title = bbp_get_topic_title( $t );
     185        $this->assertSame( '&lt;alert(&#8220;XSS&#8221;);//&lt;', $topic_title );
     186    }
     187
     188    /**
    94189     * @covers ::bbp_topic_archive_title
    95190     * @covers ::bbp_get_topic_archive_title
Note: See TracChangeset for help on using the changeset viewer.