Skip to content

Clicking internal link to uploaded file redirects to home instead of opening it #5012

Closed

Description

@waeris

Current Behavior

Bug Report

Current Behavior

Clicking on a direct in-post link to an uploaded file (e.g. an image link, <a href="https://example.com/assets/files/...jpg" class="UrlLink UrlLink--internal">) redirects the user to the forum's home page (/) instead of navigating to the file.

Opening the same link in a new tab (e.g. via "Open in new tab") works correctly and loads the image as expected — the issue only occurs on a direct in-app left-click.

Steps to Reproduce

  1. Upload an image to a post (via FoF Upload or core upload)
  2. The resulting link in the rendered post has class UrlLink UrlLink--internal
  3. Left-click directly on the image/link within the post
  4. Observe: instead of opening/viewing the image, the app redirects to the forum home page
  5. Right-click → "Open in new tab" on the same link works fine and loads the image directly

Expected Behavior

Clicking the link should either:

  • Load/display the linked file (image), or
  • At minimum, not redirect to an unrelated page (home)

Root Cause (found via investigation)

  • Formatter::isInternalUrl() in vendor/flarum/core/src/Formatter/Formatter.php marks any same-host URL as internal (UrlLink--internal), including links to static uploaded files that have no corresponding Mithril route (e.g. /assets/files/...).
  • The client-side handler in js/src/forum/utils/routeInternalLinks.ts trusts this class without checking whether the path actually corresponds to a registered app route.
  • Since /assets/files/... doesn't match any registered Mithril route, m.route.set() silently falls back to the default route (home), per the same mechanism described in the code's own comment about forums installed in a subdirectory.

Context

Steps to Reproduce

  1. Upload an image to a post (e.g. via FoF Upload or core upload)
  2. The resulting link in the rendered post has class UrlLink UrlLink--internal
  3. Left-click directly on the image/link within the post
  4. Observe that instead of opening/viewing the image, the app redirects to the forum home page
  5. Right-click → "Open in new tab" on the same link works fine and loads the image directly

Expected Behavior

Clicking the link should either load/display the linked file (image), or at minimum not redirect to an unrelated page (home).

Screenshots

No response

Environment

  • Flarum version: x.y.z
  • Website URL: http://example.com
  • Webserver: [e.g. apache, nginx]
  • Hosting environment: [e.g. shared, vps]
  • PHP version: x.y.z
  • Database: [e.g. MySQL 8.4.11, MariaDB 10.11.2, PostgreSQL 16.1, SQLite 3.45]
  • Browser: [e.g. chrome 67, safari 11]

Output of php flarum info

Output of "php flarum info", run this in terminal in your Flarum directory.

Possible Solution

No response

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions