Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbid unserialize() method. #52

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree that we should avoid serialize and unserialize entirely, it might be nice to let people know that unserialize_object() is the Moodle-provided alternative to unserialize.

Suggested change
'unserialize' => null,
'unserialize' => 'unserialize_object',

];
}
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);