Search by

roundly-consulting / safe-fetch-for-laravel

mihaliak

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.

Package info

github.com/roundly-consulting/safe-fetch-for-laravel

Homepage

Documentation

pkg:composer/roundly-consulting/safe-fetch-for-laravel

Fund package maintenance!

Patreon

Statistics

Installs: 102

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

1.0.2 2026-11-08 19:54 UTC

This package is auto-updated.

Last update: 2026-11-08 19:55:48 UTC


README

Safe Fetch for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

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.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

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