Skip to content

Commit e8d0916

Browse files
committed
[Enhancement] DiscouragedFunction rule improvement
1 parent f53758d commit e8d0916

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
4444
'^chroot$' => null,
4545
'^com_load_typelib$' => null,
4646
'^copy$' => null,
47-
'^create_function$' => null,
4847
'^curl_.*$' => null,
4948
'^cyrus_connect$' => null,
5049
'^dba_.*$' => null,
@@ -104,10 +103,8 @@ class DiscouragedFunctionSniff extends ForbiddenFunctionsSniff
104103
'^pfsockopen$' => null,
105104
'^pg_.*$' => null,
106105
'^php_check_syntax$' => null,
107-
'^popen$' => null,
108106
'^print_r$' => null,
109107
'^printf$' => null,
110-
'^proc_open$' => null,
111108
'^putenv$' => null,
112109
'^readfile$' => null,
113110
'^readgzfile$' => null,

Magento2/Sniffs/Security/InsecureFunctionSniff.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento2\Sniffs\Functions;
6+
namespace Magento2\Sniffs\Security;
77

88
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
99

@@ -26,12 +26,16 @@ class InsecureFunctionSniff extends ForbiddenFunctionsSniff
2626
*/
2727
public $forbiddenFunctions = [
2828
'assert' => null,
29+
'create_function' => null,
2930
'exec' => null,
31+
'md5' => 'improved hash functions (SHA-256, SHA-512 etc.)',
3032
'passthru' => null,
33+
'pcntl_exec' => null,
34+
'popen' => null,
35+
'proc_open' => null,
36+
'serialize' => 'json_encode',
3137
'shell_exec' => null,
3238
'system' => null,
33-
'md5' => 'improved hash functions (SHA-256, SHA-512 etc.)',
34-
'serialize' => 'json_encode',
3539
'unserialize' => 'json_decode',
3640
];
3741
}

Magento2/Tests/Functions/DiscouragedFunctionUnitTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function getWarningList()
3939
28 => 1,
4040
30 => 1,
4141
32 => 1,
42-
34 => 1,
4342
36 => 1,
4443
37 => 1,
4544
38 => 1,
@@ -128,10 +127,8 @@ public function getWarningList()
128127
184 => 1,
129128
185 => 1,
130129
187 => 1,
131-
189 => 1,
132130
191 => 1,
133131
193 => 1,
134-
195 => 1,
135132
197 => 1,
136133
199 => 1,
137134
201 => 1,

Magento2/Tests/Security/InsecureFunctionUnitTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,10 @@ serialize([]);
1616

1717
unserialize('');
1818

19+
popen('echo 1;');
20+
21+
proc_open('echo 1;');
22+
23+
create_function('args', 'code');
24+
25+
pcntl_exec('path/goes/here');

Magento2/Tests/Security/InsecureFunctionUnitTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento2\Tests\Functions;
6+
namespace Magento2\Tests\Security;
77

88
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
99

@@ -34,6 +34,10 @@ public function getWarningList()
3434
13 => 1,
3535
15 => 1,
3636
17 => 1,
37+
19 => 1,
38+
21 => 1,
39+
23 => 1,
40+
25 => 1,
3741
];
3842
}
3943
}

Magento2/ruleset.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<rule ref="Magento2.Security.Superglobal.SuperglobalUsageError">
6060
<severity>10</severity>
6161
<type>error</type>
62+
<exclude-pattern>*/lib/*</exclude-pattern>
6263
</rule>
6364
<rule ref="Magento2.Strings.ExecutableRegEx">
6465
<severity>10</severity>
@@ -86,6 +87,7 @@
8687
<rule ref="Magento2.PHP.DateTime">
8788
<severity>9</severity>
8889
<type>warning</type>
90+
<exclude-pattern>*/lib/*</exclude-pattern>
8991
</rule>
9092
<rule ref="Magento2.Security.InsecureFunction">
9193
<severity>9</severity>
@@ -94,6 +96,7 @@
9496
<rule ref="Magento2.Security.Superglobal.SuperglobalUsageWarning">
9597
<severity>9</severity>
9698
<type>warning</type>
99+
<exclude-pattern>*/lib/*</exclude-pattern>
97100
</rule>
98101
<rule ref="Magento2.Security.XssTemplate">
99102
<include-pattern>*.phtml</include-pattern>
@@ -137,6 +140,7 @@
137140
<severity>8</severity>
138141
<type>warning</type>
139142
<exclude-pattern>*/Test/*</exclude-pattern>
143+
<exclude-pattern>*/Setup/*</exclude-pattern>
140144
</rule>
141145
<rule ref="Magento2.Files.LineLength">
142146
<severity>8</severity>

0 commit comments

Comments
 (0)