arubacao / aws-ip-range-middleware
Laravel Middleware for Amazon Web Services (AWS) IP Address Range
Package info
github.com/arubacao/aws-ip-range-middleware
pkg:composer/arubacao/aws-ip-range-middleware
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/cache: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0|^13.0
- symfony/http-foundation: ^6.0|^7.0|^8.0
Requires (Dev)
- larastan/larastan: ^2.9|^3.0
- laravel/pint: ^1.13
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0|^11.0
- phpstan/phpstan: ^1.11|^2.0
- phpunit/phpunit: ^9.5|^10.0|^11.0|^12.0
This package is auto-updated.
Last update: 2026-06-04 19:53:52 UTC
README
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.
Features
- 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.
Supported versions
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+.
Installation
Install this package via composer:
composer require arubacao/aws-ip-range-middleware
Laravel 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, ],
Registering the middleware
Assign the middleware a key in your app/Http/Kernel.php:
// Within App\Http\Kernel... protected $routeMiddleware = [ // ... 'aws-ip-range' => \Arubacao\AwsIpRange\AwsIpRangeMiddleware::class, ];
Usage
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);
Configuration
Publish the config file to override the defaults:
php artisan vendor:publish --provider="Arubacao\AwsIpRange\AwsIpRangeServiceProvider" --tag=config
This 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), ];
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.