arubacao / aws-ip-range-middleware
Laravel Middleware for Amazon Web Services (AWS) IP Address Range
Installs: 2 271
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: ^7.0|^8.0
- graham-campbell/guzzle-factory: ^3.0|^4.0|^5.0
- illuminate/cache: ^5.0|^6.0|^7.0|^8.0
- symfony/http-foundation: ~2.0|~3.0|~4.0|~5.0
Requires (Dev)
- orchestra/testbench: ~3.0|4.*|5.*|6.*
- phpunit/phpunit: ~4.8.36 || >=5.7.21
This package is auto-updated.
Last update: 2024-10-29 05:10:42 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
- 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
Notes
arubacao/aws-ip-range-middleware
is functional and fully tested for Laravel5.0
-7.*
and PHP7.0
-7.3
.
Installation
Install this package via composer:
composer require arubacao/aws-ip-range-middleware
Registering 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, ];
Usage
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 () { // }]);
Todo's
- Enable/Disable caching
- Choose cache storage
- Command to fetch ip address range and store locally
Testing
composer test
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.