Skip to content

Commit c800372

Browse files
authored
Whitelist functions as soon as they are used (#269)
1 parent a514ed6 commit c800372

19 files changed

+466
-29
lines changed

specs/const/const-declaration-with-global-whitelisting.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],

specs/const/const-declaration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => false,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],

specs/function/global-scope-global-func-with-single-level-use-statement-and-alias.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],
@@ -42,6 +42,28 @@
4242
PHP
4343
,
4444

45+
'Global function call imported with a use statement in the global scope with global functions whitelisted' => [
46+
'whitelist-global-functions' => true,
47+
'registered-functions' => [
48+
['main', 'Humbug\main'],
49+
],
50+
'payload' => <<<'PHP'
51+
<?php
52+
53+
use function main as foo;
54+
55+
foo();
56+
----
57+
<?php
58+
59+
namespace Humbug;
60+
61+
use function Humbug\main as foo;
62+
\Humbug\main();
63+
64+
PHP
65+
],
66+
4567
'Global FQ function call imported with a use statement in the global scope' => <<<'PHP'
4668
<?php
4769
@@ -58,4 +80,26 @@
5880

5981
PHP
6082
,
83+
84+
'Global FQ function call imported with a use statement in the global scope with global functions whitelisted' => [
85+
'whitelist-global-functions' => true,
86+
'registered-functions' => [
87+
['foo', 'Humbug\foo'],
88+
],
89+
'payload' => <<<'PHP'
90+
<?php
91+
92+
use function main as foo;
93+
94+
\foo();
95+
----
96+
<?php
97+
98+
namespace Humbug;
99+
100+
use function Humbug\main as foo;
101+
\Humbug\foo();
102+
103+
PHP
104+
],
61105
];

specs/function/global-scope-global-func-with-single-level-use-statement.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],
@@ -42,6 +42,28 @@
4242
PHP
4343
,
4444

45+
'Global function call imported with a use statement in the global scope with global functions whitelisted' => [
46+
'whitelist-global-functions' => true,
47+
'registered-functions' => [
48+
['main', 'Humbug\main'],
49+
],
50+
'payload' => <<<'PHP'
51+
<?php
52+
53+
use function main;
54+
55+
main();
56+
----
57+
<?php
58+
59+
namespace Humbug;
60+
61+
use function Humbug\main;
62+
\Humbug\main();
63+
64+
PHP
65+
],
66+
4567
'Global FQ function call imported with a use statement in the global scope' => <<<'PHP'
4668
<?php
4769
@@ -58,4 +80,26 @@
5880

5981
PHP
6082
,
83+
84+
'Global FQ function call imported with a use statement in the global scope with global functions whitelisted' => [
85+
'whitelist-global-functions' => true,
86+
'registered-functions' => [
87+
['main', 'Humbug\main'],
88+
],
89+
'payload' => <<<'PHP'
90+
<?php
91+
92+
use function main;
93+
94+
\main();
95+
----
96+
<?php
97+
98+
namespace Humbug;
99+
100+
use function Humbug\main;
101+
\Humbug\main();
102+
103+
PHP
104+
],
61105
];

specs/function/global-scope-global-func.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],

specs/function/global-scope-single-part-namespaced-func.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],
@@ -55,6 +55,9 @@
5555

5656
'Whitelisted namespaced function call' => [
5757
'whitelist' => ['PHPUnit\main'],
58+
'registered-functions' => [
59+
['PHPUnit\main', 'Humbug\PHPUnit\main'],
60+
],
5861
'payload' => <<<'PHP'
5962
<?php
6063
@@ -71,6 +74,9 @@
7174

7275
'FQ whitelisted namespaced function call' => [
7376
'whitelist' => ['PHPUnit\main'],
77+
'registered-functions' => [
78+
['PHPUnit\main', 'Humbug\PHPUnit\main'],
79+
],
7480
'payload' => <<<'PHP'
7581
<?php
7682

specs/function/namespace-global-func-with-single-level-use-statement-and-alias.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],

specs/function/namespace-global-func-with-single-level-use-statement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],

specs/function/namespace-global-func.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],

specs/function/namespace-global-scope-func.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'whitelist' => [],
2121
'whitelist-global-constants' => true,
2222
'whitelist-global-classes' => false,
23-
'whitelist-global-functions' => true,
23+
'whitelist-global-functions' => false,
2424
'registered-classes' => [],
2525
'registered-functions' => [],
2626
],

0 commit comments

Comments
 (0)