Issues (64)

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/ConversationDB.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
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot;
12
13
use Exception;
14
use Longman\TelegramBot\Exception\TelegramException;
15
use PDO;
16
17
class ConversationDB extends DB
18
{
19
    /**
20
     * Initilize conversation table
21
     */
22 9
    public static function initializeConversation()
23
    {
24 9
        if (!defined('TB_CONVERSATION')) {
25 1
            define('TB_CONVERSATION', self::$table_prefix . 'conversation');
26
        }
27 9
    }
28
29
    /**
30
     * Select a conversation from the DB
31
     *
32
     * @param int  $user_id
33
     * @param int  $chat_id
34
     * @param bool $limit
35
     *
36
     * @return array|bool
37
     * @throws \Longman\TelegramBot\Exception\TelegramException
38
     */
39 9
    public static function selectConversation($user_id, $chat_id, $limit = null)
40
    {
41 9
        if (!self::isDbConnected()) {
42
            return false;
43
        }
44
45
        try {
46 9
            $query = 'SELECT * FROM `' . TB_CONVERSATION . '` ';
47 9
            $query .= 'WHERE `status` = :status ';
48 9
            $query .= 'AND `chat_id` = :chat_id ';
49 9
            $query .= 'AND `user_id` = :user_id ';
50
51 9
            if (!is_null($limit)) {
52 9
                $query .= ' LIMIT :limit';
53
            }
54 9
            $sth = self::$pdo->prepare($query);
55
56 9
            $active = 'active';
57 9
            $sth->bindParam(':status', $active, PDO::PARAM_STR);
58 9
            $sth->bindParam(':user_id', $user_id, PDO::PARAM_INT);
59 9
            $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT);
60 9
            $sth->bindParam(':limit', $limit, PDO::PARAM_INT);
61 9
            $sth->execute();
62
63 9
            $results = $sth->fetchAll(PDO::FETCH_ASSOC);
64
        } catch (Exception $e) {
65
            throw new TelegramException($e->getMessage());
66
        }
67 9
        return $results;
68
    }
69
70
    /**
71
     * Insert the conversation in the database
72
     *
73
     * @param int    $user_id
74
     * @param int    $chat_id
75
     * @param string $command
76
     *
77
     * @return bool
78
     * @throws \Longman\TelegramBot\Exception\TelegramException
79
     */
80 6
    public static function insertConversation($user_id, $chat_id, $command)
81
    {
82 6
        if (!self::isDbConnected()) {
83
            return false;
84
        }
85
86
        try {
87 6
            $sth    = self::$pdo->prepare('INSERT INTO `' . TB_CONVERSATION . '`
88
                (
89
                `status`, `user_id`, `chat_id`, `command`, `notes`, `created_at`, `updated_at`
90
                )
91
                VALUES (
92
                :status, :user_id, :chat_id, :command, :notes, :date, :date
93
                )
94 6
               ');
95 6
            $active = 'active';
96 6
            $notes  = '[]';
97 6
            $created_at = self::getTimestamp();
98
99 6
            $sth->bindParam(':status', $active);
100 6
            $sth->bindParam(':command', $command);
101 6
            $sth->bindParam(':user_id', $user_id);
102 6
            $sth->bindParam(':chat_id', $chat_id);
103 6
            $sth->bindParam(':notes', $notes);
104 6
            $sth->bindParam(':date', $created_at);
105
106 6
            $status = $sth->execute();
107 1
        } catch (Exception $e) {
108 1
            throw new TelegramException($e->getMessage());
109
        }
110 5
        return $status;
111
    }
112
113
    /**
114
     * Update a specific conversation
115
     *
116
     * @param array $fields_values
117
     * @param array $where_fields_values
118
     *
119
     * @return bool
120
     */
121 3
    public static function updateConversation(array $fields_values, array $where_fields_values)
122
    {
123 3
        return self::update(TB_CONVERSATION, $fields_values, $where_fields_values);
124
    }
125
126
    /**
127
     * Update the conversation in the database
128
     *
129
     * @param string $table
130
     * @param array  $fields_values
131
     * @param array  $where_fields_values
132
     *
133
     * @todo This function is generic should be moved in DB.php
134
     *
135
     * @return bool
136
     * @throws \Longman\TelegramBot\Exception\TelegramException
137
     */
138 3
    public static function update($table, array $fields_values, array $where_fields_values)
139
    {
140 3
        if (!self::isDbConnected()) {
141
            return false;
142
        }
143
        //Auto update the field update_at
144 3
        $fields_values['updated_at'] = self::getTimestamp();
145
146
        //Values
147 3
        $update         = '';
148 3
        $tokens         = [];
149 3
        $tokens_counter = 0;
150 3
        $a              = 0;
151 3 View Code Duplication
        foreach ($fields_values as $field => $value) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152 3
            if ($a) {
153 3
                $update .= ', ';
154
            }
155 3
            ++$a;
156 3
            ++$tokens_counter;
157 3
            $update .= '`' . $field . '` = :' . $tokens_counter;
158 3
            $tokens[':' . $tokens_counter] = $value;
159
        }
160
161
        //Where
162 3
        $a     = 0;
163 3
        $where = '';
164 3 View Code Duplication
        foreach ($where_fields_values as $field => $value) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
165 3
            if ($a) {
166 2
                $where .= ' AND ';
167
            } else {
168 3
                ++$a;
169 3
                $where .= 'WHERE ';
170
            }
171 3
            ++$tokens_counter;
172 3
            $where .= '`' . $field . '`= :' . $tokens_counter;
173 3
            $tokens[':' . $tokens_counter] = $value;
174
        }
175
176 3
        $query = 'UPDATE `' . $table . '` SET ' . $update . ' ' . $where;
177
        try {
178 3
            $sth    = self::$pdo->prepare($query);
179 3
            $status = $sth->execute($tokens);
180
        } catch (Exception $e) {
181
            throw new TelegramException($e->getMessage());
182
        }
183 3
        return $status;
184
    }
185
}
186