Issues (94)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Commands/AdminCommand.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the PhpBotFramework.
5
 *
6
 * PhpBotFramework is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, version 3.
9
 *
10
 * PhpBotFramework is distributed in the hope that it will be useful, but
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public License
16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace PhpBotFramework\Commands;
20
21
/**
22
 * \addtogroup Commands
23
 * @{
24
 */
25
26
/** \class AdminCommand
27
 */
28
class AdminCommand extends MessageCommand
29
{
30
    /** @} */
31
32
    public static $type = 'message';
33
34
    public static $object_class = 'PhpBotFramework\Entities\Message';
35
36
    public static $priority = 1;
37
38
    private $command;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
39
40
    private $length;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
41
42
    /**
43
     * \brief Registers commands that can be triggered only by administrators.
44
     * \details It works like <code>MessageCommand</code> but it requires a
45
     * third argument: the list of Telegram IDs which represents the users
46
     * that can execute the command.
47
     *
48
     *     $start_command = new PhpBotFramework\Commands\AdminCommand("getusers",
49
     *         function ($bot, $message) {
50
     *             $bot->sendMessage("Hello, folks!");
51
     *         },
52
     *     array(3299130043, -439991220, 12221004));
53
     *
54
     * @param string $command The command that will trigger this function (e.g. start)
55
     * @param callable $script The function that will be triggered by a command.
56
     * @param array $ids The users who can execute the command.
57
     * Must take an object(the bot) and an array(the message received).
58
     */
59
    public function __construct(string $command, callable $script, array $ids)
60
    {
61
        $this->command = "/$command";
62
        $this->length = strlen($command) + 1;
63
        $this->script = $script;
64
65
        $this->ids = $ids;
0 ignored issues
show
The property ids does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
66
    }
67
68
    /**
69
     * @internal
70
     * \brief Process a message checking if it trigger any MessageCommand.
71
     * @param string $message Message to process.
72
     * @return bool True if the message trigger any command.
73
     */
74
    public function checkCommand(array $message) : bool
75
    {
76
        // If the message contains a bot command at the start
77
        $message_is_command = (isset($message['entities']) && $message['entities'][0]['type'] === 'bot_command') ? true : false;
78
79
        // If we found a valid command (check first lenght, then use strpos)
80
        if ($message_is_command && $this->length == $message['entities'][0]['length'] &&
81
            mb_strpos($this->command, $message['text'], $message['entities'][0]['offset']) !== false) {
82
          // Check that the user can execute the command
83
          if (in_array($message['from']['id'], $this->ids)) {
84
            return true;
85
          } else {
86
            return false;
87
          }
88
        }
89
90
        return false;
91
    }
92
93
}
94