? Success

User tests: Successful: Unsuccessful:

avatar philip-sorokin
philip-sorokin
16 May 2016

Pull Request for Issue # Redirect loop in servers with the scheme "frontend-backend"

Summary of Changes

The problem appears when using NGINX as the front-end and Apache as the back-end. If NGINX does SSL/TLS encryption, Apache might not see the variable $_SERVER['HTTPS']. In fact, it might be empty, while the URL contains a protocol HTTPs. This commit can help server administrators to handle such a configuration. If they set a variable before the back-end, for example proxy_set_header X-Forwarded-Proto https;, Joomla! will see the HTTPs.

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
4.00

avatar addondev addondev - open - 16 May 2016
avatar addondev addondev - change - 16 May 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 16 May 2016
Labels Added: ?
avatar brianteeman brianteeman - change - 16 May 2016
Category Libraries
avatar piotr-cz
piotr-cz - comment - 16 May 2016

Please see #7439

avatar addondev
addondev - comment - 16 May 2016

I think, we should not change a value of a super global variable $_SERVER['https']. All we need to do is to prevent infinite rederect loops and blocking of external resources by browsers as insecure (Joomla! sets wrong links because of that). For those, who are looking for a workaround, I can suggest Apache mod_rewrite directives:

RewriteCond %{HTTP:X-FORWARDED-PROTO} =https [NC] 
RewriteRule .? - [E=HTTPS:on]

But it would be better if it works out-of-the-box.

avatar andrepereiradasilva
andrepereiradasilva - comment - 16 May 2016

i agree with @addondev, the $_SERVER['HTTPS'] super global variable shouldn't be changed by Joomla. So, IMHO, this PR is more correct than #7439.

avatar andrepereiradasilva
andrepereiradasilva - comment - 16 May 2016

@addondev please check the code style issues

FILE: /home/travis/build/joomla/joomla-cms/libraries/joomla/uri/uri.php
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
66 | ERROR | Whitespace found at end of line
67 | ERROR | Each line in a multi-line IF statement must begin with a boolean operator
--------------------------------------------------------------------------------
avatar piotr-cz
piotr-cz - comment - 16 May 2016

agree about the global variables, but check this comment

avatar addondev
addondev - comment - 17 May 2016

@piotr-cz,
Do you mean a possible MITM attack? But this code affets only the class JUri. Joomla! will build links with a protocol http or https, according to the variable $_SERVER['HTTP_X_FORWARDED_PROTO']. How can an attacker take advantage of this?

avatar piotr-cz
piotr-cz - comment - 17 May 2016

@addondev In the request attacker will set the X_FORWARDED_PROTO header, which will translate to HTTP_X_FORWARDED_PROTO in the $_SERVER variable.

There is no good solution here, maybe a switch in the global configuration such as:

https support

  • auto (based on $_SERVER['HTTPS'])
  • on: forced
  • on: for loadbalancer IPs whitelisted below
avatar addondev
addondev - comment - 17 May 2016

@piotr-cz,
An attacker sets the X_FORWARDED_PROTO header, and the JUri class returns https links instead of http links? I agree with you, but I can't understand the profit for an attacker.

avatar piotr-cz
piotr-cz - comment - 18 May 2016

In the MITM attack, attacker could sniff sensitive information, if application would be tricked in being in SSL connection based on the JUri instance:

if (JUri:::getInstance()->getScheme() == 'https')
{
    // Secure checkout
}
else
{
    // Redirect to https
}
avatar addondev
addondev - comment - 18 May 2016

@piotr-cz
Now I agree. I think, your argument is good enough for closing this PR and the other PRs on this issue as well. We need a strong concept. By now I resolve this issue by a verification in the httpd.conf

RewriteCond %{REMOTE_ADDR} =127.0.0.1
RewriteCond %{HTTP:X-FORWARDED-PROTO} =https
RewriteRule .? - [E=HTTPS:on]

There is no information about a solution in manuals, may be we could write it for the public.

avatar gimoh
gimoh - comment - 25 Aug 2016

So you think it's better to not support SSL termination at all just so you prevent a theoretical MITM attack when it's setup incorrectly (i.e. when HTTP access is still possible)?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10512.

avatar denverkurt
denverkurt - comment - 20 Oct 2016

RewriteCond %{HTTP:X-FORWARDED-PROTO} =https [NC]
RewriteRule .? - [E=HTTPS:on]

its not work in PHP CGI mode

avatar philip-sorokin
philip-sorokin - comment - 20 Oct 2016

@denverkurt, your hosting provider must set a header in NGINX proxy_set_header X-Forwarded-Proto https in order to make it work.

avatar denverkurt
denverkurt - comment - 20 Oct 2016

no

i use one provider
if use PHP as fastCGI - it work
if use PHP as CGI - not work

header isset X-Forwarded-Proto

avatar philip-sorokin
philip-sorokin - comment - 20 Oct 2016

@denverkurt proxy_header is not the same as fastcgi_param.

avatar denverkurt
denverkurt - comment - 20 Oct 2016

header set in NGINX proxy_set_header X-Forwarded-Proto https !!!

avatar philip-sorokin philip-sorokin - change - 20 Oct 2016
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2016-10-20 21:22:09
Closed_By philip-sorokin
avatar philip-sorokin philip-sorokin - close - 20 Oct 2016
avatar philip-sorokin
philip-sorokin - comment - 20 Oct 2016

Perhaps, CGI module is old enough and does not recieve headers from a load balancer. CGI protocol was introduced in the 1990’s.

Add a Comment

Login with GitHub to post a comment