PHPackages                             jdavidbakr/cloudfront-proxies - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jdavidbakr/cloudfront-proxies

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jdavidbakr/cloudfront-proxies
=============================

Sets proxy settings for Cloudfront in a Laravel project

1.9(2mo ago)23295.6k↓40.2%7MITPHPCI failing

Since Feb 16Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/jdavidbakr/CloudfrontProxies)[ Packagist](https://packagist.org/packages/jdavidbakr/cloudfront-proxies)[ RSS](/packages/jdavidbakr-cloudfront-proxies/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (10)Versions (19)Used By (0)

Cloudfront Proxies
==================

[](#cloudfront-proxies)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c07167d3408d8ab0b73787f750d735f0c48e7a87fd804f6ec53e1f32a215e146/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a646176696462616b722f636c6f756466726f6e742d70726f786965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jdavidbakr/cloudfront-proxies)[![Total Downloads](https://camo.githubusercontent.com/4e96d8a5998b8681bec55f8ac926d03cfb4df345b2363bd0d2b61166fdddf73c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a646176696462616b722f636c6f756466726f6e742d70726f786965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jdavidbakr/cloudfront-proxies)[![Travis](https://camo.githubusercontent.com/ac6d7a6dc8607076288205f152f57ef27e1f0d028d670f0fd5293dc96afc373e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a646176696462616b722f636c6f756466726f6e7470726f786965732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/jdavidbakr/cloudfrontproxies)

Purpose
-------

[](#purpose)

One of the great things about putting your application behind a load balancer or CDN is that you can terminate your TLS there, and make the requests to your application via http. The problem with this, though, is that your application is not aware of the protocol with which it is being accessed. This will cause a problem with Laravel's URL generation tools, as the assets will be prefixed with http.

Laravel takes care of this nicely by using the TrustedProxies package, which allows you to define what IP addresses and what headers you want to use to convert the incoming request to the IP address and protocol of the originating request.

This was all wonderful, until Laravel 5.6 came out. This version of Laravel uses Symfony version 4, which no longer exposes the header you want to use to determine the protocol. Not a problem, you say, because you can use the X-Forwarded headers? It wouldn't be a problem, except for the fact that CloudFront uses a special header `Cloudfront-Forwarded-Proto` - and so now there is not a simple solution to set the protocol.

Further, you probably don't want to expose all IP addresses to your trusted proxy settings - ideally we should only use CloudFront IP addresses for our trusted proxies.

The solution
------------

[](#the-solution)

This package contains a simple middleware that does two very important tasks:

1. Downloads the CloudFront IPv4 and IPv6 addresses into the trusted proxy IP addresses. This is cached according to your cache settings for one hour, so you are not making this call on every request.
2. Adds the `X-Forwarded-Proto` header to your requests based on the `Cloudfront-Forwarded-Proto` value. This helps Symfony behave as if the original headers were what it needed in the first place.

This middleware only fires for requests that look like they came from CloudFront. It checks for any of the following headers:

- `Cloudfront-Forwarded-Proto`
- `Cloudfront-Forwarded-Port`
- `Cloudfront-Viewer-Address`
- `X-Amz-Cf-Id`

So it is ignored if you are using other load balancers or accessing the server directly.

Usage
-----

[](#usage)

To use, simply install via composer:

```
composer require jdavidbakr/cloudfront-proxies

```

Then add the middleware to your kernel after the `TrustProxies` middleware:

```
        \App\Http\Middleware\TrustProxies::class,
        \jdavidbakr\CloudfrontProxies\CloudfrontProxies::class,

```

If you desire, you may publish the config file to give you access to some options:

```
php artisan vendor:publish

```

This will publish a `cloudfront-proxies.php` config file that you may edit.

By default, this package maps the parsed `Cloudfront-Viewer-Address` IP into `X-Forwarded-For`, so Laravel/Symfony `Request::getClientIp()` (or `Request::clientIp()`) resolves to the viewer IP when behind CloudFront.

You do **not** need to set `viewer-address-attribute` for `getClientIp()` to work.

`viewer-address-attribute` is only an optional extra request attribute if you want to read the parsed viewer IP directly from request attributes:

```
// config/cloudfront-proxies.php
'viewer-address-attribute' => 'cloudfront_viewer_ip',
```

By default, this optional attribute is disabled (`null`).

If you want to disable that behavior:

```
// config/cloudfront-proxies.php
'viewer-address-to-forwarded-for' => false,
```

And everything should be good to go from here.

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance83

Actively maintained with recent releases

Popularity45

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 73.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~174 days

Recently: every ~192 days

Total

18

Last Release

86d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25177?v=4)[J David Baker](/maintainers/jdavidbakr)[@jdavidbakr](https://github.com/jdavidbakr)

---

Top Contributors

[![jdavidbakr](https://avatars.githubusercontent.com/u/25177?v=4)](https://github.com/jdavidbakr "jdavidbakr (11 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![josiasmontag](https://avatars.githubusercontent.com/u/1945577?v=4)](https://github.com/josiasmontag "josiasmontag (1 commits)")

---

Tags

laravelcloudfronttrusted proxies

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jdavidbakr-cloudfront-proxies/health.svg)

```
[![Health](https://phpackages.com/badges/jdavidbakr-cloudfront-proxies/health.svg)](https://phpackages.com/packages/jdavidbakr-cloudfront-proxies)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[nativephp/mobile

NativePHP for Mobile

1.1k75.1k91](/packages/nativephp-mobile)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[venturedrake/laravel-crm

A free open source CRM built as a package for laravel projects

43311.2k](/packages/venturedrake-laravel-crm)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
