flarum / flarum/framework

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

Open
#5,012 0 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
PHP
Stars
6.7k
Forks
883
Avg merge
15h 16m
Merged PRs (30d)
73

Description

### Current Behavior

## Bug Report

### Current Behavior

Clicking on a direct in-post link to an uploaded file (e.g. an image link, ``) 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_

Contributor guide

Open the contributing guide

Research direction

Read vendor/flarum/core/src/Formatter/Formatter.php and js/src/forum/utils/routeInternalLinks.ts first, then reproduce the direct left-click behavior for an uploaded-file link. Done means uploaded-file links open without redirecting to the home page while registered internal routes continue to navigate in-app.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, typescript
Domain
backend, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.