Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.9.1] Action::linkToRoute does not handle reverse proxy context #6244

Open
kira0269 opened this issue Apr 5, 2024 · 1 comment
Open

[4.9.1] Action::linkToRoute does not handle reverse proxy context #6244

kira0269 opened this issue Apr 5, 2024 · 1 comment

Comments

@kira0269
Copy link

kira0269 commented Apr 5, 2024

Describe the bug
The request handling of a custom action created with the linkToRoute method does not work as expected if the app is behind a reverse proxy.

Context

  • My app is behind reverse proxy. So when accessing https://rp-domain.com/my-app, the reverse proxy redirects all requests to https://app-domain.com/
  • Symfony handles well the reverse proxy settings: it will detect the URI prefix (/my-app) and will not consider it during routing process.

To Reproduce

  • In standard CRUD Controller, create custom action and use linkToRoute() to specify the target based on an existing route.
  • Go on your app and click on the link.
  • Here, src/EventListener/AdminRouterSubscriber.php will detect the route name from the query string and will generate the url. If behind a reverse proxy, the url will contain the uri prefix /my-app.
  • As you can see in the screenshot below, the REQUEST_URI will be set with this url, but it should not include the uri prefix

(OPTIONAL) Additional context
image

Possible solutions
1.
Instead of generate the url to detect the controller to call, we could rely on routes configuration:

$routes = $this->get('router')->getRouteCollection();
$controller = $routes->get($routename)->getDefaults()['_controller'];

Why don't we just forward the request to the route name ?
Like AbstractController::forward() method ?

Instead of creating the link like /admin?routeName=app_my_route, generate the right url: /my-route

@kira0269
Copy link
Author

kira0269 commented Apr 5, 2024

Workaround:

Instead of using linkToRoute('app_my_route'), I use linkToUrl($this->generateUrl('app_my_route'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant