Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -4903,7 +4903,7 @@ function get_the_taxonomies( $post = 0, $args = array() ) {
$links = array();

foreach ( $terms as $term ) {
$links[] = wp_sprintf( $t['term_template'], esc_attr( get_term_link( $term ) ), $term->name );
$links[] = wp_sprintf( $t['term_template'], esc_url( get_term_link( $term ) ), $term->name );
}
if ( $links ) {
$taxonomies[ $taxonomy ] = wp_sprintf( $t['template'], $t['label'], $links, $terms );
Expand Down
19 changes: 19 additions & 0 deletions tests/phpunit/tests/taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ public function test_get_the_taxonomies_term_template() {
$this->assertSame( 'Categories: <span class="foo"><a href="' . $link . '">Uncategorized</a></span>.', $taxes['category'] );
}

/**
* The term URL fills an `href`, so it must be escaped with esc_url() to
* enforce the protocol allowlist, matching get_the_term_list(). A term_link
* filter returning a javascript: URL must not survive into the markup.
*/
public function test_get_the_taxonomies_escapes_term_url() {
$post_id = self::factory()->post->create();

add_filter( 'term_link', array( $this, 'filter_term_link_to_js' ) );
$taxes = get_the_taxonomies( $post_id );
remove_filter( 'term_link', array( $this, 'filter_term_link_to_js' ) );

$this->assertStringNotContainsString( 'javascript:', $taxes['category'] );
}

public function filter_term_link_to_js() {
return 'javascript:alert(1)';
}

public function test_the_taxonomies() {
$post_id = self::factory()->post->create();

Expand Down
Loading