Signed Glide URLs return 400 when the site URL is on a different domain from the app

Aperta
#15,506 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #15515 di @lazerg — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
laravel, php
Ambito
backend

Direzione di ricerca

Start with GlideController::validateSignature(), where the issue identifies the URL-path calculation. Check how its existing tests cover signature validation, then add regression coverage for a site URL on a different domain and for a site URL with a path prefix. Done means both cases validate signed Glide URLs correctly; an open linked pull request indicates work is already underway.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

assets multisite
Bug description

With image_manipulation.secure enabled, every Glide request returns 400 Signature is not valid. if the site's url in sites.yaml is on a different domain from the one serving Statamic.

We hit this running Statamic headless. The site URLs point at our frontend (https://www.example.com) so entry URLs come out right, while Statamic and its /img route are on https://cms.example.com.

GlideController::validateSignature() works out the path to check like this:

$path = Str::after($this->request->url(), Site::current()->absoluteUrl());

For a request to https://cms.example.com/img/..., the site URL is https://www.example.com. That isn't part of the request URL, so Str::after() returns the whole URL. The signature was generated over /img/..., so it never matches.

One possible fix is to fall back to the request path when the site URL isn't a prefix of the request URL:

$url = $this->request->url();
$siteUrl = Site::current()->absoluteUrl();

$path = Str::startsWith($url, $siteUrl)
    ? Str::after($url, $siteUrl)
    : $this->request->getPathInfo();

Sites with a path prefix (/de/img/...) still take the first branch, so their URLs keep working. Using getPathInfo() on its own would break them.

How to reproduce
  1. Set a site's url in resources/sites.yaml to a different domain from the app, for example https://www.example.com while the app runs on http://localhost.
  2. Leave statamic.assets.image_manipulation.secure at its default of true.
  3. Generate a URL with Image::manipulate('image.jpg', ['w' => 300]). It comes back relative, as /img/image.jpg?w=300&s=....
  4. Request it from the app: http://localhost/img/image.jpg?w=300&s=.... The response is 400 Signature is not valid.

If you change the site URL to http://localhost, the same URL passes the signature check.

Logs

N/A

Environment

Statamic 6.33.0, league/glide 4.1.0, PHP 8.5.0, Laravel 13.32.0. The same line is still in GlideController in 6.34.0.

Installation

Existing Laravel app

Additional details

My colleague Andrius Gluzeckis found this.

Lingua principale
PHP
Stelle
4.9k
Fork
647
Merge medio
1g 45m
PR unite (30g)
221

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di statamic/cms

Tutte le issue di statamic/cms

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.