Skip to content

Commit 4353592

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 9ec28ac commit 4353592

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

moodle/Sniffs/PHP/ForbiddenFunctionsSniff.php

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ public function test_moodle_php_forbiddenfunctions() {
443443
15 => 0,
444444
16 => 0,
445445
17 => 0,
446+
20 => 'function unserialize() is forbidden',
446447
));
447448
$this->set_warnings(array());
448449

moodle/Tests/fixtures/moodle_php_forbiddenfunctions.php

Lines changed: 2 additions & 1 deletion
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)