Skip to content

Added note about trusted proxies and hosts#586

Closed
Nyholm wants to merge 2 commits intobrefphp:masterfrom
Nyholm:trusted
Closed

Added note about trusted proxies and hosts#586
Nyholm wants to merge 2 commits intobrefphp:masterfrom
Nyholm:trusted

Conversation

@Nyholm
Copy link
Contributor

@Nyholm Nyholm commented Mar 11, 2020

Trusted proxies are for:

  • Getting users IP
  • Generating links with HTTPS

Trusted hosts are for:

  • Getting correct host name

This update is probably needed for Laravel too. I leave that some someone else to contribute.

If your application needs the user's IP you must fetch it from the `LAMBDA_CONTEXT` variable.
Modify `public/index.php` accordingly.

```diff
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is diff supported?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so yes.

environment:
APP_ENV: prod
TRUSTED_PROXIES: '127.0.0.1'
TRUSTED_HOSTS: '^api\.example\.com$'
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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:

That could be done with [environment variables](#Environment variables) or by running
these lines in public/index.php.

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?

Copy link
Member

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)

## 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.
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 LAMBDA_CONTEXT_IDENTITY_SOURCEIP

Copy link
Member

Choose a reason for hiding this comment

The 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?

@mnapoli
Copy link
Member

mnapoli commented Nov 21, 2020

Closing for now (closing all stuck issues/PR from the tracker to better track the ongoing work).

@mnapoli mnapoli closed this Nov 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants