Skip to:
Content

bbPress.org

Changeset 7465


Ignore:
Timestamp:
09/09/2026 07:17:33 AM (2 weeks ago)
Author:
johnjamesjacoby
Message:

Topic Tags: Escape names before template output.

This change hardens all current topic-tag name presentation contexts, including copied template overrides, by applying HTML escaping through the existing getter filter. It preserves extension behavior at the standard filter priority and avoids double-encoding stored entities.

In trunk, for 2.7.

Props faran66.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CHANGELOG.md

    r7463 r7465  
    5050### Security
    5151
     52- Hardened topic-tag name output with consistent HTML escaping.
    5253- Prevented topic-tag names from being interpreted as JavaScript in confirmation
    5354  prompts.
  • trunk/src/includes/core/filters.php

    r7461 r7465  
    230230        add_filter( 'bbp_get_topic_content', 'bbp_topic_content_append_revisions',  99,  2 );
    231231}
     232
     233// Topic tag output - sanitize
     234add_filter( 'bbp_get_topic_tag_name', 'esc_html' );
    232235
    233236// Form textarea output - undo the code-trick done pre-save, and sanitize
  • trunk/tests/phpunit/testcases/topics/template/topic-tag.php

    r5756 r7465  
    7373         * @covers ::bbp_topic_tag_name
    7474         * @covers ::bbp_get_topic_tag_name
    75          * @todo   Implement test_bbp_get_topic_tag_name().
    7675         */
    7776        public function test_bbp_get_topic_tag_name() {
    78                 // Remove the following lines when you implement this test.
    79                 $this->markTestIncomplete(
    80                         'This test has not been implemented yet.'
     77                $term = wp_insert_term(
     78                        'Rock & Roll\'s <tag>',
     79                        bbp_get_topic_tag_tax_id(),
     80                        array( 'slug' => 'rock-and-roll' )
    8181                );
     82
     83                $this->assertFalse( is_wp_error( $term ) );
     84                $topic_tag_name = bbp_get_topic_tag_name( 'rock-and-roll' );
     85
     86                $this->assertSame( 'Rock & Roll's <tag>', $topic_tag_name );
     87                $this->assertSame( 'Rock & Roll's <tag>', esc_attr( $topic_tag_name ) );
     88
     89                $filter = static function() {
     90                        return '<img src=x onerror=alert(document.domain)>';
     91                };
     92
     93                add_filter( 'bbp_get_topic_tag_name', $filter, 9 );
     94                $topic_tag_name = bbp_get_topic_tag_name( 'rock-and-roll' );
     95                remove_filter( 'bbp_get_topic_tag_name', $filter, 9 );
     96
     97                $this->assertSame( '&lt;img src=x onerror=alert(document.domain)&gt;', $topic_tag_name );
    8298        }
    8399
Note: See TracChangeset for help on using the changeset viewer.