EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

mixed block HTTPS->HTTP - all ajax calls are via http instead of https

Open milos-ilic opened this issue 6 years ago • 20 comments

Describe the bug When I try to edit some content using ajax request in administration (for example switch, or delete some entity) I have been blocked via browser.

To Reproduce EasyAdmin 3 version used.

(OPTIONAL) Additional context Screenshot from 2020-07-13 15-34-12

milos-ilic avatar Jul 13 '20 13:07 milos-ilic

I have the same issue using docker because for some reason, symfony thinks my app only serves http (even though I am sure that Nginx is configured properly).

The thing is that EasyAdmin generate absolute urls (with host and scheme) and not relative urls: https://github.com/EasyCorp/EasyAdminBundle/blob/7722c8d9f55a611e2fcb13b16a2b74537a7279c8/src/Router/CrudUrlBuilder.php#L180

I have patched this file to remove UrlGeneratorInterface::ABSOLUTE_URL so that relative urls are generated and I no longer have the issue.

xaviermarchegay avatar Jul 13 '20 17:07 xaviermarchegay

Hi @xaviermarchegay thanks for sharing your solution. It helped me, too.

I am using docker as well, and I think it is well configured.

milos-ilic avatar Jul 13 '20 19:07 milos-ilic

I don't use Docker, so I can't debug this ... but I'm convinced this has to be some Docker + Symfony issue (or Docker + Nginx, etc.)

I use Symfony local serve to work on my apps, so I can't use HTTP ... everything is HTTPS and I can't see that error. All URLs use HTTPS.

A few days ago, Symfony merged this change related to the profiler: https://github.com/symfony/symfony/pull/31349/files It now generates absolute URLs. Can you please check if this breaks those links to you too? Thanks!

javiereguiluz avatar Jul 16 '20 18:07 javiereguiluz

@javiereguiluz Yes, it was actually a simple Symfony configuration issue that I solved a few minutes ago.

@milos-ilic You have to uncomment TRUSTED_PROXIES and TRUSTED_HOSTS in your .env file. Then I added my domain in the host variable and it works perfectly.

xaviermarchegay avatar Jul 16 '20 19:07 xaviermarchegay

@xaviermarchegay Thanks it solved the problem for me !

t4cfantasy42 avatar Nov 10 '20 10:11 t4cfantasy42

@javiereguiluz I think you could close this issue because it seems to be a symfony configuration issue.

xaviermarchegay avatar Nov 10 '20 10:11 xaviermarchegay

@javiereguiluz This issue can be reproduced in a scenario: https request -> load balancer:443 -> apache/nginx:80

In above scenario configs for apache/nginx are not aware that they are serving https content. This is very common in aws deployments.

cvele avatar Nov 28 '20 20:11 cvele

@cvele thanks for the insights ... but we're going to close this issue as recommended by @xaviermarchegay because this looks outside of the scope of this bundle. We use Symfony's asset() to link to all images, CSS and JS files, so I think we're doing all we can do. The rest is Symfony's and others (nginx, AWS, reverse proxies, etc.) responsibility.

javiereguiluz avatar Nov 29 '20 11:11 javiereguiluz

@javiereguiluz This issue can be reproduced in a scenario: https request -> load balancer:443 -> apache/nginx:80

In above scenario configs for apache/nginx are not aware that they are serving https content. This is very common in aws deployments.

I have the same issue in aws with load balancer as @cvele said above. Somehow easy admin is generating the links with http not https in the dashboard.

iulianbeleiu avatar Dec 19 '20 20:12 iulianbeleiu

@iulianbeleiu please try to debug the cause of this issue because I don't use that infrastructure. Please, also make sure that the error only happens in EasyAdmin and not in other parts of the Symfony application. Thanks!

javiereguiluz avatar Dec 20 '20 11:12 javiereguiluz

@javiereguiluz might be because of end-to-end encryption is not setup. so the load balancer talks with the server instance on port 80, you think this might be the case? The load balancer listens on port 443 tho and also redirects traffic from 80 to 443. When I try to delete a record for example, it redirects to https but then i get redirected to /admin, and the record is not deleted. The Symfony project routes are working fine.

iulianbeleiu avatar Jan 09 '21 13:01 iulianbeleiu

Yes, problem solved. Everything is explained here: https://symfony.com/doc/current/deployment/proxies.html We have to configure Symfony to Work behind a Load Balancer or a Reverse Proxy

iulianbeleiu avatar Feb 25 '21 20:02 iulianbeleiu

Hello,

I have a similar issue with this, unfortunately in my case, the problem only happened on CRUD with AssociationField::new('field')->autocomplete() enabled.

Before using autocomplete, the AssociationField is working. With autocomplete enabled, I cannot fetch the resource because it's blocked (turn out the autocomplete send http request instead of https). Everything else works normally.

My environment: I ran the test app with PHP Built in server (ex: php -S localhost:8088 -t public/), and then use nginx in front of that with valid SSL on port 443 (configured as reverse proxy).

Is there something we need to improve with the AssociationField autocomplete method?

dadangnh avatar Nov 04 '21 07:11 dadangnh

Hello,

It's possible for someone to give a full example please.

My case : https request ->nginx:443 (and 80) -> apache:80 (symfony project)

Thanks

asijoumi avatar Nov 23 '21 05:11 asijoumi

Hi, I go a similar problem with a reverse proxy pass with path prefix (proxy settings are fine, all x-forwarded headers are correctly used by Symfony 5.2) MenuItem::linkToCrud works fine but MenuItem::linkToRoute is not handle correctly : "No routes found for /<PREFIX/ my/path/

It turns out that AdminRouterSubscriber::getSymfonyControllerFqcn try to match the external path (with prefix) with the internal one (as declared in Symfony).

I fix the problem by overriding it and using relative URL $url = $this->urlGenerator->generate($routeName, $routeParams, UrlGeneratorInterface::RELATIVE_PATH);, but I hope there's a better solution.

Should I open a new issue ?

To reproduce :

  • place your symfony application behind a reverse proxy (apache or traefik with PathPrefix)
  • configure it so <external_url>/<prefix> points to <internal_symfony_url>/
  • modify accordingly the conf (https://symfony.com/doc/current/deployment/proxies.html)
  • add a MenuItem::linkToRoute item => get the "No routes found" error

obriat avatar Dec 21 '21 14:12 obriat

I know this is old and closed, but the solution is to set HTTPS=on env var in production deployments.

cvele avatar Jan 16 '22 20:01 cvele

I know this is old and closed, but the solution is to set HTTPS=on env var in production deployments.

I was having this issue with a Docker / Nginx / Php-FPM setup and setting this environment variable fixed it. Thanks @cvele

I did not found any documentation on Symfony about this variable. Do you have some info about it?

grimabe avatar Feb 01 '22 16:02 grimabe

@grimabe Sorry, not a lot. I found it while facing the similar issue a while back by stepping.

cvele avatar Apr 14 '22 18:04 cvele

Again, forcing HTTPS is no the best solution, you should better setup the correct reverse proxy settings, otherwise your application never get the correct remote IP, protocol, prefix or correct hostname

obriat avatar Apr 14 '22 19:04 obriat

HTTPS=on fixed the issue but you may also consider the ->generateRelativeUrls() option:

  • https://github.com/EasyCorp/EasyAdminBundle/issues/5750#issuecomment-1541583581

alexisLefebvre avatar Aug 05 '24 17:08 alexisLefebvre