https://github.com/arubacao/aws-ip-range-middleware
Laravel Middleware for Amazon Web Services (AWS) IP Address Range Validation
https://github.com/arubacao/aws-ip-range-middleware
aws ip ip-ranges laravel middleware
Last synced: over 1 year ago
JSON representation
Laravel Middleware for Amazon Web Services (AWS) IP Address Range Validation
- Host: GitHub
- URL: https://github.com/arubacao/aws-ip-range-middleware
- Owner: arubacao
- License: mit
- Created: 2018-02-14T10:01:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-05-03T00:07:50.000Z (about 5 years ago)
- Last Synced: 2025-03-17T16:50:01.229Z (over 1 year ago)
- Topics: aws, ip, ip-ranges, laravel, middleware
- Language: PHP
- Homepage:
- Size: 18.6 KB
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Middleware for Amazon Web Services (AWS) IP Address Range Validation
[](https://packagist.org/packages/arubacao/aws-ip-range-middleware)
[](https://github.com/arubacao/aws-ip-range-middleware/actions?query=workflow%3A%22Run+Tests%22)
[](https://codecov.io/gh/arubacao/aws-ip-range-middleware)
[](https://packagist.org/packages/arubacao/aws-ip-range-middleware)
This package allows for **validation** of incoming **requests** against the official [Amazon Web Services (AWS) IP Address Range](https://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html).
Use this to determine if an incoming request actually comes from the AWS infrastructure e.g. for [Simple Notification Service (SNS)](https://docs.aws.amazon.com/sns/latest/dg/welcome.html) 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 Laravel `5.0` - `7.*` and PHP `7.0` - `7.3`.
## Installation
Install this package via composer:
```bash
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.
```PHP
// 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:
```PHP
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_
```PHP
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
``` bash
composer test
```
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## Credits
- [Christopher Lass](https://github.com/arubacao)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.