statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.11k stars 538 forks source link

Gilde assets returning 400 after upgrading site on forge #11089

Open sattyframework opened 2 weeks ago

sattyframework commented 2 weeks ago

Bug description

Hey all, any help is appreciated. I had upgraded a site from v4 to v5, I did this by setting up a new site with the upgrade on forge and then switching the domain to the current live site.

All images were working prior to switching. I have ran the following commands to clear caches, regenerate presets and meta etc but still no luck.

php please glide:clear
php please cache:clear
php please stache:refresh
php please assets:generate-presets
php please assets:meta

I have found that changing secure setting in the config to false allows the images to work but obviously this isn't recommended on production.

this is my config otherwise:

<?php

return [
    'image_manipulation' => [
        'route' => 'img',
        'secure' => env('STATAMIC_ASSETS_SECURE_ENABLED', true),
        'driver' => 'gd',
        'cache' => false,
        'presets' => [
            // 'small' => ['w' => 200, 'h' => 200, 'q' => 75, 'fit' => 'crop'],
        ],
    ],
    'auto_crop' => true,
    'thumbnails' => [
        'max_width' => 10000,
        'max_height' => 10000,
    ],
    'google_docs_viewer' => false,
    'cache_meta' => env('STATAMIC_ASSETS_CACHE_ENABLED', true),
    'focal_point_editor' => true,
];

I have found a similar post https://github.com/statamic/cms/issues/10053 which suggest amending nginx config, however I do not have any configuration regarding images.

The only other consideration is I am using spatie responsive image, however images were working prior to changing domains so am sure this isnt the issue.

The images return 400 in the network tab

Screenshot 2024-11-07 at 17 12 31

How to reproduce

Upgrade existing site on forge to V5

Logs

Nothing in logs aside for 400 error in the network tab.

Environment

Environment
Application Name: RST Moto
Laravel Version: 10.48.22
PHP Version: 8.2.18
Composer Version: 2.8.2
Environment: production
Debug Mode: OFF
URL: www.rst-moto.com
Maintenance Mode: OFF

Cache
Config: CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: database
Session: file

Simple Commerce
Currencies: GBP, USD, EUR
Gateways
Repository: Customer: DuncanMcClean\SimpleCommerce\Customers\EloquentCustomerRepository
Repository: Order: App\Repositories\RstEloquentOrderRepository
Repository: Product: DuncanMcClean\SimpleCommerce\Products\EntryProductRepository
Shipping Methods: Standard
Tax Engine: DuncanMcClean\SimpleCommerce\Tax\BasicTaxEngine

Statamic
Addons: 16
Sites: 3 (United Kingdom, United States Of America, France)
Stache Watcher: Disabled
Static Caching: full
Version: 5.36.0 PRO

Statamic Addons
duncanmcclean/simple-commerce: 7.5.4
jacksleight/statamic-bard-texstyle: 3.3.0
rias/statamic-data-import: 1.5.0
rias/statamic-link-it: 2.4.0
rias/statamic-redirect: 3.8.1
spatie/statamic-responsive-images: 5.0.1
statamic-rad-pack/runway: 7.10.1
statamic/eloquent-driver: 4.15.0
statamic/seo-pro: 6.1.2
weareframework/api-product-importer: dev-bugfix/asset-upload-issue
weareframework/clever-search: dev-bugfix/asset-upload-issue
weareframework/fwk-helper-tools: dev-bugfix/asset-upload-issue
weareframework/fwk-responsive: dev-bugfix/asset-upload-issue
weareframework/product-color-swatches: dev-bugfix/update-array_pull-to-be-Arr--pull
weareframework/vertex-service: dev-bugfix/asset-upload-issue
weareframework/wps-service: dev-bugfix/asset-upload-issue

Statamic Eloquent Driver
Asset Containers: eloquent
Assets: eloquent
Blueprints: eloquent
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: file
Navigation Trees: eloquent
Navigations: eloquent
Revisions: eloquent
Sites: file
Taxonomies: eloquent
Terms: eloquent
Tokens: file

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

duncanmcclean commented 2 weeks ago

I have found a similar post https://github.com/statamic/cms/issues/10053 which suggest amending nginx config, however I do not have any configuration regarding images.

This looks like a web server error page, rather than a Laravel/Statamic one.

What does your Nginx config look like?

sattyframework commented 2 weeks ago

Thanks for the quick reply! Currently the images are only working when I set secure to false in the asset config. I cant see the token being passed in the images url that are showing as 400.

This is my nginx:

...

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_tokens off;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
dhoffmann1979 commented 1 week ago

i also have this problem, the 400 is gone when setting secure to false in assets.php. Some deeper debugging makes me think that the problem is the generated Url from GlideUrlBuilder, when line 59 "$path .= Str::ensureLeft(URL::encode($filename), '/');" is removed, everythings works fine.