Skip to content

Call check_url_before_add hook when previewing a feed - #9343

Merged
Alkarex merged 1 commit into
FreshRSS:edgefrom
ethanstoner:fix/9339-check-url-before-add-get-preview
Sep 26, 2026
Merged

Alkarex merged 1 commit into
FreshRSS:edgefrom
ethanstoner:fix/9339-check-url-before-add-get-preview

Conversation

@ethanstoner

Copy link
Copy Markdown
Contributor

Closes #9339

Changes proposed in this pull request:

  • Invoke the Minz_HookType::CheckUrlBeforeAdd (check_url_before_add) hook at the start of the GET branch of feedController::addAction(), so the confirmation/preview page probes the URL that would actually be subscribed to instead of the raw requested URL.
  • Reuse the existing feedback.sub.feed.not_added feedback when an extension refuses the URL (hook returns null), matching what addFeed() does. No new translation key needed.
  • No change to the POST path, so subscribing itself behaves exactly as before.

Why: only the POST branch ran the hook, via addFeed(). The GET branch built new FreshRSS_Feed($url) and loaded it directly. Extensions that rewrite a website URL into a feed URL (RSS-Bridge and similar) were therefore bypassed on the page reached from the bookmarklet, so the preview probed a site that advertises no feed and reported that the feed could not be added — while submitting the very same form succeeded. docs/en/developers/03_Backend/05_Extensions.md documents the hook as one that "will be executed every time a URL is added", so the preview should not be an exception.

How to test the feature manually:

  1. Install FreshRSS locally and add a small extension registering the hook, RSS-Bridge style:

    final class HookProbeExtension extends Minz_Extension {
    	#[\Override]
    	public function init(): void {
    		parent::init();
    		$this->registerHook(Minz_HookType::CheckUrlBeforeAdd, [self::class, 'checkUrl'], -10);
    	}
    
    	public static function checkUrl(string $url): ?string {
    		return $url === 'http://example.invalid/website.html' ? 'http://example.invalid/feed.xml' : $url;
    	}
    }
  2. Serve a website.html that advertises no feed, and a valid feed.xml, then enable the extension.

  3. Visit the bookmarklet/preview URL by GET: ?c=feed&a=add&url_rss=http%3A%2F%2Fexample.invalid%2Fwebsite.html.

  4. Before this change the hook never fires, the page shows the "newsfeed could not be added" alert, and the form still holds website.html. After this change the hook fires, the form holds the rewritten feed.xml, and the preview shows the rewritten feed's title and description.

  5. Also check the refusal path: make the hook return null for some URL, request it by GET, and confirm you land back on the subscription page with the existing "could not be added" feedback rather than a broken preview.

Verified locally on PHP 8.5.10 with SQLite, comparing the same request with and without the patch (hook fired: no → yes; alert shown: yes → no; previewed URL: website.html → feed.xml).

Checks run locally, matching .github/workflows/tests.yml:

Check Result
composer run-script php-lint pass
composer run-script phtml-lint pass
composer run-script translations + git diff --exit-code pass, tree clean
composer run-script phpunit 737 tests, 1397 assertions, pass (2 pre-existing session_start() warnings, unchanged from edge)
composer run-script phpcs pass
composer run-script phpstan no errors
npm run eslint / markdownlint / stylelint pass
npm run rtlcss + git diff --exit-code pass, tree clean
typos pass

Notes for reviewers:

  • I deliberately did not extract the hook call into a shared helper. The two call sites need different error handling — addFeed() throws FreshRSS_FeedNotAdded_Exception, the GET branch calls Minz_Request::bad() and returns — so a helper would either add more lines than it saves or push exceptions into local control flow. Per the KISS guidance in .github/instructions/_general.instructions.md I kept the change minimal and left addFeed() untouched. Happy to extract a small private static helper instead if you would rather have one code path.
  • No unit test added. There is no controller test harness in tests/ (no tests/app/Controllers/), and addAction() needs Minz_Request, session, auth, DAOs and network access. Per the checklist's "optional if too hard" I verified by running the application instead, as described above. Glad to add a test if you can point me at the preferred way to drive a controller under PHPUnit.
  • The linked issue is still labeled Bug (unconfirmed). I reproduced it independently as described, but a maintainer may want to confirm the intended behavior before merging.

Pull request checklist:

  • clear commit messages
  • code manually tested
  • unit tests written (optional if too hard) — see note above
  • documentation updated — no change needed; this makes the code match the documented hook contract

Generated with Claude Code on behalf of @ethanstoner.

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 FreshRSS#9339
@Alkarex Alkarex added this to the 1.30.1 milestone Sep 21, 2026
@Alkarex
Alkarex merged commit 5fb6246 into FreshRSS:edge Sep 26, 2026
3 checks passed
doonga pushed a commit to greyrock-labs/home-ops that referenced this pull request Oct 6, 2026
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [freshrss/freshrss](https://freshrss.org/) ([source](https://github.com/FreshRSS/FreshRSS)) | patch | `1.30.0-alpine` → `1.30.1-alpine` |

---

### Release Notes

<details>
<summary>FreshRSS/FreshRSS (freshrss/freshrss)</summary>

### [`v1.30.1`](https://github.com/FreshRSS/FreshRSS/blob/HEAD/CHANGELOG.md#2026-10-05-FreshRSS-1301)

[Compare Source](FreshRSS/FreshRSS@1.30.0...1.30.1)

- Deployment
  - Reword recommendations and explanations for *edge* (rolling release) vs. *latest* (versioned release) channels [#&#8203;9270](FreshRSS/FreshRSS#9270)
- Security
  - Config + increase default values for search max length and depth [#&#8203;9280](FreshRSS/FreshRSS#9280)
  - Accept a trusted proxy address given without a subnet [#&#8203;9301](FreshRSS/FreshRSS#9301)
  - Warn during session regenerate fail [#&#8203;9311](FreshRSS/FreshRSS#9311), [#&#8203;9376](FreshRSS/FreshRSS#9376)
  - CI/CD add zizmor workflow for action security checks [#&#8203;9228](FreshRSS/FreshRSS#9228), [#&#8203;9331](FreshRSS/FreshRSS#9331)
  - Use PHP `#[\SensitiveParameter]` [#&#8203;9322](FreshRSS/FreshRSS#9322)
  - Reject token access (RSS/OPML export, feed refresh) for disabled accounts [#&#8203;9336](FreshRSS/FreshRSS#9336)
  - Require POST+CSRF for self-update mutations [#&#8203;9335](FreshRSS/FreshRSS#9335)
  - Make the login challenge nonce one-time [#&#8203;9334](FreshRSS/FreshRSS#9334)
  - Bound ZIP import against decompression bombs [#&#8203;9332](FreshRSS/FreshRSS#9332)
  - Rotate session ID on all authenticated transitions [#&#8203;9333](FreshRSS/FreshRSS#9333)
  - Minz: Remove vulnerable and unused code path for displaying errors [#&#8203;9395](FreshRSS/FreshRSS#9395)
  - Fix NAT64 feed fetching on IPv6-only hosts [#&#8203;9372](FreshRSS/FreshRSS#9372)
- Bug fixes
  - Fix domain-wide `Retry-After` [#&#8203;9390](FreshRSS/FreshRSS#9390)
  - Fix muting of feeds gone with HTTP 410 [#&#8203;9391](FreshRSS/FreshRSS#9391)
  - Fix infinite redirect loop due to `SCRIPT_NAME` in `PATH_INFO` [#&#8203;9282](FreshRSS/FreshRSS#9282), [#&#8203;9287](FreshRSS/FreshRSS#9287)
  - Restore the automatic reading view after marking articles as read, while preserving explicit filters [#&#8203;9288](FreshRSS/FreshRSS#9288)
  - Fix adaptive reading state after marking articles read [#&#8203;9290](FreshRSS/FreshRSS#9290)
  - Fix regression sharing links [#&#8203;9303](FreshRSS/FreshRSS#9303)
  - Don’t disable anonymous refresh when anonymous feed access is disabled [#&#8203;9354](FreshRSS/FreshRSS#9354)
  - Fix regression with HTTPS proxies due to wrong TLS SNI resolution [#&#8203;9341](FreshRSS/FreshRSS#9341)
  - Better enforce limits for feeds and categories [#&#8203;9357](FreshRSS/FreshRSS#9357)
  - Fix JavaScript error when opening a label menu in sidebar [#&#8203;9377](FreshRSS/FreshRSS#9377)
  - Fix custom favicon with GReader API [#&#8203;9409](FreshRSS/FreshRSS#9409)
- CLI
  - Add optional feed argument to `actualize-user.php` [#&#8203;9319](FreshRSS/FreshRSS#9319)
- UI
  - Various UI and style improvements [#&#8203;9298](FreshRSS/FreshRSS#9298), [#&#8203;9369](FreshRSS/FreshRSS#9369),
    [#&#8203;9388](FreshRSS/FreshRSS#9388)
- Extensions
  - Call `check_url_before_add` hook when previewing a feed [#&#8203;9343](FreshRSS/FreshRSS#9343)
- I18n
  - Add Belarusian [#&#8203;9351](FreshRSS/FreshRSS#9351)
  - Improve German [#&#8203;9370](FreshRSS/FreshRSS#9370), [#&#8203;9385](FreshRSS/FreshRSS#9385)
  - Improve Italian [#&#8203;9370](FreshRSS/FreshRSS#9370)
  - Improve Japanese [#&#8203;9398](FreshRSS/FreshRSS#9398)
  - Improve Turkish [#&#8203;9349](FreshRSS/FreshRSS#9349)
- Misc.
  - Check SVG optimization in the tests CI workflow with SVGO [#&#8203;9361](FreshRSS/FreshRSS#9361)
  - Move PHPUnit flags to a config file and use strictest failure mode [#&#8203;9374](FreshRSS/FreshRSS#9374)
  - Avoid writing to log files during unit tests [#&#8203;9373](FreshRSS/FreshRSS#9373)
  - Bump Ruby gems automatically with Dependabot for docs [#&#8203;9401](FreshRSS/FreshRSS#9401)
  - Update dev dependencies [#&#8203;9323](FreshRSS/FreshRSS#9323), [#&#8203;9324](FreshRSS/FreshRSS#9324),
    [#&#8203;9325](FreshRSS/FreshRSS#9325), [#&#8203;9326](FreshRSS/FreshRSS#9326), [#&#8203;9327](FreshRSS/FreshRSS#9327),
    [#&#8203;9328](FreshRSS/FreshRSS#9328), [#&#8203;9368](FreshRSS/FreshRSS#9368), [#&#8203;9378](FreshRSS/FreshRSS#9378),
    [#&#8203;9379](FreshRSS/FreshRSS#9379), [#&#8203;9380](FreshRSS/FreshRSS#9380), [#&#8203;9381](FreshRSS/FreshRSS#9381),
    [#&#8203;9402](FreshRSS/FreshRSS#9402), [#&#8203;9403](FreshRSS/FreshRSS#9403), [#&#8203;9404](FreshRSS/FreshRSS#9404),
    [#&#8203;9405](FreshRSS/FreshRSS#9405), [#&#8203;9406](FreshRSS/FreshRSS#9406), [#&#8203;9407](FreshRSS/FreshRSS#9407)

</details>

---

### Configuration

📅 **Schedule**: (in timezone America/New_York)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjEzMy4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9jb250YWluZXIiLCJ0eXBlL3BhdGNoIl19-->

Reviewed-on: https://git.greyrock.io/todd/home-ops/pulls/358
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Bookmarklet GET preview bypasses check_url_before_add hook

2 participants