Skip to content
Extraits de code Groupes Projets
Valider ae71bc82 rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

Do not overwrite piwikUrl when host is localhost

parent 41b743af
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -839,9 +839,8 @@ class Http ...@@ -839,9 +839,8 @@ class Http
private static function getProxyConfiguration($url) private static function getProxyConfiguration($url)
{ {
$hostname = UrlHelper::getHostFromUrl($url); $hostname = UrlHelper::getHostFromUrl($url);
$localHostnames = Url::getLocalHostnames();
if(in_array($hostname, $localHostnames)) { if (Url::isLocalHost($hostname)) {
return array(null, null, null, null); return array(null, null, null, null);
} }
......
...@@ -152,6 +152,6 @@ class Mail extends Zend_Mail ...@@ -152,6 +152,6 @@ class Mail extends Zend_Mail
*/ */
protected function isHostDefinedAndNotLocal($url) protected function isHostDefinedAndNotLocal($url)
{ {
return isset($url['host']) && !in_array($url['host'], Url::getLocalHostnames(), true); return isset($url['host']) && !Url::isLocalHost($url['host']);
} }
} }
...@@ -186,7 +186,10 @@ class SettingsPiwik ...@@ -186,7 +186,10 @@ class SettingsPiwik
// if URL changes, always update the cache // if URL changes, always update the cache
|| $currentUrl != $url || $currentUrl != $url
) { ) {
if (strlen($currentUrl) >= strlen('http://a/')) { $host = Url::getHostFromUrl($url);
if (strlen($currentUrl) >= strlen('http://a/')
&& !Url::isLocalHost($host)) {
self::overwritePiwikUrl($currentUrl); self::overwritePiwikUrl($currentUrl);
} }
$url = $currentUrl; $url = $currentUrl;
......
...@@ -551,6 +551,21 @@ class Url ...@@ -551,6 +551,21 @@ class Url
&& in_array($parsedUrl['scheme'], array('http', 'https')); && in_array($parsedUrl['scheme'], array('http', 'https'));
} }
/**
* Checks whether the given host is a local host like `127.0.0.1` or `localhost`.
*
* @param string $host
* @return bool
*/
public static function isLocalHost($host)
{
if (empty($host)) {
return false;
}
return in_array($host, Url::getLocalHostnames(), true);
}
public static function getTrustedHostsFromConfig() public static function getTrustedHostsFromConfig()
{ {
$hosts = self::getHostsFromConfig('General', 'trusted_hosts'); $hosts = self::getHostsFromConfig('General', 'trusted_hosts');
...@@ -677,7 +692,6 @@ class Url ...@@ -677,7 +692,6 @@ class Url
return array('localhost', '127.0.0.1', '::1', '[::1]'); return array('localhost', '127.0.0.1', '::1', '[::1]');
} }
/** /**
* @return bool * @return bool
*/ */
......
...@@ -13,12 +13,10 @@ use Piwik\Url; ...@@ -13,12 +13,10 @@ use Piwik\Url;
/** /**
* @backupGlobals enabled * @backupGlobals enabled
* @group Core
*/ */
class UrlTest extends \PHPUnit_Framework_TestCase class UrlTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @group Core
*/
public function testAllMethods() public function testAllMethods()
{ {
$this->assertEquals(Url::getCurrentQueryStringWithParametersModified(array()), Url::getCurrentQueryString()); $this->assertEquals(Url::getCurrentQueryStringWithParametersModified(array()), Url::getCurrentQueryString());
...@@ -63,7 +61,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -63,7 +61,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider getCurrentHosts * @dataProvider getCurrentHosts
* @group Core
*/ */
public function testGetCurrentHost($description, $test) public function testGetCurrentHost($description, $test)
{ {
...@@ -131,9 +128,31 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -131,9 +128,31 @@ class UrlTest extends \PHPUnit_Framework_TestCase
); );
} }
/**
* @dataProvider getIsLocalHost
*/
public function test_isLocalHost($expectedIsLocal, $host)
{
$this->assertSame($expectedIsLocal, Url::isLocalHost($host));
}
public function getIsLocalHost()
{
return array(
array($isLocal = false, '127.0.0.2'),
array($isLocal = false, '192.168.1.1'),
array($isLocal = false, '10.1.1.1'),
array($isLocal = false, '172.30.1.1'),
array($isLocal = true, 'localhost'),
array($isLocal = true, '127.0.0.1'),
array($isLocal = true, '::1'),
array($isLocal = true, '[::1]'),
);
}
/** /**
* @dataProvider getLocalUrls * @dataProvider getLocalUrls
* @group Core
*/ */
public function testIsLocalUrl($httphost, $scripturi, $requesturi, $testurl, $result) public function testIsLocalUrl($httphost, $scripturi, $requesturi, $testurl, $result)
{ {
...@@ -161,7 +180,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -161,7 +180,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider getCurrentUrlWithoutFilename * @dataProvider getCurrentUrlWithoutFilename
* @group Core
*/ */
public function testGetCurrentUrlWithoutFilename($expected, $https, $host, $path) public function testGetCurrentUrlWithoutFilename($expected, $https, $host, $path)
{ {
...@@ -182,9 +200,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -182,9 +200,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, $url); $this->assertEquals($expected, $url);
} }
/**
* @group Core
*/
public function test_getCurrentScriptName() public function test_getCurrentScriptName()
{ {
$this->resetGlobalVariables(); $this->resetGlobalVariables();
...@@ -238,7 +253,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -238,7 +253,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
/** /**
* @dataProvider getValidHostData * @dataProvider getValidHostData
* @group Core
*/ */
public function testIsValidHost($expected, $host, $trustedHosts, $description) public function testIsValidHost($expected, $host, $trustedHosts, $description)
{ {
...@@ -247,9 +261,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -247,9 +261,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expected, Url::isValidHost($host), $description); $this->assertEquals($expected, Url::isValidHost($host), $description);
} }
/**
* @group Core
*/
public function testGetReferrer() public function testGetReferrer()
{ {
$_SERVER['HTTP_REFERER'] = 'http://www.piwik.org'; $_SERVER['HTTP_REFERER'] = 'http://www.piwik.org';
...@@ -257,8 +268,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -257,8 +268,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @group Core
*
* @dataProvider getQueryParameters * @dataProvider getQueryParameters
*/ */
public function testGetQueryStringFromParameters($params, $queryString) public function testGetQueryStringFromParameters($params, $queryString)
...@@ -281,8 +290,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -281,8 +290,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @group Core
*
* @dataProvider getHostsFromUrl * @dataProvider getHostsFromUrl
*/ */
public function testGetHostsFromUrl($url, $expectedHost) public function testGetHostsFromUrl($url, $expectedHost)
...@@ -304,8 +311,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -304,8 +311,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @group Core
*
* @dataProvider getIsHostInUrls * @dataProvider getIsHostInUrls
*/ */
public function testIsHostInUrlsl($isHost, $host, $urls) public function testIsHostInUrlsl($isHost, $host, $urls)
...@@ -348,7 +353,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -348,7 +353,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @group Core
* @dataProvider urlProvider * @dataProvider urlProvider
*/ */
public function testGetCurrentUrl($url, $pathInfo = null) public function testGetCurrentUrl($url, $pathInfo = null)
...@@ -372,7 +376,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -372,7 +376,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* @group Core
* @dataProvider urlWithoutQueryStringProvider * @dataProvider urlWithoutQueryStringProvider
*/ */
public function testGetCurrentUrlWithoutQueryString($url, $expected, $pathInfo = null) public function testGetCurrentUrlWithoutQueryString($url, $expected, $pathInfo = null)
...@@ -387,7 +390,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase ...@@ -387,7 +390,6 @@ class UrlTest extends \PHPUnit_Framework_TestCase
* Tests a use case that was reported by some users: Nginx is not properly configured and passes * Tests a use case that was reported by some users: Nginx is not properly configured and passes
* incorrect PATH_INFO values in $_SERVER. * incorrect PATH_INFO values in $_SERVER.
* @link https://github.com/piwik/piwik/issues/6491 * @link https://github.com/piwik/piwik/issues/6491
* @group Core
*/ */
public function testMisconfiguredNginxPathInfo() public function testMisconfiguredNginxPathInfo()
{ {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter