1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 07:24:27 +02:00

Fixes wrong IP address when using a reverse proxy (#2236)

Added reverse proxy support to preserve forwarded IPs
This commit is contained in:
Jake Esser
2020-07-22 14:55:44 +02:00
committed by GitHub
parent eaac78650f
commit 451a557532
7 changed files with 128 additions and 2 deletions

View File

@@ -22,6 +22,7 @@ use Flarum\Http\Middleware as HttpMiddleware;
use Flarum\Http\RouteCollection;
use Flarum\Http\RouteHandlerFactory;
use Flarum\Http\UrlGenerator;
use Illuminate\Support\Arr;
use Laminas\Stratigility\MiddlewarePipe;
class ApiServiceProvider extends AbstractServiceProvider
@@ -45,6 +46,7 @@ class ApiServiceProvider extends AbstractServiceProvider
$this->app->singleton('flarum.api.middleware', function () {
return [
'flarum.api.error_handler',
'flarum.api.proxy_middleware',
HttpMiddleware\ParseJsonBody::class,
Middleware\FakeHttpMethods::class,
HttpMiddleware\StartSession::class,
@@ -64,6 +66,15 @@ class ApiServiceProvider extends AbstractServiceProvider
);
});
$this->app->bind('flarum.api.proxy_middleware', function () {
$config = $this->app->make('flarum.config');
return new HttpMiddleware\ProxyAddress(
Arr::get($config, 'reverse_proxy.enabled', false),
Arr::get($config, 'reverse_proxy.allowed', ['127.0.0.1'])
);
});
$this->app->singleton('flarum.api.handler', function () {
$pipe = new MiddlewarePipe;