Looking to hire Laravel developers? Try LaraJobs

safe-fetch-for-laravel maintained by roundly-consulting

Description
SSRF protection for Laravel's HTTP client: strict URL canonicalising, private and cloud-metadata address blocking, DNS pinning, re-vetted redirects and a validation rule.
Last update
2026/11/09 23:00 (dev-main)
License
Downloads
111

Comments
comments powered by Disqus

Safe Fetch for Laravel

Make server-side requests to URLs you do not control — webhook targets, link previews, avatar, feed and import URLs — without reaching your own network. Every URL is parsed strictly, every address it resolves to must be public, and the connection is pinned to exactly those addresses, redirects included.

Installation

Requires PHP 8.4 and Laravel 13; ext-curl to send requests (ext-intl for international host names).

composer require roundly-consulting/safe-fetch-for-laravel

Usage

Validate a URL a user hands in, then fetch it — capped, with errors that say whether a retry can help:

use Illuminate\Support\Facades\Http;
use RoundlyConsulting\SafeFetch\Exceptions\SafeFetchException;
use RoundlyConsulting\SafeFetch\Facades\SafeFetch;
use RoundlyConsulting\SafeFetch\Rules\SafeUrl;

$request->validate(['feed' => ['required', 'string', 'max:2048', new SafeUrl]]);

try {
    $feed = SafeFetch::fetch($request->input('feed'), maxBytes: 2_000_000);
    // $feed->body, $feed->contentType, $feed->url
} catch (SafeFetchException $e) {
    $e->retryable(); // a 5xx or a timeout can heal; a blocked address never does
}

Or guard any Laravel HTTP call:

Http::safe()->withToken($token)->post($hookUrl, $payload);

Documentation

The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/safe-fetch-for-laravel

Release notes are in CHANGELOG.md. To contribute, see the contributing guide.

Support our work

This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.

License

The MIT License (MIT). See LICENSE.md.