Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Trusted proxies #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Symfony/assets/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
Request::setTrustedHosts([$trustedHosts]);
}

// Get user IP:
if (isset($_SERVER['LAMBDA_CONTEXT'])) {
$context = json_decode($_SERVER['LAMBDA_CONTEXT'], true);
$_SERVER['HTTP_X_FORWARDED_FOR'] = $context['identity']['sourceIp'] ?? '';
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();

// Trust all headers for everyone. This is extremely dangerous. But it fine if the code runs on Lambda thanks to AWs security.
Request::setTrustedProxies(['127.0.0.1', $request->server->get('REMOTE_ADDR')], Request::HEADER_X_FORWARDED_ALL);

$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
1 change: 1 addition & 0 deletions Symfony/assets/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ provider:
runtime: provided
environment:
APP_ENV: prod
TRUSTED_PROXIES: '127.0.0.1'
APP_SECRET: 7ca3adc3815e12d67b4637595b7f9dff
MESSENGER_TRANSPORT_DSN: https://sqs.us-east-1.amazonaws.com/403367587399/foobar

Expand Down
10 changes: 6 additions & 4 deletions Symfony/binary/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
Request::setTrustedHosts([$trustedHosts]);
}

// Get user IP:
if (isset($_SERVER['LAMBDA_CONTEXT'])) {
$context = json_decode($_SERVER['LAMBDA_CONTEXT'], true);
$_SERVER['HTTP_X_FORWARDED_FOR'] = $context['identity']['sourceIp'] ?? '';
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();

// Trust all headers for everyone. This is extremely dangerous. But it fine if the code runs on Lambda thanks to AWs security.
Request::setTrustedProxies(['127.0.0.1', $request->server->get('REMOTE_ADDR')], Request::HEADER_X_FORWARDED_ALL);

$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
1 change: 1 addition & 0 deletions Symfony/binary/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ provider:

environment:
APP_ENV: prod
TRUSTED_PROXIES: '127.0.0.1'
APP_SECRET: 7ca3adc3815e12d67b4637595b7f9dff
MY_BUCKET: 'bref-example'
BREF_BINARY_RESPONSES: 1
Expand Down
10 changes: 6 additions & 4 deletions Symfony/sqs/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
Request::setTrustedHosts([$trustedHosts]);
}

// Get user IP:
if (isset($_SERVER['LAMBDA_CONTEXT'])) {
$context = json_decode($_SERVER['LAMBDA_CONTEXT'], true);
$_SERVER['HTTP_X_FORWARDED_FOR'] = $context['identity']['sourceIp'] ?? '';
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();

// Trust all headers for everyone. This is extremely dangerous. But it fine if the code runs on Lambda thanks to AWs security.
Request::setTrustedProxies(['127.0.0.1', $request->server->get('REMOTE_ADDR')], Request::HEADER_X_FORWARDED_ALL);

$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
1 change: 1 addition & 0 deletions Symfony/sqs/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ provider:
runtime: provided
environment:
APP_ENV: prod
TRUSTED_PROXIES: '127.0.0.1'
APP_SECRET: 7ca3adc3815e12d67b4637595b7f9dff
MESSENGER_TRANSPORT_DSN: https://sqs.us-east-1.amazonaws.com/403367587399/foobar

Expand Down