Skip to content

Commit cb9db0e

Browse files
authored
Merge pull request #48 from phpbb/paul999-patch-1
Return a fatal when using enable_super_globals()
2 parents 5238b08 + c9725a2 commit cb9db0e

File tree

3 files changed

+97
-1
lines changed

3 files changed

+97
-1
lines changed

src/Tests/Tests/epv_test_validate_php_functions.php

+46-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use PHPParser_Node_Stmt_Interface;
3232
use PHPParser_Node_Stmt_Namespace;
3333
use PHPParser_Node_Stmt_Use;
34+
use PHPParser_Node_Expr_MethodCall;
3435
use PHPParser_Parser;
3536

3637

@@ -285,6 +286,7 @@ private function parseNode(array $nodes)
285286
$this->validateFunctionNames($node);
286287
$this->validateExit($node);
287288
$this->validatePrint($node);
289+
$this->validateMethodCalls($node);
288290
}
289291

290292
if (is_array($node) || is_object($node))
@@ -366,13 +368,56 @@ private function validateFunctionNames(PHPParser_Node $node)
366368
$name = (string)$node->expr->name->subNodes[0];
367369
}
368370

369-
if ($name != null)
371+
if ($name !== null)
370372
{
371373
$this->validateDbal($name, $node);
372374
$this->validateDeprecated($name, $node);
373375
$this->validateFunctions($name, $node);
374376
}
375377
}
378+
379+
/**
380+
* Validate method calls to classes.
381+
* @param \PHPParser_Node $node Node to validate
382+
*/
383+
private function validateMethodCalls(PHPParser_Node $node) {
384+
$name = null;
385+
if ($node instanceof PHPParser_Node_Expr_MethodCall)
386+
{
387+
if ($node->name instanceof PHPParser_Node_Expr_Variable)
388+
{
389+
// If function name is a variable.
390+
$name = (string)$node->name->name;
391+
}
392+
else
393+
{
394+
$name = (string)$node->name;
395+
}
396+
}
397+
else if (isset($node->expr) && $node->expr instanceof PHPParser_Node_Expr_MethodCall)
398+
{
399+
$name = (string)$node->expr->name;
400+
}
401+
402+
if ($name !== null)
403+
{
404+
$this->validateEnableGlobals($name, $node);
405+
}
406+
}
407+
408+
/**
409+
* Valdiate the use of enable_globals.
410+
*
411+
* @param $name
412+
* @param \PHPParser_Node $node
413+
*/
414+
private function validateEnableGlobals($name, PHPParser_Node $node)
415+
{
416+
if ($name == 'enable_super_globals')
417+
{
418+
$this->addMessage(Output::FATAL, sprintf('The use of enable_super_globals() is not allowed for security reasons on line %s', $node->getAttribute('startLine')));
419+
}
420+
}
376421

377422
/**
378423
* Valdiate the use of deprecated functions.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
*
4+
* EPV :: The phpBB Forum Extension Pre Validator.
5+
*
6+
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
class epv_test_validate_php_functions extends PHPUnit_Framework_TestCase
12+
{
13+
public static function setUpBeforeClass()
14+
{
15+
require_once('./tests/Mock/Output.php');
16+
}
17+
18+
public function test_usage_of_enable_globals() {
19+
$output = $this->getOutputMock();
20+
$output->expects($this->exactly(1))
21+
->method('addMessage')
22+
->with(\Phpbb\Epv\Output\OutputInterface::FATAL, 'The use of enable_super_globals() is not allowed for security reasons on line 7 in tests/testFiles/enable_globalsphp')
23+
;
24+
25+
$file = $this->getLoader()->loadFile('tests/testFiles/enable_globals.php');
26+
27+
$tester = new \Phpbb\Epv\Tests\Tests\epv_test_validate_php_functions(false, $output, '/a/b/', 'epv/test', false, '/a/');
28+
$tester->validateFile($file);
29+
}
30+
31+
private function getLoader()
32+
{
33+
return $file = new \Phpbb\Epv\Files\FileLoader(new \Phpbb\Epv\Tests\Mock\Output(), false, '.', '.');
34+
}
35+
36+
/**
37+
* @return \PHPUnit_Framework_MockObject_MockObject
38+
*/
39+
function getOutputMock()
40+
{
41+
return $this->getMock('Phpbb\Epv\Output\OutputInterface');
42+
}
43+
}

tests/testFiles/enable_globals.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
if (!defined('IN_PHPBB')) {
4+
exit;
5+
}
6+
7+
$request->enable_super_globals();
8+

0 commit comments

Comments
 (0)