-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add a new requirement function to disable dangerous functions #23141
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
base: 11.0/bugfixes
Are you sure you want to change the base?
Changes from all commits
0a472ae
e4c7fb6
bd27cbb
9e8b882
eef5e20
82cec5a
de13d25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,147 @@ | ||||||
| <?php | ||||||
|
|
||||||
| /** | ||||||
| * --------------------------------------------------------------------- | ||||||
| * | ||||||
| * GLPI - Gestionnaire Libre de Parc Informatique | ||||||
| * | ||||||
| * http://glpi-project.org | ||||||
| * | ||||||
| * @copyright 2015-2026 Teclib' and contributors. | ||||||
| * @licence https://www.gnu.org/licenses/gpl-3.0.html | ||||||
| * | ||||||
| * --------------------------------------------------------------------- | ||||||
| * | ||||||
| * LICENSE | ||||||
| * | ||||||
| * This file is part of GLPI. | ||||||
| * | ||||||
| * This program is free software: you can redistribute it and/or modify | ||||||
| * it under the terms of the GNU General Public License as published by | ||||||
| * the Free Software Foundation, either version 3 of the License, or | ||||||
| * (at your option) any later version. | ||||||
| * | ||||||
| * This program is distributed in the hope that it will be useful, | ||||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
| * GNU General Public License for more details. | ||||||
| * | ||||||
| * You should have received a copy of the GNU General Public License | ||||||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||||
| * | ||||||
| * --------------------------------------------------------------------- | ||||||
| */ | ||||||
|
|
||||||
| namespace Glpi\System\Requirement; | ||||||
|
|
||||||
| /** | ||||||
| * @since 10.0.3 | ||||||
| */ | ||||||
| class DangerousFunctionsSecurity extends AbstractRequirement | ||||||
| { | ||||||
| /** | ||||||
| * @var string[] | ||||||
| */ | ||||||
| protected array $dangerous_functions = [ | ||||||
| 'pcntl_alarm', | ||||||
| 'pcntl_fork', | ||||||
| 'pcntl_waitpid', | ||||||
| 'pcntl_wait', | ||||||
| 'pcntl_wifexited', | ||||||
| 'pcntl_wifstopped', | ||||||
| 'pcntl_wifsignaled', | ||||||
| 'pcntl_wifsignaled', | ||||||
| 'pcntl_wifcontinued', | ||||||
| 'pcntl_wexitstatus', | ||||||
| 'pcntl_wtermsig', | ||||||
| 'pcntl_wstopsig', | ||||||
| 'pcntl_get_last_error', | ||||||
| 'pcntl_strerror', | ||||||
| 'pcntl_sigprocmask', | ||||||
| 'pcntl_sigwaitinfo', | ||||||
| 'pcntl_sigtimedwait', | ||||||
| 'pcntl_exec', | ||||||
| 'pcntl_getpriority', | ||||||
| 'pcntl_setpriority', | ||||||
| 'posix_ctermid', | ||||||
| 'posix_getcwd', | ||||||
| 'posix_getegid', | ||||||
| 'posix_getgid', | ||||||
| 'posix_getgrgid', | ||||||
| 'posix_getgrnam', | ||||||
| 'posix_getgroups', | ||||||
| 'posix_getlogin', | ||||||
| 'posix_getpgid', | ||||||
| 'posix_getpgrp', | ||||||
| 'posix_getpid', | ||||||
| 'posix_getppid', | ||||||
| 'posix_getpwuid', | ||||||
| 'posix_getrlimit', | ||||||
| 'posix_getsid', | ||||||
| 'posix_getuid', | ||||||
| 'posix_isatty', | ||||||
| 'posix_kill', | ||||||
| 'posix_mkfifo', | ||||||
| 'posix_setegid', | ||||||
| 'posix_seteuid', | ||||||
| 'posix_setgid', | ||||||
| 'posix_setpgid', | ||||||
| 'posix_setsid', | ||||||
| 'posix_setuid', | ||||||
| 'posix_times', | ||||||
| 'posix_ttyname', | ||||||
| 'posix_uname', | ||||||
| 'socket_accept', | ||||||
| 'socket_bind', | ||||||
| 'socket_clear_error', | ||||||
| 'socket_close', | ||||||
| 'socket_connect', | ||||||
| 'socket_listen', | ||||||
| 'socket_create_listen', | ||||||
| 'socket_read', | ||||||
| 'socket_create_pair', | ||||||
|
Comment on lines
+94
to
+102
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we should block them. Socket could be use for example by plugin to interact with a realtime tool. |
||||||
| 'stream_socket_server', | ||||||
| 'proc_open', | ||||||
| 'proc_close', | ||||||
| 'proc_nice', | ||||||
| 'proc_terminate', | ||||||
| 'dl', | ||||||
| 'link', | ||||||
| 'highlight_file', | ||||||
| 'show_source', | ||||||
| 'diskfreespace', | ||||||
| 'disk_free_space', | ||||||
| 'getmyuid', | ||||||
| 'popen', | ||||||
| 'escapeshellcmd', | ||||||
| 'symlink', | ||||||
| 'shell_exec', | ||||||
| 'exec', | ||||||
| 'system', | ||||||
| 'passthru', | ||||||
| ]; | ||||||
|
|
||||||
| public function __construct() | ||||||
| { | ||||||
| parent::__construct( | ||||||
| __('Security configuration for dangerous functions'), | ||||||
| __('Ensure dangerous functions are disabled.'), | ||||||
| true, | ||||||
| true, | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| protected function check() | ||||||
| { | ||||||
| $enabled_functions = []; | ||||||
| foreach ($this->dangerous_functions as $function) { | ||||||
| if (function_exists($function)) { | ||||||
| $enabled_functions[] = $function; | ||||||
| } | ||||||
| } | ||||||
orthagh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| $this->validation_messages[] = sprintf( | ||||||
| __('Functions "%s" are enabled. Please disable them in php.ini (see disable_functions directive) to avoid security risks.'), | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be disabled either from the
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this one. It's clearer for people that don't know how to do it and for other we probably don't have to explain |
||||||
| implode(', ', $enabled_functions) | ||||||
| ); | ||||||
| } | ||||||
orthagh marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it could rely on
get_defined_functions()+preg_grep()to get allpcntl/posixfunctions. It could permit to be sure that no function is forgotten and any new function introduced in the future would be detected.