Skip to content

Commit

Permalink
Sanitize the iCal URL before initializing (#2607)
Browse files Browse the repository at this point in the history
* Sanitize the iCal URL before initializing

* Escape the URL

* Refuse localhost URLs in events block

* sanitize_url

* Update error string

* esc_url_raw()
  • Loading branch information
EvanHerman authored Apr 30, 2024
1 parent f64b933 commit b5b5fb7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/blocks/events/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function coblocks_render_coblocks_events_block( $attributes, $content ) {
return $content;
}

// If externalCalendarUrl contains a localhost URL, return an error message.
if ( strpos( $attributes['externalCalendarUrl'], 'localhost' ) !== false || strpos( $attributes['externalCalendarUrl'], '127.0' ) !== false ) {
return '<div class="components-placeholder"><div class="notice notice-error">' . __( 'An error has occurred. localhost URLs are not permitted.', 'coblocks' ) . '</div></div>';
}

try {
$ical = new \CoBlocks_ICal(
false,
Expand All @@ -34,7 +39,7 @@ function coblocks_render_coblocks_events_block( $attributes, $content ) {
'use_timezone_with_r_rules' => false,
)
);
$ical->init_url( $attributes['externalCalendarUrl'] );
$ical->init_url( esc_url_raw( $attributes['externalCalendarUrl'] ) );

if ( 'all' === $attributes['eventsRange'] ) {
$events = $ical->events_from_range();
Expand Down

0 comments on commit b5b5fb7

Please sign in to comment.