arubacao/aws-ip-range-middleware

Laravel Middleware for Amazon Web Services (AWS) IP Address Range
2,412 17
Install
composer require arubacao/aws-ip-range-middleware
Latest Version:v1.3.0
PHP:^8.1
License:MIT
Last Updated:Jun 4, 2026
Links: GitHub  ·  Packagist
Maintainer: arubacao

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

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.

Related Packages

dusterio/laravel-aws-worker

Run Laravel (or Lumen) tasks and queue listeners inside of AWS Elastic Beanstalk...

6,054,184 307
codesleeve/laravel-stapler

Easy file upload management for the Laravel Framework.

415,863 556
atyagi/elasticache-laravel

Elasticache Drivers for Laravel Cache and Session

313,478 25
dusterio/laravel-plain-sqs

Custom SQS connector for Laravel that supports custom format JSON

2,871,990 134
aws/aws-sdk-php-laravel

A simple Laravel 9/10/11/12/13 service provider for including the AWS SDK for PH...

41,170,406 1,715