Explorar o código

Call check_url_before_add hook when previewing a feed (#9343)

The GET branch of feedController::addAction() built a FreshRSS_Feed
straight from the requested URL and loaded it, without invoking the
Minz_HookType::CheckUrlBeforeAdd hook. Only the POST branch, through
addFeed(), ran the hook.

Extensions that turn a website URL into a feed URL (e.g. RSS-Bridge)
were therefore bypassed on the confirmation page reached from the
bookmarklet: the raw website URL was probed, and since such sites do
not advertise a feed, the preview reported that no feed could be
added. Submitting the very same form then succeeded, because the POST
path did apply the hook.

Run the hook at the start of the GET branch so the preview probes the
URL that would actually be subscribed to, and reuse the existing
"not added" feedback when an extension refuses the URL, matching what
addFeed() does when the hook returns null.

The documented contract is that the hook "will be executed every time
a URL is added", so the preview should not be an exception.

Fixes #9339
Ethan Stoner hai 1 día
pai
achega
5fb62464e9
Modificáronse 1 ficheiros con 9 adicións e 0 borrados
  1. 9 0
      app/Controllers/feedController.php

+ 9 - 0
app/Controllers/feedController.php

@@ -354,6 +354,15 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 			// GET request: we must ask confirmation to user before adding feed.
 			FreshRSS_View::prependTitle(_t('sub.feed.title_add') . ' · ');
 
+			// Same hook as in addFeed(), so that the preview probes the URL that would actually be subscribed to.
+			/** @var string|null $urlHooked */
+			$urlHooked = Minz_ExtensionManager::callHook(Minz_HookType::CheckUrlBeforeAdd, $url);
+			if ($urlHooked === null) {
+				Minz_Request::bad(_t('feedback.sub.feed.not_added', $url), $url_redirect);
+				return;
+			}
+			$url = $urlHooked;
+
 			$catDAO = FreshRSS_Factory::createCategoryDao();
 			$this->view->categories = $catDAO->listCategories(prePopulateFeeds: false);
 			$this->view->feed = new FreshRSS_Feed($url);