Skip to content

Mixed Content errors when using Trusted Proxy middleware and the default basset disk #166

@scottbradybuckii

Description

@scottbradybuckii

When trying to install Backpack 7 on a Laravel 12 installation, every CSS and JS asset that was getting served was blocked by the browser with a "Mixed Content" error message. This is because our site is behind a reverse proxy, but the weird part was that we had already setup the $middleware->trustProxies(at: '*'); line in our bootstrap/app.php file, which should have correctly allowed the url() helper function to generate "https" urls.

After a bit of digging around, I discovered that if the filesystems.disks.basset config isn't defined, the BassetServiceProvider.php file generates a config with the following code:

config(['filesystems.disks.basset' => [
    'driver' => 'local',
    'root' => storage_path('app/public'),
    'url' => url('').'/storage',
    'visibility' => 'public',
    'throw' => false,
]]);

The only issue is that the url() function in this code does not know anything about the trusted proxies set in the middleware above, because it is running too soon (inside a Service Provider). It looks like this issue was introduced in this commit: 310d331#diff-23625bed93cfb2bca4092ecb9897ba66ca129414e56f87e027214d1f579daa10

My fix for now was just adding the below config into my filesystems.php config file, but it would probably be best to switch back to env('APP_URL') instead of url(''), since middleware is not taken into account in ServiceProviders:

'basset' => [
    'driver' => 'local',
    'root' => storage_path('app/public'),
    'url' => env('APP_URL').'/storage',
    'visibility' => 'public',
    'throw' => false,
],

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions