Skip to content

Commit

Permalink
Forbid unserialize() method.
Browse files Browse the repository at this point in the history
Can lead to code execution exploits if not used properly with
user supplied data. There are better methods of data exchange.
  • Loading branch information
paulholden committed Nov 27, 2023
1 parent aea4999 commit 3a31c65
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 1 addition & 2 deletions moodle/Sniffs/PHP/ForbiddenFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
// phpcs:disable moodle.NamingConventions

use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff as GenericForbiddenFunctionsSniff;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;

/**
* Sniff for debugging and other functions that we don't want used in finished code.
Expand Down Expand Up @@ -65,5 +63,6 @@ class ForbiddenFunctionsSniff extends GenericForbiddenFunctionsSniff {
'print_object' => null,
// Dangerous functions. From coding style.
'extract' => null,
'unserialize' => null,
];
}
1 change: 1 addition & 0 deletions moodle/Tests/MoodleStandardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ public function test_moodle_php_forbiddenfunctions() {
15 => 0,
16 => 0,
17 => 0,
20 => 'function unserialize() is forbidden',
));
$this->set_warnings(array());

Expand Down
3 changes: 2 additions & 1 deletion moodle/Tests/fixtures/moodle_php_forbiddenfunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
a: echo 'Goto labels, oh my!'
b:
echo 'More goto labels, re-oh my!'
// Fair enough.
// Fair enough. Unserialize can be dangerous too, better catch it.
$a = unserialize($b);

0 comments on commit 3a31c65

Please sign in to comment.