Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel serving assets insecurely with AWS

With my new project, when I deploy my app to my https:// domain, every {{ asset() }} and every {{ route() }} is being served over http (which causes "mixed content" security issues in browsers).

I'm using AWS with a load-balanced Elastic Beanstalk application.

I've tried ensuring APP_URL is correctly set to https, and I understand I can use secure_asset or forceScheme, however I didn't have to do this with my previous project and I want to understand why.

How can I see where Laravel is making a decision about protocol? I want to get to the root of the problem rather than plaster over it.

like image 310
Chuck Le Butt Avatar asked Jul 05 '18 09:07

Chuck Le Butt


1 Answers

This is an easy gotcha. If you're using AWS you need to change your config. It's very simple and, as usual, Laravel's documentation has the solution. You can read more here:

https://laravel.com/docs/5.6/requests#configuring-trusted-proxies

enter image description here

All I had to do (as an AWS Elastic Beanstalk user) was edit app/Http/Middleware/TrustProxies.php:

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array
     */
    protected $proxies = '*';

    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_AWS_ELB;
}

Now everything is fine. Easy to miss when setting up a new project.

like image 84
Chuck Le Butt Avatar answered Oct 03 '22 13:10

Chuck Le Butt