diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index bffcfd9fed3aa6a841589f8467a9da90213e05ea..bae3ad9634bb87faebd2c07b83537f1c96fb3e80 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -15,6 +15,7 @@ class Kernel extends HttpKernel */ protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, + \Fideloper\Proxy\TrustProxies::class, ]; /** diff --git a/composer.json b/composer.json index 33730d16b9479411aea7fd56244fda215e826893..3bfc901bbc97ffc33faff853468a4d6cf8fa4119 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,8 @@ "laravel/framework": "5.2.*", "mcamara/laravel-localization": "^1.1", "guzzlehttp/guzzle": "^6.2", - "jenssegers/agent": "^2.3" + "jenssegers/agent": "^2.3", + "fideloper/proxy": "^3.1" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index 8205ad207506f2a01b8950d20953e0d851b69ec2..c2af0ff21166d9c80b0b12bc121e28e877f87ae3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a5625c89574373a28838231ec9326946", - "content-hash": "ede6c673894b3df9d137acec400d9125", + "hash": "6c69571109b6dd87f8d052141f0f526c", + "content-hash": "36e343030681180e2b652dc511a00c9b", "packages": [ { "name": "classpreloader/classpreloader", @@ -161,6 +161,57 @@ ], "time": "2015-11-06 14:35:42" }, + { + "name": "fideloper/proxy", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/fideloper/TrustedProxy.git", + "reference": "ec4dd30141e2515e307aea3539ff242e85c3f120" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/fideloper/TrustedProxy/zipball/ec4dd30141e2515e307aea3539ff242e85c3f120", + "reference": "ec4dd30141e2515e307aea3539ff242e85c3f120", + "shasum": "" + }, + "require": { + "illuminate/contracts": "~5.0", + "php": ">=5.4.0" + }, + "require-dev": { + "illuminate/http": "~5.0", + "mockery/mockery": "~0.9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.1-dev" + } + }, + "autoload": { + "psr-4": { + "Fideloper\\Proxy\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Fidao", + "email": "fideloper@gmail.com" + } + ], + "description": "Set trusted proxies for Laravel", + "keywords": [ + "load balancing", + "proxy", + "trusted proxy" + ], + "time": "2015-12-24 15:02:55" + }, { "name": "guzzlehttp/guzzle", "version": "6.2.0", diff --git a/config/app.php b/config/app.php index 088dc4ddc9cc880a6ac8dfa6188cc4c0dd64efd3..786d22694dcfb2459b85f4b3a1f6664f80b2cce3 100644 --- a/config/app.php +++ b/config/app.php @@ -158,6 +158,7 @@ return [ Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider::class, App\Providers\MetaGerProvider::class, Jenssegers\Agent\AgentServiceProvider::class, + Fideloper\Proxy\TrustedProxyServiceProvider::class, ], diff --git a/config/trustedproxy.php b/config/trustedproxy.php new file mode 100644 index 0000000000000000000000000000000000000000..f4cf913d8fbd3c2f6389b520b1abf69d7a5e9d47 --- /dev/null +++ b/config/trustedproxy.php @@ -0,0 +1,44 @@ +<?php + +return [ + + /* + * Set trusted proxy IP addresses. + * + * Both IPv4 and IPv6 addresses are + * supported, along with CIDR notation. + * + * The "*" character is syntactic sugar + * within TrustedProxy to trust any proxy; + * a requirement when you cannot know the address + * of your proxy (e.g. if using Rackspace balancers). + */ + 'proxies' => [ + '5.9.157.179', + '144.76.113.134', + ], + + /* + * Or, to trust all proxies, uncomment this: + */ + # 'proxies' => '*', + + /* + * Default Header Names + * + * Change these if the proxy does + * not send the default header names. + * + * Note that headers such as X-Forwarded-For + * are transformed to HTTP_X_FORWARDED_FOR format. + * + * The following are Symfony defaults, found in + * \Symfony\Component\HttpFoundation\Request::$trustedHeaders + */ + 'headers' => [ + \Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', + \Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', + \Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', + \Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT', + ] +]; \ No newline at end of file