fix(templates): respect reverse-proxy path prefix in hardcoded JS/URLs - #16
fix(templates): respect reverse-proxy path prefix in hardcoded JS/URLs#16jeromelefeuvre wants to merge 1 commit into
Conversation
290d73c to
6a1fd41
Compare
|
Salut! ton projet avance plus vite que l'original, je t'envois quelques PRs ;) |
|
Thanks for this — I read the whole diff, and the change itself is clean: 421 added lines, 420 of which are purely the I'm going to hold this on the fork rather than merge it, for reasons that aren't about the patch quality:
One substantive note for whichever repo takes it: this introduces a second prefix convention. There's already a named-route pattern in the tree — var BASE = '{{ path("app_qbittorrent_index") }}'; {# templates/qbittorrent/index.html.twig:849 #}
var BASE = '{{ path("app_deluge_index") }}'; {# templates/deluge/index.html.twig:793 #}— and you used exactly that approach for the one Happy to revisit here if Shoshuo#80 stalls upstream. |
6a1fd41 to
db46fcc
Compare
db46fcc to
d71b393
Compare
Inline JS and href/action attributes across /medias, /decouverte,
/jellyseerr, /prowlarr and /setup templates hardcoded absolute paths
(fetch('/medias/...'), href="/jellyseerr/...", etc.), which ignore the
X-Forwarded-Prefix header set by a reverse proxy stripping a path
prefix (e.g. Traefik serving the app under /prismarr/). Symfony's
Request::getBasePath() already reflects that header, so prefix each
hardcoded literal with app.request.getBasePath() (or, inside an
already-open Twig expression, with the ~ concat operator) instead of
relying on instance_path()/path() helpers that aren't used everywhere.
Each affected template now computes the prefix once into a local
`var BASE` (matching the existing convention in qbittorrent/index and
deluge/index) instead of repeating the Twig call inline at every call
site, shrinking the diff and keeping a single point of change per
template.
The initial sweep missed the app-wide quick-look modal (_quicklook.html.twig,
shared by the dashboard, calendar, Explorer and top-bar search), the
top-bar search's own quicklook URLs in base.html.twig, the Plex info
modal (dashboard/_plex_info_modal.html.twig) and the entire Tautulli
dashboard page (tautulli/index.html.twig) — none of those were under
/medias, /decouverte, /jellyseerr, /prowlarr or /setup, so they kept
hardcoded absolute paths that broke behind a stripped path prefix.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
d71b393 to
ce1adc8
Compare
Summary
When Prismarr is served behind a reverse proxy that strips a path prefix (e.g. Traefik routing
https://host/prismarr/...to the container root, withX-Forwarded-Prefix: /prismarrforwarded), server-generated URLs are already prefix-safe viainstance_path()/path()(which go through the Symfony router, itself driven byRequest::getBasePath()— already trusted viatrusted_headers: [..., x-forwarded-prefix]inconfig/packages/framework.yaml).However, ~276 places across 67 Twig templates build absolute paths as raw string literals inside inline
<script>blocks orhref/action attributes (fetch('/medias/' + slug + ...),href="/jellyseerr/...", etc.). These literals ignore the prefix entirely, sinceX-Forwarded-Prefixonly affects server-side URL generation, not raw JS strings.Fix
<script>block or HTML attribute): prefix the literal with{{ app.request.getBasePath() }}.{% include ... with { save_url_edit: ... } %}or a ternary): use the Twig concat operatorapp.request.getBasePath() ~ '...'instead, since{{ }}doesn't interpolate inside an already-parsed Twig expression./api/health/services) was switched to the named route via{{ path('api_health_services') }}instead, which is cleaner and needed no raw-path handling.Request::getBasePath()already reflectsX-Forwarded-Prefix(Symfony 5.3+), so this resolves to/prismarrbehind the proxy and''on a root deployment — no extra config needed.Affected roots:
/medias,/decouverte,/jellyseerr,/prowlarr,/setup.Test plan
make lint-twig(php bin/console lint:twig templates) — all 149 Twig files pass syntax validation~instead of{{ }}