framework: Signed URL's dont use HTTPS when forced

  • Laravel Version: 5.8.24
  • PHP Version: 7.3.6

Description:

While signing url’s locally everything worked fine since everything was unsecured using “http” but upon putting this project into a production environment and securing it using “https” using Nginx or using the built in “forceScheme(‘https’)” the signatures generated were different. Upon further investigation I data dumped some variables in the UrlGenerator class and the url’s being used to create the hash are unsecured. I detailed below how I fixed this problem by modifying that class.

Proposed Fix

Editing the hasValidSignature function in “vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php” as shown below.

// Checking if the request was secure, if so then replacing "http://" with "https://". if($request->secure()){ $url = str_replace("http://","https://", $url); }

This fixed the problem for me and works both on development unsecured and on production secured.

Steps To Reproduce:

  1. Sign a url using “URL::temporarySignedRoute()”.
  2. Force https through either your AppServiceProvider with “URL::forceScheme(‘https’)” or through Nginx/Apache.
  3. Navigate to the signed url and you will recieve a “403 Invalid Signature” error.
  4. Data dumping the variables in “vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php” on the hasValidSignature function results in showing that it is using unsecured url’s.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

Are you behind a load balancer? Have you configured your trusted proxies correctly?

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

Make sure you have the right headers being passed in your Nginx file such as

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Port $server_port;
    proxy_set_header X-Forwarded-Proto $scheme;