• Stars
    star
    7,355
  • Rank 5,259 (Top 0.2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 11 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Laravel Proxy Package for handling sessions when behind load balancers or other intermediaries.

Laravel Trusted Proxies

Build Status Total Downloads

Setting a trusted proxy allows for correct URL generation, redirecting, session handling and logging in Laravel when behind a reverse proxy such as a load balancer or cache.


Installation

Laravel 5.5+ comes with this package. If you are using Laravel 5.5 or greater, you do not need to add this to your project separately.

Laravel 5.0 - 5.4

To install Trusted Proxy, use:

composer require fideloper/proxy:^3.3

Laravel 4

composer require fideloper/proxy:^2.0

Setup

Refer to the docs above for using Trusted Proxy in Laravel 5.5+. For Laravel 4.0 - 5.4, refer to the wiki.

What Does This Do?

Setting a trusted proxy allows for correct URL generation, redirecting, session handling and logging in Laravel when behind a reverse proxy.

This is useful if your web servers sit behind a load balancer (Nginx, HAProxy, Envoy, ELB/ALB, etc), HTTP cache (CloudFlare, Squid, Varnish, etc), or other intermediary (reverse) proxy.

How Does This Work?

Applications behind a reverse proxy typically read some HTTP headers such as X-Forwarded, X-Forwarded-For, X-Forwarded-Proto (and more) to know about the real end-client making an HTTP request.

If those headers were not set, then the application code would think every incoming HTTP request would be from the proxy.

Laravel (technically the Symfony HTTP base classes) have a concept of a "trusted proxy", where those X-Forwarded headers will only be used if the source IP address of the request is known. In other words, it only trusts those headers if the proxy is trusted.

This package creates an easier interface to that option. You can set the IP addresses of the proxies (that the application would see, so it may be a private network IP address), and the Symfony HTTP classes will know to use the X-Forwarded headers if an HTTP requets containing those headers was from the trusted proxy.

Why Does This Matter?

A very common load balancing approach is to send https:// requests to a load balancer, but send http:// requests to the application servers behind the load balancer.

For example, you may send a request in your browser to https://example.org. The load balancer, in turn, might send requests to an application server at http://192.168.1.23.

What if that server returns a redirect, or generates an asset url? The users's browser would get back a redirect or HTML that includes http://192.168.1.23 in it, which is clearly wrong.

What happens is that the application thinks its hostname is 192.168.1.23 and the schema is http://. It doesn't know that the end client used https://example.org for its web request.

So the application needs to know to read the X-Forwarded headers to get the correct request details (schema https://, host example.org).

Laravel/Symfony automatically reads those headers, but only if the trusted proxy configuration is set to "trust" the load balancer/reverse proxy.

Note: Many of us use hosted load balancers/proxies such as AWS ELB/ALB, etc. We don't know the IP address of those reverse proxies, and so you need to trusted all proxies in that case.

The trade-off there is running the security risk of allowing people to potentially spoof the X-Forwarded headers.

IP Addresses by Service

This Wiki page has a list of popular services and their IP addresses of their servers, if available. Any updates or suggestions are welcome!

More Repositories

1

Vaprobash

Vagrant Provisioning Bash Scripts
Shell
1,929
star
2

docker-nginx-php

An Ubuntu, Nginx and PHP stack Built in Docker
Shell
361
star
3

Implementing-Laravel

Companion application to the e-book Implementing Laravel
CSS
173
star
4

hexagonal-php

Code to support my talk on Hexagonal PHP and Laravel
PHP
109
star
5

docker-mysql

A Docker container for MySQL
Shell
95
star
6

CI-Mandrill

A Codeigniter library for the Mandrill email platform
PHP
50
star
7

larvel

The little emoji framework.
PHP
38
star
8

l4-api

Example Laravel 4 API with ETags
PHP
29
star
9

fideloper.com

My Site
PHP
28
star
10

Queue-Image-Processing

Image processing offline using Queues in Laravel
PHP
26
star
11

UniversalAnalytics

PHP Implementation of Google's Measurement Protocol
PHP
21
star
12

Generic-Facebook-App

For Great Copy-Pasta Justice!
PHP
16
star
13

vaprobash12

Vagrant Provisioning Bash Scripts for Ubuntu 12.04
Shell
15
star
14

Mailman

A CodeIgniter library for using third-party email systems.
PHP
15
star
15

dotfiles

My Dotfiles
Shell
13
star
16

myproxy

This is my proxy. There are many like it, but this one is mine.
Go
12
star
17

livewire-global-notifications

See https://fly.io/laravel-bytes/global-notifications-with-livewire/
PHP
12
star
18

ConditionalRequest

Handle Validation Cacheing and Concurrency Control (Etags/Modified Dates), geared towards Laravel 4/Symfony
PHP
10
star
19

entity-mapper

An Entity Mapping ORM
PHP
9
star
20

How-EE-Works

A brief explanation of How Expression Engine Works - Content organization and Templates
PHP
8
star
21

CI-Hook

Namespaced Observer pattern with some PubSub flavor for CodeIgniter
PHP
8
star
22

ResourceCache

Handle Validation Cacheing and Concurrency Control (Etags/Modified Dates) in Laravel 4
PHP
7
star
23

Learnix

Notes while learning *nix system admin
7
star
24

Laravel-Architecture

Experimenting with code Architecture in Laravel
PHP
6
star
25

recipeplz

Parse some recipes
PHP
6
star
26

deploy-me

Example deploy setup
PHP
6
star
27

Porter

Extendable link-parser and meta-data obtainer for various services such as Vimeo and Youtube
PHP
5
star
28

Design-Patterns

Exploring design patterns and their uses. See the readme for more information.
PHP
5
star
29

jQuery-Infinite-Carousel

Adaption of the jQuery Infinite Carousel
4
star
30

node-remotecontrol

Control a Vimeo video with Socket.io
JavaScript
3
star
31

Earthquake

Tracking tweets related to #earthquake and their locations. Google maps display over time, and database of tweets.
JavaScript
3
star
32

on-demand-compute

On-demand compute using Fly.io Machines API
PHP
2
star
33

Markdown-web

Website supporting Markdown-API
PHP
2
star
34

livewire-browser-stream

Streaming content to your browser with Laravel Echo and Livewire
PHP
2
star
35

saas-starter

Shell Application for a SaaS Application. Will it be abandoned, like so many other projects? Who knows.
CSS
2
star
36

Timely

Tools for handling time and timezones
PHP
2
star
37

Articles

Markdown Articles
2
star
38

punctual

Because already-read-it > read-it-later
PHP
2
star
39

Markdown-api

A Node-based [simple] Markdown API. Send Markdown, get HTML
JavaScript
1
star
40

Create-H5BP-project--CLI

I'm lazy, and h5bp is awesome.
Shell
1
star
41

chipperci-failing-project

Generate some logs and screenshot files
PHP
1
star
42

Testable-Maintainable

Code for "Writing Testable & Maintainable PHP" presentation
PHP
1
star
43

Me

JavaScript
1
star
44

Cookbook

Laravel 4 Cookbook Sample Project
PHP
1
star
45

Learnpythonthehardway

Keeping track of lesson files.
Python
1
star
46

Shooter

JS Bookmarklet, destroy DOM elements
JavaScript
1
star
47

cli-browser-register

Example of using a CLI command to kick off registration and magically get an API key back
PHP
1
star
48

larvel-example

Example use of the Larvelโ„ข Framework
PHP
1
star
49

ExpressionEngine---Dev-Tools

Some development tools for EE2
PHP
1
star
50

ExpressionEngine---Youtube-field

Grabs the youtube video ID and gives you options on using it for display.
PHP
1
star
51

expediatedwaf

For Mike
Dockerfile
1
star
52

fideloper.github.io

HTML
1
star
53

max-children.com

https://max-children.com
PHP
1
star