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
- AWS ip address range is fetched on demand and therefore always up-to-date
- Caching of ip address range --> only fetched once per day
- Retry with exponential back-off on network issues while fetching the ip address range from AWS
arubacao/aws-ip-range-middleware
is functional and fully tested for Laravel5.0
-7.*
and PHP7.0
-7.3
.
Install this package via composer:
composer require arubacao/aws-ip-range-middleware
First assign the aws-ip-range-middleware a key in your app/Http/Kernel.php
file to the $routeMiddleware
property.
// Within App\Http\Kernel Class...
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
// .
// .
// .
'aws-ip-range' => \Arubacao\AwsIpRange\AwsIpRangeMiddleware::class,
];
Once the aws-ip-range-middleware has been defined in the HTTP kernel, you may use the middleware method to assign aws-ip-range-middleware to a route:
Route::post('api/sns', function () {
//
})->middleware('aws-ip-range');
// Older Laravel Versions:
Route::post('api/sns', ['middleware' => 'aws-ip-range', function () {
//
}]);
When assigning middleware, you may also pass the fully qualified class name:
Note: In this case you do not need to register the aws-ip-range-middleware in the HTTP kernel
use Arubacao\AwsIpRange\AwsIpRangeMiddleware;
Route::post('api/sns', function () {
//
})->middleware(AwsIpRangeMiddleware::class);
// Older Laravel Versions:
Route::post('api/sns', ['middleware' => AwsIpRangeMiddleware::class, function () {
//
}]);
- Enable/Disable caching
- Choose cache storage
- Command to fetch ip address range and store locally
composer test
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.