Skip to content

Commit

Permalink
Merge pull request #14418 from nijel/page_validity
Browse files Browse the repository at this point in the history
Avoid looking for ? when checking for file to be included
  • Loading branch information
ibennetch committed Jun 21, 2018
2 parents c27b9c1 + 7662d02 commit 536b214
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.php
Expand Up @@ -56,7 +56,7 @@
&& is_string($_REQUEST['target'])
&& ! preg_match('/^index/', $_REQUEST['target'])
&& ! in_array($_REQUEST['target'], $target_blacklist)
&& Core::checkPageValidity($_REQUEST['target'])
&& Core::checkPageValidity($_REQUEST['target'], [], true)
) {
include $_REQUEST['target'];
exit;
Expand Down
10 changes: 7 additions & 3 deletions libraries/classes/Core.php
Expand Up @@ -435,12 +435,13 @@ public static function getRealSize($size = 0)
* checks given $page against given $whitelist and returns true if valid
* it optionally ignores query parameters in $page (script.php?ignored)
*
* @param string &$page page to check
* @param array $whitelist whitelist to check page against
* @param string &$page page to check
* @param array $whitelist whitelist to check page against
* @param boolean $include whether the page is going to be included
*
* @return boolean whether $page is valid or not (in $whitelist or not)
*/
public static function checkPageValidity(&$page, array $whitelist = [])
public static function checkPageValidity(&$page, array $whitelist = [], $include = false)
{
if (empty($whitelist)) {
$whitelist = self::$goto_whitelist;
Expand All @@ -452,6 +453,9 @@ public static function checkPageValidity(&$page, array $whitelist = [])
if (in_array($page, $whitelist)) {
return true;
}
if ($include) {
return false;
}

$_page = mb_substr(
$page,
Expand Down
22 changes: 14 additions & 8 deletions test/classes/CoreTest.php
Expand Up @@ -267,9 +267,9 @@ function testArrayRemove()
*
* @dataProvider providerTestGotoNowhere
*/
function testGotoNowhere($page, $whiteList, $expected)
function testGotoNowhere($page, $whiteList, $include, $expected)
{
$this->assertSame($expected, Core::checkPageValidity($page, $whiteList));
$this->assertSame($expected, Core::checkPageValidity($page, $whiteList, $include));
}

/**
Expand All @@ -280,12 +280,18 @@ function testGotoNowhere($page, $whiteList, $expected)
public function providerTestGotoNowhere()
{
return array(
array(null, [], false),
array('export.php', [], true),
array('export.php', $this->goto_whitelist, true),
array('shell.php', $this->goto_whitelist, false),
array('index.php?sql.php&test=true', $this->goto_whitelist, true),
array('index.php%3Fsql.php%26test%3Dtrue', $this->goto_whitelist, true),
array(null, [], false, false),
array(null, [], true, false),
array('export.php', [], false, true),
array('export.php', [], true, true),
array('export.php', $this->goto_whitelist, false, true),
array('export.php', $this->goto_whitelist, true, true),
array('shell.php', $this->goto_whitelist, false, false),
array('shell.php', $this->goto_whitelist, true, false),
array('index.php?sql.php&test=true', $this->goto_whitelist, false, true),
array('index.php?sql.php&test=true', $this->goto_whitelist, true, false),
array('index.php%3Fsql.php%26test%3Dtrue', $this->goto_whitelist, false, true),
array('index.php%3Fsql.php%26test%3Dtrue', $this->goto_whitelist, true, false),
);
}

Expand Down

0 comments on commit 536b214

Please sign in to comment.