1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-24 21:48:21 +01:00
phorge-phorge/src/infrastructure/env
epriestley adc2002d28 Make it easier to parse "X-Forwarded-For" with one or more load balancers
Summary:
Fixes T13392. If you have 17 load balancers in sequence, Phabricator will receive requests with at least 17 "X-Forwarded-For" components in the header.

We want to select the 17th-from-last element, since prior elements are not trustworthy.

This currently isn't very easy/obvious, and you have to add a kind of sketchy piece of custom code to `preamble.php` to do any "X-Forwarded-For" parsing. Make handling this correctly easier.

Test Plan:
  - Ran unit tests.
  - Configured my local `preamble.php` to call `preamble_trust_x_forwarded_for_header(4)`, then made `/debug/` dump the header and the final value of `REMOTE_ADDR`.

```
$ curl http://local.phacility.com/debug/
<pre>

HTTP_X_FORWARDED_FOR =
   FINAL REMOTE_ADDR = 127.0.0.1
</pre>
```

```
$ curl -H 'X-Forwarded-For: 1.1.1.1, 2.2.2.2, 3.3.3.3, 4.4.4.4, 5.5.5.5, 6.6.6.6' http://local.phacility.com/debug/
<pre>

HTTP_X_FORWARDED_FOR = 1.1.1.1, 2.2.2.2, 3.3.3.3, 4.4.4.4, 5.5.5.5, 6.6.6.6
   FINAL REMOTE_ADDR = 3.3.3.3
</pre>
```

```
$ curl -H 'X-Forwarded-For: 5.5.5.5, 6.6.6.6' http://local.phacility.com/debug/
<pre>

HTTP_X_FORWARDED_FOR = 5.5.5.5, 6.6.6.6
   FINAL REMOTE_ADDR = 5.5.5.5
</pre>
```

Maniphest Tasks: T13392

Differential Revision: https://secure.phabricator.com/D20785
2019-09-05 04:30:13 -07:00
..
__tests__ Provide PhabricatorEnv::isSelfURI to test if a URI points at the current install 2017-03-17 16:44:53 -07:00
PhabricatorConfigDatabaseSource.php Add database configuration source to the source stack 2013-01-17 15:10:21 -08:00
PhabricatorConfigDefaultSource.php Read default values of custom config options 2013-01-19 08:36:08 -08:00
PhabricatorConfigDictionarySource.php Formalize configuration sources and source stacks 2012-12-25 06:44:29 -08:00
PhabricatorConfigFileSource.php phtize all the things 2015-05-22 21:16:39 +10:00
PhabricatorConfigLocalSource.php Make the success message from "bin/config" more clear 2019-08-12 12:50:03 -07:00
PhabricatorConfigProxySource.php phtize all the things 2015-05-22 21:16:39 +10:00
PhabricatorConfigSiteSource.php Add an extensible "SiteSource" for configuration 2014-11-05 15:30:40 -08:00
PhabricatorConfigSource.php Extend from Phobject 2015-06-15 18:02:27 +10:00
PhabricatorConfigStackSource.php phtize all the things 2015-05-22 21:16:39 +10:00
PhabricatorEnv.php Make it easier to parse "X-Forwarded-For" with one or more load balancers 2019-09-05 04:30:13 -07:00
PhabricatorScopedEnv.php Extend from Phobject 2015-06-15 18:02:27 +10:00