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:
- Sign a url using “URL::temporarySignedRoute()”.
- Force https through either your AppServiceProvider with “URL::forceScheme(‘https’)” or through Nginx/Apache.
- Navigate to the signed url and you will recieve a “403 Invalid Signature” error.
- 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)
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