Skip to content

Commit 7662d02

Browse files
committed
Avoid looking for ? when checking for file to be included
Signed-off-by: Michal Čihař <michal@cihar.com>
1 parent c27b9c1 commit 7662d02

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
&& is_string($_REQUEST['target'])
5757
&& ! preg_match('/^index/', $_REQUEST['target'])
5858
&& ! in_array($_REQUEST['target'], $target_blacklist)
59-
&& Core::checkPageValidity($_REQUEST['target'])
59+
&& Core::checkPageValidity($_REQUEST['target'], [], true)
6060
) {
6161
include $_REQUEST['target'];
6262
exit;

libraries/classes/Core.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,13 @@ public static function getRealSize($size = 0)
435435
* checks given $page against given $whitelist and returns true if valid
436436
* it optionally ignores query parameters in $page (script.php?ignored)
437437
*
438-
* @param string &$page page to check
439-
* @param array $whitelist whitelist to check page against
438+
* @param string &$page page to check
439+
* @param array $whitelist whitelist to check page against
440+
* @param boolean $include whether the page is going to be included
440441
*
441442
* @return boolean whether $page is valid or not (in $whitelist or not)
442443
*/
443-
public static function checkPageValidity(&$page, array $whitelist = [])
444+
public static function checkPageValidity(&$page, array $whitelist = [], $include = false)
444445
{
445446
if (empty($whitelist)) {
446447
$whitelist = self::$goto_whitelist;
@@ -452,6 +453,9 @@ public static function checkPageValidity(&$page, array $whitelist = [])
452453
if (in_array($page, $whitelist)) {
453454
return true;
454455
}
456+
if ($include) {
457+
return false;
458+
}
455459

456460
$_page = mb_substr(
457461
$page,

test/classes/CoreTest.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ function testArrayRemove()
267267
*
268268
* @dataProvider providerTestGotoNowhere
269269
*/
270-
function testGotoNowhere($page, $whiteList, $expected)
270+
function testGotoNowhere($page, $whiteList, $include, $expected)
271271
{
272-
$this->assertSame($expected, Core::checkPageValidity($page, $whiteList));
272+
$this->assertSame($expected, Core::checkPageValidity($page, $whiteList, $include));
273273
}
274274

275275
/**
@@ -280,12 +280,18 @@ function testGotoNowhere($page, $whiteList, $expected)
280280
public function providerTestGotoNowhere()
281281
{
282282
return array(
283-
array(null, [], false),
284-
array('export.php', [], true),
285-
array('export.php', $this->goto_whitelist, true),
286-
array('shell.php', $this->goto_whitelist, false),
287-
array('index.php?sql.php&test=true', $this->goto_whitelist, true),
288-
array('index.php%3Fsql.php%26test%3Dtrue', $this->goto_whitelist, true),
283+
array(null, [], false, false),
284+
array(null, [], true, false),
285+
array('export.php', [], false, true),
286+
array('export.php', [], true, true),
287+
array('export.php', $this->goto_whitelist, false, true),
288+
array('export.php', $this->goto_whitelist, true, true),
289+
array('shell.php', $this->goto_whitelist, false, false),
290+
array('shell.php', $this->goto_whitelist, true, false),
291+
array('index.php?sql.php&test=true', $this->goto_whitelist, false, true),
292+
array('index.php?sql.php&test=true', $this->goto_whitelist, true, false),
293+
array('index.php%3Fsql.php%26test%3Dtrue', $this->goto_whitelist, false, true),
294+
array('index.php%3Fsql.php%26test%3Dtrue', $this->goto_whitelist, true, false),
289295
);
290296
}
291297

0 commit comments

Comments
 (0)