diff options
| author | 2025-07-19 22:52:06 +0200 | |
|---|---|---|
| committer | 2025-07-19 22:52:06 +0200 | |
| commit | 01eae00ca2a5532b18682dfc55c83fce8725ee30 (patch) | |
| tree | 969da6ceff8b1b06ee8ba98888f30cb869b17e5f /p/api/pshb.php | |
| parent | 0d158f37621e116767383c0fa7b8c4a141a360a7 (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 'p/api/pshb.php')
| -rw-r--r-- | p/api/pshb.php | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/p/api/pshb.php b/p/api/pshb.php index 6b5bda4b5..91dd4e901 100644 --- a/p/api/pshb.php +++ b/p/api/pshb.php @@ -104,13 +104,33 @@ $simplePie->init(); unset($ORIGINAL_INPUT); $links = $simplePie->get_links('self'); -$self = $links[0] ?? null; +$self = $links[0] ?? ''; + +// Support HTTP header `Link: <http://example.net/hub.php>; rel="hub", <http://example.net/feed.php>; rel="self"` +$httpLink = is_string($_SERVER['HTTP_LINK'] ?? null) ? $_SERVER['HTTP_LINK'] : ''; +if ($httpLink !== '' && preg_match_all('/<([^>]+)>;\\s*rel="([^"]+)"/', $httpLink, $matches, PREG_SET_ORDER)) { + $links = []; + foreach ($matches as $match) { + if (!empty($match[1]) && !empty($match[2])) { + $links[$match[2]] = $match[1]; + } + } + // if (!empty($links['hub'])) { + // // TODO: Support WebSub hub redirection + // } + if (!empty($links['self'])) { + $httpSelf = checkUrl($links['self']) ?: ''; + if ($self !== '' && $self !== $httpSelf) { + Minz_Log::warning('Warning: Self URL mismatch between XML [' . $self . '] and HTTP!: ' . $httpSelf, PSHB_LOG); + } + $self = $httpSelf; + } +} if ($self !== $canonical) { //header('HTTP/1.1 422 Unprocessable Entity'); Minz_Log::warning('Warning: Self URL [' . $self . '] does not match registered canonical URL!: ' . $canonical, PSHB_LOG); //die('Self URL does not match registered canonical URL!'); - $self = $canonical; } Minz_ExtensionManager::init(); @@ -120,7 +140,7 @@ $nb = 0; foreach ($users as $userFilename) { $username = basename($userFilename, '.txt'); if (!file_exists(USERS_PATH . '/' . $username . '/config.php')) { - Minz_Log::warning('Warning: Removing broken user link: ' . $username . ' for ' . $self, PSHB_LOG); + Minz_Log::warning('Warning: Removing broken user link: ' . $username . ' for ' . $canonical, PSHB_LOG); unlink($userFilename); continue; } @@ -134,15 +154,15 @@ foreach ($users as $userFilename) { Minz_ExtensionManager::enableByList(FreshRSS_Context::userConf()->extensions_enabled, 'user'); Minz_Translate::reset(FreshRSS_Context::userConf()->language); - [$nbUpdatedFeeds, ] = FreshRSS_feed_Controller::actualizeFeedsAndCommit(null, $self, null, $simplePie); + [$nbUpdatedFeeds, ] = FreshRSS_feed_Controller::actualizeFeedsAndCommit(feed_url: $canonical, simplePiePush: $simplePie, selfUrl: $self); if ($nbUpdatedFeeds > 0) { $nb++; } else { - Minz_Log::warning('Warning: User ' . $username . ' does not subscribe anymore to ' . $self, PSHB_LOG); + Minz_Log::warning('Warning: User ' . $username . ' does not subscribe anymore to ' . $canonical, PSHB_LOG); unlink($userFilename); } } catch (Exception $e) { - Minz_Log::error('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $self, PSHB_LOG); + Minz_Log::error('Error: ' . $e->getMessage() . ' for user ' . $username . ' and feed ' . $canonical, PSHB_LOG); } } @@ -151,12 +171,12 @@ unset($simplePie); if ($nb === 0) { header('HTTP/1.1 410 Gone'); - Minz_Log::warning('Warning: Nobody subscribes to this feed anymore after all!: ' . $self, PSHB_LOG); + Minz_Log::warning('Warning: Nobody subscribes to this feed anymore after all!: ' . $canonical, PSHB_LOG); die('Nobody subscribes to this feed anymore after all!'); } elseif (!empty($hubJson['error'])) { $hubJson['error'] = false; file_put_contents('./!hub.json', json_encode($hubJson)); } -Minz_Log::notice('WebSub ' . $self . ' done: ' . $nb, PSHB_LOG); +Minz_Log::notice('WebSub ' . $canonical . ' done: ' . $nb, PSHB_LOG); exit('Done: ' . $nb . "\n"); |
