-
-
Notifications
You must be signed in to change notification settings - Fork 381
Added note about trusted proxies and hosts #586
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,22 @@ Since [the filesystem is readonly](/docs/environment/storage.md) except for `/tm | |
| } | ||
| ``` | ||
|
|
||
| An optional last step is to set "Trusted proxy" and "Trusted hosts". Failing to add | ||
| these will cause issues like: | ||
| - your application don't generate links using https. | ||
| - impossible to capture user IP address | ||
| - failure to recognize host names | ||
|
|
||
| That could be done with [environment variables](#Environment variables) or by running | ||
| these lines in `public/index.php`. | ||
|
|
||
| ```php | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
||
| Request::setTrustedProxies(['127.0.0.1'], Request::HEADER_X_FORWARDED_ALL); | ||
| Request::setTrustedHosts(['api\.example\.com']); | ||
| ``` | ||
|
|
||
| ## Deploy | ||
|
|
||
| Your application is now ready to be deployed. Follow [the deployment guide](/docs/deploy.md). | ||
|
|
@@ -127,8 +143,28 @@ Since Symfony 4, the production parameters are configured through environment va | |
| provider: | ||
| environment: | ||
| APP_ENV: prod | ||
| TRUSTED_PROXIES: '127.0.0.1' | ||
| TRUSTED_HOSTS: '^api\.example\.com$' | ||
| ``` | ||
|
|
||
| The secrets (e.g. database passwords) must however not be committed in this file. | ||
|
|
||
| To learn more about all this, read the [environment variables documentation](/docs/environment/variables.md). | ||
|
|
||
| ## Getting the user's IP | ||
|
|
||
| If your application needs the user's IP you must fetch it from the `LAMBDA_CONTEXT` variable. | ||
| Modify `public/index.php` accordingly. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to forward those values automatically in Bref itself? I.e. maybe (not sure) set a header with the value that is in the lambda context?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many of these solutions were discussed in #501 However, I do think it makes sense to cherry-pick useful variables. Ie creating
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but beyond #501 (which is about the request context containing many things), I'm focusing especially on HTTP-related stuff here: if we have the clients' IP address, we could maybe "fix" the HTTP headers (in the FPM runtime only) so that they contain the correct values out of the box? |
||
|
|
||
| ```diff | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so yes. |
||
| +// 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(); | ||
| ``` | ||
|
|
||
| This will only work if you configured "Trusted proxies" properly. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are these environment variables used? I can't see them in the diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are used in the Symfony default index.php
https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/5.1/public/index.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think I understand from the diff above:
Simply setting those variables is enough? I would say that it's better to document one solution, it is simpler and less confusing. The env var seem quite simple to setup (compared to editing Symfony code), what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the link, turns out we commented at the same time.
What do you think about recommending only the environment variables? (for simplicity)