From edc750fe444b6af65eccee879a048cf3e0cdd215 Mon Sep 17 00:00:00 2001 From: rupak Date: Thu, 29 Jan 2026 14:53:08 +0545 Subject: pubSub, if hub have same host it can be reached without being public (#8450) Compares host of hub and baseUrl, to detect they can connect each other ofr pubSubHub Helps https://github.com/FreshRSS/FreshRSS/issues/8442 Changes proposed in this pull request: - if host of hub and baseUrl are same then they hub can access freshrss even in localhost How to test the feature manually: - Create pubsub server on localhost and connect to RSS instance on localhost. --------- Co-authored-by: Alexandre Alapetite --- app/Models/Feed.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 511bdc54a..6a995fef0 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -1322,9 +1322,17 @@ class FreshRSS_Feed extends Minz_Model { return false; } + private static function isSameHost(string $url1, string $url2): bool { + $hubHost = parse_url($url1, PHP_URL_HOST); + $baseHost = parse_url($url2, PHP_URL_HOST); + return ($hubHost != null && $baseHost != null && strcasecmp($hubHost, $baseHost) === 0); + } + public function pubSubHubbubPrepare(): string|false { $key = ''; - if (Minz_Request::serverIsPublic(FreshRSS_Context::systemConf()->base_url) && + $baseUrl = FreshRSS_Context::systemConf()->base_url; + // If they have the same host, they can reach each other (e.g., localhost to localhost) + if ((Minz_Request::serverIsPublic($baseUrl) || self::isSameHost($this->hubUrl, $baseUrl)) && $this->hubUrl !== '' && $this->selfUrl !== '' && @is_dir(PSHB_PATH)) { $path = PSHB_PATH . '/feeds/' . sha1($this->selfUrl); $hubFilename = $path . '/!hub.json'; @@ -1376,7 +1384,9 @@ class FreshRSS_Feed extends Minz_Model { } else { $url = $this->url; //Always use current URL during unsubscribe } - if ($url !== '' && (Minz_Request::serverIsPublic(FreshRSS_Context::systemConf()->base_url) || !$state)) { + $baseUrl = FreshRSS_Context::systemConf()->base_url; + // If they have the same host, they can reach each other (e.g., localhost to localhost) + if ($url !== '' && (Minz_Request::serverIsPublic($baseUrl) || self::isSameHost($url, $baseUrl) || !$state)) { $hubFilename = PSHB_PATH . '/feeds/' . sha1($url) . '/!hub.json'; $hubFile = @file_get_contents($hubFilename); if ($hubFile === false) { -- cgit v1.2.3