aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-07-19 22:52:06 +0200
committerGravatar GitHub <noreply@github.com> 2025-07-19 22:52:06 +0200
commit01eae00ca2a5532b18682dfc55c83fce8725ee30 (patch)
tree969da6ceff8b1b06ee8ba98888f30cb869b17e5f /app
parent0d158f37621e116767383c0fa7b8c4a141a360a7 (diff)
WebSub: only perform a redirect when coming from WebSub (#7738)
And add support for HTTP Link header for "self" URL Changing URL based on "self" URL will only be done when coming from a WebSub push fix https://github.com/FreshRSS/FreshRSS/issues/7737
Diffstat (limited to 'app')
-rwxr-xr-xapp/Controllers/feedController.php41
-rw-r--r--app/Models/Feed.php4
2 files changed, 27 insertions, 18 deletions
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index 075ecb5e6..2aae5a0a8 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -393,12 +393,14 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
}
/**
+ * @param \SimplePie\SimplePie|null $simplePiePush Used by WebSub (PubSubHubbub) to push updates
+ * @param string $selfUrl Used by WebSub (PubSubHubbub) to override the feed URL
* @return array{0:int,1:FreshRSS_Feed|null,2:int,3:array<FreshRSS_Feed>} Number of updated feeds, first feed or null, number of new articles,
* list of feeds for which a cache refresh is needed
* @throws FreshRSS_BadUrl_Exception
*/
public static function actualizeFeeds(?int $feed_id = null, ?string $feed_url = null, ?int $maxFeeds = null,
- ?\SimplePie\SimplePie $simplePiePush = null): array {
+ ?\SimplePie\SimplePie $simplePiePush = null, string $selfUrl = ''): array {
if (function_exists('set_time_limit')) {
@set_time_limit(300);
}
@@ -422,6 +424,9 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
if ($feed_id !== null || $feed_url !== null) {
$feed = $feed_id !== null ? $feedDAO->searchById($feed_id) : $feedDAO->searchByUrl($feed_url);
if ($feed !== null && $feed->id() > 0) {
+ if ($selfUrl !== '') {
+ $feed->_selfUrl($selfUrl);
+ }
$feeds[] = $feed;
$feed_id = $feed->id();
}
@@ -692,22 +697,19 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
$feedProperties['attributes'] = $feed->attributes();
}
- if ($pubsubhubbubEnabledGeneral && $feed->hubUrl() !== '' && $feed->selfUrl() !== '') { //selfUrl has priority for WebSub
- if ($feed->selfUrl() !== $url) { // https://github.com/pubsubhubbub/PubSubHubbub/wiki/Moving-Feeds-or-changing-Hubs
- $selfUrl = checkUrl($feed->selfUrl());
- if ($selfUrl != false) {
- Minz_Log::debug('WebSub unsubscribe ' . $feed->url(false));
- if (!$feed->pubSubHubbubSubscribe(false)) { //Unsubscribe
- Minz_Log::warning('Error while WebSub unsubscribing from ' . $feed->url(false));
- }
- $feed->_url($selfUrl, false);
- Minz_Log::notice('Feed ' . $url . ' canonical address moved to ' . $feed->url(false));
- $feedDAO->updateFeed($feed->id(), ['url' => $feed->url()]);
- }
+ if ($feed->url() !== $url) { // HTTP 301 Moved Permanently
+ Minz_Log::warning('Feed ' . \SimplePie\Misc::url_remove_credentials($url) .
+ ' moved permanently to ' . $feed->url(includeCredentials: false));
+ $feedProperties['url'] = $feed->url();
+ } elseif ($simplePiePush !== null && $selfUrl !== '' && $selfUrl !== $feed->url()) { // selfUrl has priority for WebSub
+ // https://github.com/pubsubhubbub/PubSubHubbub/wiki/Moving-Feeds-or-changing-Hubs
+ Minz_Log::debug('WebSub unsubscribe ' . $feed->url(includeCredentials: false));
+ if (!$feed->pubSubHubbubSubscribe(false)) { //Unsubscribe
+ Minz_Log::warning('Error while WebSub unsubscribing from ' . $feed->url(includeCredentials: false));
}
- } elseif ($feed->url() !== $url) { // HTTP 301 Moved Permanently
- Minz_Log::notice('Feed ' . \SimplePie\Misc::url_remove_credentials($url) .
- ' moved permanently to ' . \SimplePie\Misc::url_remove_credentials($feed->url(false)));
+ $feed->_url($selfUrl);
+ Minz_Log::warning('Feed ' . \SimplePie\Misc::url_remove_credentials($url) .
+ ' canonical address moved to ' . $feed->url(includeCredentials: false));
$feedProperties['url'] = $feed->url();
}
@@ -826,14 +828,17 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
}
/**
+ * @param \SimplePie\SimplePie|null $simplePiePush Used by WebSub (PubSubHubbub) to push updates
+ * @param string $selfUrl Used by WebSub (PubSubHubbub) to override the feed URL
* @return array{0:int,1:FreshRSS_Feed|null,2:int,3:array<FreshRSS_Feed>} Number of updated feeds, first feed or null, number of new articles,
* list of feeds for which a cache refresh is needed
* @throws FreshRSS_BadUrl_Exception
*/
public static function actualizeFeedsAndCommit(?int $feed_id = null, ?string $feed_url = null, ?int $maxFeeds = null,
- ?SimplePie\SimplePie $simplePiePush = null): array {
+ ?SimplePie\SimplePie $simplePiePush = null, string $selfUrl = ''): array {
$entryDAO = FreshRSS_Factory::createEntryDao();
- [$nbUpdatedFeeds, $feed, $nbNewArticles, $feedsCacheToRefresh] = FreshRSS_feed_Controller::actualizeFeeds($feed_id, $feed_url, $maxFeeds, $simplePiePush);
+ [$nbUpdatedFeeds, $feed, $nbNewArticles, $feedsCacheToRefresh] =
+ FreshRSS_feed_Controller::actualizeFeeds($feed_id, $feed_url, $maxFeeds, $simplePiePush, $selfUrl);
if ($nbNewArticles > 0) {
$entryDAO->beginTransaction();
FreshRSS_feed_Controller::commitNewEntries();
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index b91d1af75..171b054ca 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -463,6 +463,10 @@ class FreshRSS_Feed extends Minz_Model {
$this->url = $url;
}
+ public function _selfUrl(string $value): void {
+ $this->selfUrl = $value;
+ }
+
public function _kind(int $value): void {
$this->kind = $value;
}