fix: skip invalid URLs from SDIR

dev
gravel 2 years ago
parent 841f880c7a
commit 26502b1ca0
Signed by: gravel
GPG Key ID: C0538F3C906B308F

@ -1640,7 +1640,7 @@
$pubkey_old = $this->get_pubkey(); $pubkey_old = $this->get_pubkey();
$pubkey_new = url_get_pubkey($link); $pubkey_new = url_get_pubkey($link);
log_error( log_error(
"Key collision for $base_url:" . "Key mismatch for $base_url:" .
"Have $pubkey_old, fetched $pubkey_new from $preview_url" "Have $pubkey_old, fetched $pubkey_new from $preview_url"
); );
return false; return false;

@ -49,7 +49,8 @@
private static function sdir_validate_entry( private static function sdir_validate_entry(
array $room_entry, array $room_entry,
bool &$missing_url, bool &$missing_url,
bool &$missing_tags bool &$missing_tags,
bool &$invalid_url
): bool { ): bool {
if (!isset($room_entry['url']) || !is_string($room_entry['url'])) { if (!isset($room_entry['url']) || !is_string($room_entry['url'])) {
log_value($room_entry); log_value($room_entry);
@ -63,10 +64,16 @@
return false; return false;
} }
if (!filter_var($room_entry['url'], FILTER_VALIDATE_URL)) {
log_value($room_entry);
$invalid_url = true;
return false;
}
return true; return true;
} }
private static function sdir_report_errors(bool $entry_missing_url, bool $entry_missing_tags) { private static function sdir_report_errors(bool $entry_missing_url, bool $entry_missing_tags, bool $entry_invalid_url) {
if ($entry_missing_url) { if ($entry_missing_url) {
log_error("One or more room entries from session.directory is missing the 'url' parameter."); log_error("One or more room entries from session.directory is missing the 'url' parameter.");
} }
@ -74,6 +81,10 @@
if ($entry_missing_tags) { if ($entry_missing_tags) {
log_error("One or more room entries from session.directory is missing the 'tags' parameter."); log_error("One or more room entries from session.directory is missing the 'tags' parameter.");
} }
if ($entry_invalid_url) {
log_warning("One or more room entries from session.directory contain an invalid 'url' parameter.");
}
} }
private function get_sdir_entries(): array|bool { private function get_sdir_entries(): array|bool {
@ -97,7 +108,7 @@
foreach ($rooms as $room_entry) { foreach ($rooms as $room_entry) {
if (!SDIRCommunitySource::sdir_validate_entry( if (!SDIRCommunitySource::sdir_validate_entry(
$room_entry, $entry_missing_url, $entry_missing_tags $room_entry, $entry_missing_url, $entry_missing_tags, $entry_invalid_url
)) { )) {
continue; continue;
} }
@ -116,7 +127,7 @@
} }
} }
SDIRCommunitySource::sdir_report_errors($entry_missing_url, $entry_missing_tags); SDIRCommunitySource::sdir_report_errors($entry_missing_url, $entry_missing_tags, $entry_invalid_url);
return true; return true;
} }

@ -130,11 +130,16 @@
/** /**
* Extracts the server public key from a join URL. * Extracts the server public key from a join URL.
* @param string $join_url Join URL for Session Community. * @param string $join_url Join URL for Session Community.
* @return string SOGS public key * @return string|null SOGS public key
*/ */
function url_get_pubkey(string $join_url) { function url_get_pubkey(string $join_url) {
$url_components = parse_url($join_url); $url_components = parse_url($join_url);
parse_str($url_components['query'], $query_components); $query = $url_components['query'] ?? "";
if ($query === "") {
log_value($join_url);
throw new DomainException("Join URL does not contain public key");
}
parse_str($query, $query_components);
return $query_components['public_key']; return $query_components['public_key'];
} }

Loading…
Cancel
Save