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/Database/User.php (2 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\Database;
20
21
use PhpBotFramework\Exceptions\BotException;
22
23
/**
24
 * \addtogroup Modules
25
 * \brief Build your own bot using modules.
26
 * \details PhpBotFramework\Bot contains all modules and features of this framework but you're probabily not using all of them.
27
 * If you prefer keeping your bot lightweight you can extends PhpFrameworkBot\Core\BaseBot and use modules to add features.
28
 * The BaseBot class includes command handler (command types have to be included manually), api methods and file uploading.
29
 * @{
30
 */
31
32
/** \class User
33
 */
34
trait User
35
{
36
    /** @} */
37
38
    abstract protected function sanitizeUserTable();
39
40
    /** @internal
41
      * \brief PDO connection to the database. */
42
    public $pdo;
43
44
    /**
45
     * \addtogroup Database
46
     * @{
47
     */
48
49
    /**
50
     * \addtogroup Users-handle Users handling
51
     * \brief Handle bot users on the database.
52
     * @{
53
     */
54
55
    /** \brief Table contaning bot users data in the SQL database. */
56
    public $user_table = 'User';
57
58
    /** \brief Name of the column that represents the user id in the sql database */
59
    public $id_column = 'chat_id';
60
61
    /**
62
     * \brief Add a user to the database.
63
     * \details Add a user to the database in Bot::$user_table table and Bot::$id_column column using Bot::$pdo connection.
64
     * @param string|int $chat_id chat ID of the user to add.
65
     * @return bool True on success.
66
     */
67
    public function addUser($chat_id) : bool
68
    {
69
        if (!isset($this->pdo)) {
70
            throw new BotException("Database connection not set");
71
        }
72
73
        $this->sanitizeUserTable();
74
75
        // Create insertion query and initialize variable
76
        $query = "INSERT INTO $this->user_table ($this->id_column) VALUES (:chat_id)";
77
78
        $sth = $this->pdo->prepare($query);
79
        $sth->bindParam(':chat_id', $chat_id);
80
81
        try {
82
            $sth->execute();
83
            $success = true;
84
        } catch (\PDOException $e) {
85
            echo $e->getMessage();
86
87
            $success = false;
88
        }
89
90
        return $success;
91
    }
92
93
    /**
94
     * \brief Send a message to every user available on the database.
95
     * \details Send a message to all subscribed users, change Bot::$user_table and Bot::$id_column to match your database structure.
96
     * This method requires Bot::$pdo connection set.
97
     * All parameters are the same as CoreBot::sendMessage.
98
     * Because a limitation of Telegram Bot API the bot will have a delay after 20 messages sent in different chats.
99
     * @return int How many messages were sent.
100
     * @see CoreBot::sendMessage
101
     */
102
    public function broadcastMessage(
103
        string $text,
104
        string $reply_markup = null,
105
        string $parse_mode = 'HTML',
106
        bool $disable_web_preview = true,
107
        bool $disable_notification = false
108
    ) : int {
109
        if (!isset($this->pdo)) {
110
            throw new BotException("Database connection not set");
111
        }
112
113
        $this->sanitizeUserTable();
114
115
        $sth = $this->pdo->prepare("SELECT $this->id_column FROM $this->user_table");
116
117
        try {
118
            $sth->execute();
119
        } catch (\PDOException $e) {
120
            echo $e->getMessage();
121
        }
122
123
        // Iterate over all the row got
124
        while ($user = $sth->fetch()) {
125
            $user_data = $this->getChat($user[$this->id_column]);
0 ignored issues
show
It seems like getChat() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
126
127
            if ($user_data !== false) {
128
                // Change the chat_id for the next API method
129
                $this->bot->setChatID($user[$this->id_column]);
0 ignored issues
show
The property bot 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...
130
                $this->bot->sendMessage($text, $reply_markup, null, $parse_mode, $disable_web_preview, $disable_notification);
131
            }
132
        }
133
134
        return $sth->rowCount();
135
    }
136
137
    /** @} */
138
139
    /** @} */
140
}
141