Skip to content

Commit 1c5d43b

Browse files
Infinite-NullInfinite-Nullt-hamanosabernhardtthisismyurl
authored
Fix: Escape URLs in block render functions using esc_url() (#78912)
* Enhance security by escaping URLs in post author name, post date, featured image, and read more blocks * Fix typo in URL escaping for post date link rendering Co-authored-by: Infinite-Null <ankitkumarshah@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: sabernhardt <sabernhardt@git.wordpress.org> Co-authored-by: thisismyurl <thisismyurl@git.wordpress.org>
1 parent b50c7db commit 1c5d43b

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎packages/block-library/src/post-author-name/index.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function render_block_core_post_author_name( $attributes, $content, $block ) {
3232

3333
$author_name = get_the_author_meta( 'display_name', $author_id );
3434
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
35-
$author_name = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a>', get_author_posts_url( $author_id ), esc_attr( $attributes['linkTarget'] ), $author_name );
35+
$author_name = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a>', esc_url( get_author_posts_url( $author_id ) ), esc_attr( $attributes['linkTarget'] ), $author_name );
3636
}
3737

3838
$classes = array();

‎packages/block-library/src/post-date/index.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function render_block_core_post_date( $attributes, $content, $block ) {
8484
$time_tag = sprintf( '<time datetime="%1$s">%2$s</time>', $unformatted_date, $formatted_date );
8585

8686
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] && isset( $block->context['postId'] ) ) {
87-
$time_tag = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $block->context['postId'] ), $time_tag );
87+
$time_tag = sprintf( '<a href="%1s">%2s</a>', esc_url( get_the_permalink( $block->context['postId'] ) ), $time_tag );
8888
}
8989

9090
return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $time_tag );

‎packages/block-library/src/post-featured-image/index.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
104104
$height = ! empty( $attributes['height'] ) ? 'style="' . esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . '"' : '';
105105
$featured_image = sprintf(
106106
'<a href="%1$s" target="%2$s" %3$s %4$s>%5$s%6$s</a>',
107-
get_the_permalink( $post_ID ),
107+
esc_url( get_the_permalink( $post_ID ) ),
108108
esc_attr( $link_target ),
109109
$rel,
110110
$height,

‎packages/block-library/src/read-more/index.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function render_block_core_read_more( $attributes, $content, $block ) {
4040
return sprintf(
4141
'<a %1s href="%2s" target="%3s">%4s<span class="screen-reader-text">%5s</span></a>',
4242
$wrapper_attributes,
43-
get_the_permalink( $post_ID ),
43+
esc_url( get_the_permalink( $post_ID ) ),
4444
esc_attr( $attributes['linkTarget'] ),
4545
$more_text,
4646
$screen_reader_text

0 commit comments

Comments
 (0)