Skip to content

Commit 3a31c65

Browse files
committed
Forbid unserialize() method.
Can lead to code execution exploits if not used properly with user supplied data. There are better methods of data exchange.
1 parent aea4999 commit 3a31c65

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

moodle/Sniffs/PHP/ForbiddenFunctionsSniff.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
// phpcs:disable moodle.NamingConventions
2020

2121
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff as GenericForbiddenFunctionsSniff;
22-
use PHP_CodeSniffer\Sniffs\Sniff;
23-
use PHP_CodeSniffer\Files\File;
2422

2523
/**
2624
* Sniff for debugging and other functions that we don't want used in finished code.
@@ -65,5 +63,6 @@ class ForbiddenFunctionsSniff extends GenericForbiddenFunctionsSniff {
6563
'print_object' => null,
6664
// Dangerous functions. From coding style.
6765
'extract' => null,
66+
'unserialize' => null,
6867
];
6968
}

moodle/Tests/MoodleStandardTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ public function test_moodle_php_forbiddenfunctions() {
470470
15 => 0,
471471
16 => 0,
472472
17 => 0,
473+
20 => 'function unserialize() is forbidden',
473474
));
474475
$this->set_warnings(array());
475476

moodle/Tests/fixtures/moodle_php_forbiddenfunctions.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
a: echo 'Goto labels, oh my!'
1717
b:
1818
echo 'More goto labels, re-oh my!'
19-
// Fair enough.
19+
// Fair enough. Unserialize can be dangerous too, better catch it.
20+
$a = unserialize($b);
2021

0 commit comments

Comments
 (0)