This package allows for validation of incoming requests against the official Amazon Web Services (AWS) IP Address Range. Use this to determine if an incoming request actually comes from the AWS infrastructure e.g. for Simple Notification Service (SNS) payloads.
- Passes incoming HTTP requests from AWS, rejects everything else with a
403. - AWS IP address range is fetched on demand and therefore always up-to-date.
- Caches the parsed IP address range (default: 24 hours).
- Source URL, cache key, and TTL are configurable.
Actively tested in CI:
| PHP | Laravel |
|---|---|
8.1 |
9.*, 10.* |
8.2 |
10.*, 11.* |
8.3 |
11.*, 12.* |
8.4 |
11.*, 12.* |
This package requires PHP 8.1+ and Laravel 9+.
Install this package via composer:
composer require arubacao/aws-ip-range-middlewareLaravel registers the service provider automatically via package discovery. If package discovery is disabled, add the provider manually in config/app.php:
'providers' => [
// ...
Arubacao\AwsIpRange\AwsIpRangeServiceProvider::class,
],Assign the middleware a key in your app/Http/Kernel.php:
// Within App\Http\Kernel...
protected $routeMiddleware = [
// ...
'aws-ip-range' => \Arubacao\AwsIpRange\AwsIpRangeMiddleware::class,
];Route::post('api/sns', function () {
//
})->middleware('aws-ip-range');You can also pass the fully qualified class name (no Kernel registration required):
use Arubacao\AwsIpRange\AwsIpRangeMiddleware;
Route::post('api/sns', function () {
//
})->middleware(AwsIpRangeMiddleware::class);Publish the config file to override the defaults:
php artisan vendor:publish --provider="Arubacao\AwsIpRange\AwsIpRangeServiceProvider" --tag=configThis creates config/aws-ip-range.php:
return [
'url' => env('AWS_IP_RANGE_URL', 'https://ip-ranges.amazonaws.com/ip-ranges.json'),
'cache_key' => env('AWS_IP_RANGE_CACHE_KEY', 'arubacao_aws-ip-ranges'),
'cache_ttl' => (int) env('AWS_IP_RANGE_CACHE_TTL', 86400),
];composer testPlease see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.