Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize the iCal URL before initializing #2607

Merged
merged 6 commits into from
Apr 30, 2024
Merged
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
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
Loading