spatie/laravel-url-signer
Sign and validate any URL in Laravel with an expiring signature. Works across apps, uses a configurable secret (not the app key), and includes middleware to protect routes. Generate time-limited links in one call and verify them anywhere.
spatie/signed-url (~100 LOC), with no heavy dependencies. Low risk of conflicts..env or config files, reducing hardcoded credentials.APP_KEY). Misconfiguration could lead to signature forgery if secrets are exposed.?expires=&signature= parameters, which may exceed HTTP/HTTPS URL length limits (e.g., ~2000 chars) for long-lived URLs or large signatures. Mitigation: Use shorter expiration windows or URL shorteners.leeway buffer in validation.UrlSigner as a singleton.UrlSigner::sign()/validate() for clean syntax.secret, expires format, and algorithm (default: HMAC-SHA256).spatie/signed-url can be used standalone in PHP 8.0+ (no Laravel required). Useful for:
sign()/validate() behavior in staging with mock time (e.g., Carbon::setTestNow()).APP_KEY to dedicated signing secrets per environment.spatie/laravel-encrypter for encrypted env vars).http, https, and relative paths (e.g., /protected). Avoids issues with:
?key=value pairs (appends &expires=...).#hash to prevent signature pollution.https://例.com/路径).&, =, ? in signatures.composer require spatie/laravel-url-signer.php artisan vendor:publish --provider="Spatie\UrlSigner\UrlSignerServiceProvider"..env:
URL_SIGNER_SECRET=your_secure_random_string_here
URL_SIGNER_EXPIRES_FORMAT=Y-m-d\TH:i:s\Z
$signedUrl = UrlSigner::sign('https://example.com/download', now()->addMinutes(5));
$this->assertTrue(UrlSigner::validate($signedUrl));
UrlSigner::validate() returns false).route()->signed()) with this package..env + restart workers). Consider automating via:
spatie/signed-url for breaking changes (e.g., algorithm updates).expires/signature pairs to identify:
expires timestamp mismatch.dd(UrlSigner::getSignatureParts($url)) to inspect components.&).expires window.URL_SIGNER_SECRET.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Secret leakage | Forged URLs | Rotate secrets immediately; use short TTLs. |
| Clock desync | False URL expirations | Sync servers via NTP; add leeway in validation. |
| URL truncation | Broken signatures | Use shorter expirations or URL shorteners. |
| Algorithm downgrade | Vul |
How can I help you explore Laravel packages today?