فهرست منبع

Add checkUrl() to favicon functions (#8714)

* Add checkUrl() to favicon functions

* Update lib/favicons.php

Co-authored-by: Inverle <inverle@proton.me>

---------

Co-authored-by: Inverle <inverle@proton.me>
Alexandre Alapetite 3 هفته پیش
والد
کامیت
1a490f778f
2فایلهای تغییر یافته به همراه18 افزوده شده و 6 حذف شده
  1. 13 6
      lib/favicons.php
  2. 5 0
      p/f.php

+ 13 - 6
lib/favicons.php

@@ -68,7 +68,11 @@ function searchFavicon(string $url): string {
 
 		$iri = $href->get_iri();
 		if ($iri == false) {
-			return '';
+			continue;
+		}
+		$iri = FreshRSS_http_Util::checkUrl($iri, fixScheme: false);
+		if (!is_string($iri) || $iri === '') {
+			continue;
 		}
 		$favicon = FreshRSS_http_Util::httpGet($iri, faviconCachePath($iri), 'ico', curl_options: [
 			CURLOPT_REFERER => $effective_url,
@@ -85,8 +89,8 @@ function searchFavicon(string $url): string {
  * Returns false without any fallback if the URL does not point to a valid image.
  */
 function download_favicon_from_image_url(string $imageUrl, string $dest): bool {
-	$imageUrl = trim($imageUrl);
-	if ($imageUrl === '') {
+	$imageUrl = FreshRSS_http_Util::checkUrl($imageUrl);
+	if (!is_string($imageUrl) || $imageUrl === '') {
 		return false;
 	}
 	$favicon = FreshRSS_http_Util::httpGet($imageUrl, faviconCachePath($imageUrl), 'ico')['body'];
@@ -97,7 +101,10 @@ function download_favicon_from_image_url(string $imageUrl, string $dest): bool {
 }
 
 function download_favicon(string $url, string $dest): bool {
-	$url = trim($url);
+	$url = FreshRSS_http_Util::checkUrl($url);
+	if (!is_string($url) || $url === '') {
+		return @copy(DEFAULT_FAVICON, $dest);
+	}
 	$favicon = searchFavicon($url);
 	if ($favicon == '') {
 		$rootUrl = preg_replace('%^(https?://[^/]+).*$%i', '$1/', $url) ?? $url;
@@ -106,8 +113,8 @@ function download_favicon(string $url, string $dest): bool {
 			$favicon = searchFavicon($url);
 		}
 		if ($favicon == '') {
-			$link = $rootUrl . 'favicon.ico';
-			$favicon = FreshRSS_http_Util::httpGet($link, faviconCachePath($link), 'ico', curl_options: [
+			$link = FreshRSS_http_Util::checkUrl($rootUrl . 'favicon.ico', fixScheme: false) ?: '';
+			$favicon = $link === '' ? '' : FreshRSS_http_Util::httpGet($link, faviconCachePath($link), 'ico', curl_options: [
 				CURLOPT_REFERER => $url,
 			])['body'];
 			if (!isImgMime($favicon)) {

+ 5 - 0
p/f.php

@@ -51,6 +51,11 @@ if (($ico_mtime == false || $ico_mtime < $txt_mtime || ($ico_mtime < time() - (r
 		show_default_favicon(1800);
 		exit();
 	}
+	$url = FreshRSS_http_Util::checkUrl($url) ?: '';
+	if ($url === '') {
+		show_default_favicon(1800);
+		exit();
+	}
 
 	// Try downloading the URL as a direct image first (e.g. from a feed's <image><url>),
 	// then fall back to HTML favicon search if it is not a valid image.