arubacao/aws-ip-range-middleware

Laravel Middleware for Amazon Web Services (AWS) IP Address Range

Maintainers

Package info

github.com/arubacao/aws-ip-range-middleware

pkg:composer/arubacao/aws-ip-range-middleware

Statistics

Installs: 2 316

Dependents: 0

Suggesters: 0

Stars: 17

Open Issues: 1

v1.3.0 2026-06-04 19:51 UTC

This package is auto-updated.

Last update: 2026-06-04 19:53:52 UTC


README

Latest Version on Packagist Run Tests Total Downloads

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.