XF 2.0 Xenforo CDN Issues

TheMantis

Member
Hi New Xenforo user here!

I recently switched from vbulletin to Xenforo 2. Very happy with the switch so far except I am having issues using my CDN(Content Delivery Network) with the site.

The root of the issue is Xenforo is only picking up the IP's of the CDN endpoints instead of the actual client IP.

Now the CDN does provide the actual client IP in the "HTTP_X_FORWARDED_FOR" HTTP field in the following format. However Xenforo grabs the IP "192.16.55.202" instead of 111.111.111.111
$_SERVER['HTTP_X_FORWARDED_FOR']111.111.111111, 192.16.55.202, 108.161.246.65:38574


It is also can be presented in a Custom header for example I could have it dumped exclusively into "HTTP_ENDUSER_IP" in the format of
$_SERVER['HTTP_ENDUSER_IP']111.111.111.111

Where 111.111.111.111 is the actual client IP in both examples.


For Xenforo I see that it does have options for using Cloudflare exclusively but those options have been highly customized for use with CF only. I use both Akamai's and Verizon's CDN's through Azure with my websites hosted within.

I have gotten around the issue for now by modifying the src/XF/Http/Request.php from approximately line 438 changing "REMOTE_ADDR" to "HTTP_ENDUSER_IP"

###########
if ($this->_remoteIp === null)
{
$ip = $this->getTrustedRealIp($this->getServer('HTTP_ENDUSER_IP'));
$this->_remoteIp = $this->getFilteredIp($ip);
#########

Akamai CDN - Largest CDN in the world
https://www.akamai.com/

Verizon CDN
https://www.verizondigitalmedia.com/platform/edgecast-cdn/

Potential Questions/Solutions
1) Can we make the code compatible with *Any CDN?
- Steps Required
1) In the Options provide a field which we can enter IP's that the CDN uses(Similar to the same functionality which already exists for Cloudflare)
2) Provide an option field to specific the header containing the actual client IP.
2) Is there a way to provide an exception to the file verification checks which does now fail because of my custom modification of this header?
3) Did I miss something is there an easier way to fix this?

Thanks in advance!

 
Sorry maybe I missed something.... not trying to be rude, but asking for true clarification instead of saying check out this link, which I referenced that error in my original post.

The easy would be essentially what I have done. However there are problems with that.

If I overwrite the IP as you say the header it is looking for is specific to cloudflare not any other CDN.
If I edit the files I still have the issue where it mentions the files are not valid "There are 1 missing files or files with unexpected contents. You should review these. "

When I made the suggestions it would be for the better of the overall application not simply make it specific for cloudflare which it has done so far.

If we make the IP's a field in the options instead of the files we do not have the issue with the validation, and we also make it generic for any CDN in the future

If we make the header it uses a field in the options instead of being hardset we make it generic for use with a CDN or even without a CDN, even use with a Load balancer etc..

Maybe I missed something?
 
All I meant was that you just need to add this to your src/config.php file:

PHP:
if (isset($_SERVER['HTTP_ENDUSER_IP']))
{
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_ENDUSER_IP'];
}
Based on the code you’ve already given as an example, that’s the exact code you need to use in src/config.php, and it doesn’t require editing a core file.

This basically answers question 3) that you asked in your original post.

For everything else, we’re not really looking to do any of that at this point and the code above is the recommended approach.
 
Top Bottom