-
Notifications
You must be signed in to change notification settings - Fork 160
[Enhancement] DiscouragedFunction rule improvement #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento2\Sniffs\Security; | ||
|
||
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff; | ||
|
||
/** | ||
* Detects the use of insecure functions. | ||
*/ | ||
class InsecureFunctionSniff extends ForbiddenFunctionsSniff | ||
{ | ||
/** | ||
* If true, an error will be thrown; otherwise a warning. | ||
* | ||
* @var boolean | ||
*/ | ||
public $error = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it a warning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's under |
||
|
||
/** | ||
* List of patterns for forbidden functions. | ||
* | ||
* @var array | ||
*/ | ||
public $forbiddenFunctions = [ | ||
'assert' => null, | ||
'create_function' => null, | ||
'exec' => null, | ||
'md5' => 'improved hash functions (SHA-256, SHA-512 etc.)', | ||
'passthru' => null, | ||
'pcntl_exec' => null, | ||
'popen' => null, | ||
'proc_open' => null, | ||
'serialize' => 'json_encode', | ||
'shell_exec' => null, | ||
'system' => null, | ||
'unserialize' => 'json_decode', | ||
]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
assert($a === true); | ||
|
||
exec('echo 1;'); | ||
|
||
passthru('echo 1;'); | ||
|
||
shell_exec('echo 1;'); | ||
|
||
system('echo 1;'); | ||
|
||
md5($text); | ||
|
||
serialize([]); | ||
|
||
unserialize(''); | ||
|
||
popen('echo 1;'); | ||
|
||
proc_open('echo 1;'); | ||
|
||
create_function('args', 'code'); | ||
|
||
pcntl_exec('path/goes/here'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento2\Tests\Security; | ||
|
||
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; | ||
|
||
/** | ||
* Class InsecureFunctionUnitTest | ||
*/ | ||
class InsecureFunctionUnitTest extends AbstractSniffUnitTest | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getErrorList() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getWarningList() | ||
{ | ||
return [ | ||
3 => 1, | ||
5 => 1, | ||
7 => 1, | ||
9 => 1, | ||
11 => 1, | ||
13 => 1, | ||
15 => 1, | ||
17 => 1, | ||
19 => 1, | ||
21 => 1, | ||
23 => 1, | ||
25 => 1, | ||
]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please validate the list against https://stackoverflow.com/questions/3115559/exploitable-php-functions and ask security team to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.