1. Go to this page and download the library: Download securized/laravel-ssrf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Illuminate\Support\Facades\Http;
// Wrap any Http:: call with ->ssrf() to enable protection
Http::ssrf()->get($userSuppliedUrl);
Http::ssrf()->post($webhookUrl, $payload);
use Illuminate\Support\Facades\Http;
// Protect a single request
$response = Http::ssrf()->get($userUrl);
// Chain with other options
$response = Http::ssrf()
->withHeaders(['Accept' => 'application/json'])
->timeout(10)
->get($userUrl);
// Both macros are identical
Http::withSsrfProtection()->post($webhookUrl, $data);
'auto_protect' => true,
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Securized\Ssrf\Http\Middleware\SsrfProtectionMiddleware;
$stack = HandlerStack::create();
$stack->push(SsrfProtectionMiddleware::make());
$client = new Client(['handler' => $stack]);
$response = $client->get($userUrl);
use Securized\Ssrf\Rules\SsrfSafeUrl;
$request->validate([
'webhook_url' => ['
use Securized\Ssrf\Facades\Ssrf;
// Returns array{url: string, host: string, ips: list<string>, pinned: bool}
// Throws SsrfException on failure.
$result = Ssrf::validate($url);
// Returns the validated URL string.
// When pin_dns is enabled, the host is replaced with the resolved IP.
// Always use this value for the actual request, not the original $url.
// Throws SsrfException on failure.
$safeUrl = Ssrf::safeUrl($url);
// Returns true/false, never throws.
if (!Ssrf::isSafe($url)) {
abort(422, 'URL is not permitted.');
}
return [
// Apply SSRF protection to all Http:: requests globally.
'auto_protect' => env('SSRF_AUTO_PROTECT', false),
// Allow credentials (user:pass@host) in URLs. Disabled by default.
'send_credentials' => false,
// Replace hostname with resolved IP before sending the request.
// Prevents DNS rebinding attacks. See "DNS Pinning" below.
'pin_dns' => false,
'whitelist' => [
'ips' => [], // CIDR ranges or exact IPs
'ports' => [80, 443, 8080], // Allowed ports (empty = allow all)
'domains' => [], // Regex patterns (empty = allow all)
'schemes' => ['http', 'https'],
],
'blacklist' => [
'ips' => [
// RFC 1918 private ranges
'10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16',
// Loopback
'127.0.0.0/8',
// Link-local (cloud metadata: AWS, GCP, Azure)
'169.254.0.0/16',
// ... and more (see config/ssrf.php for the full list)
],
'ports' => [],
'domains' => [],
'schemes' => [],
],
];
'whitelist' => [
'domains' => [
'api.example.com', // exact host
'*.trusted.com', // any subdomain (not the bare apex)
],
],
'blacklist' => [
'ips' => [
'10.0.0.0/8', // IPv4 range
'fc00::/7', // IPv6 unique local
],
],
use Securized\Ssrf\SsrfOptions;
// Build from config and customise
$options = SsrfOptions::fromConfig(config('ssrf'))
->withPinDns()
->withWhitelistSchemes(['https']) // HTTPS only for this request
->addBlacklistIp('203.0.113.0/24');
Http::ssrf($options)->get($url);
// Also works with the validation rule
new SsrfSafeUrl($options)
// In config/ssrf.php
'pin_dns' => true,
// Or per-request
Http::ssrf(SsrfOptions::fromConfig(config('ssrf'))->withPinDns())->get($url);
use Securized\Ssrf\Exceptions\InvalidIpException;
use Securized\Ssrf\Exceptions\SsrfException;
use Securized\Ssrf\Facades\Ssrf;
try {
$safeUrl = Ssrf::safeUrl($userUrl);
} catch (InvalidIpException $e) {
// Resolved to a private IP
} catch (SsrfException $e) {
// Any other validation failure
}