Issues (90)

Security Analysis    not enabled

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/Conversation.php (4 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
 * Conversation Class Doc Comment
4
 *
5
 * PHP version 5
6
 *
7
 * @category PHP
8
 * @package  OpenChat
9
 * @author   Ankit Jain <[email protected]>
10
 * @license  The MIT License (MIT)
11
 * @link     https://github.com/ankitjain28may/openchat
12
 */
13
namespace ChatApp;
14
15
require_once dirname(__DIR__).'/vendor/autoload.php';
16
use ChatApp\Time;
17
use ChatApp\User;
18
use mysqli;
19
use Dotenv\Dotenv;
20
$dotenv = new Dotenv(dirname(__DIR__));
21
$dotenv->load();
22
23
/**
24
 * To Return the Conversation Data between users
25
 *
26
 * @category PHP
27
 * @package  OpenChat
28
 * @author   Ankit Jain <[email protected]>
29
 * @license  The MIT License (MIT)
30
 * @link     https://github.com/ankitjain28may/openchat
31
 */
32
class Conversation
33
{
34
    /*
35
    |--------------------------------------------------------------------------
36
    | Conversation Class
37
    |--------------------------------------------------------------------------
38
    |
39
    | To Return the Conversation Data between users.
40
    |
41
    */
42
43
    protected $connect;
44
    protected $array;
45
    protected $obTime;
46
    protected $obUser;
47
48
    /**
49
     * Create a new class instance.
50
     *
51
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
52
     */
53 View Code Duplication
    public function __construct()
0 ignored issues
show
This method seems to be duplicated in 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...
54
    {
55
        $this->connect = new mysqli(
56
            getenv('DB_HOST'),
57
            getenv('DB_USER'),
58
            getenv('DB_PASSWORD'),
59
            getenv('DB_NAME')
60
        );
61
        $this->obTime = new Time();
62
        $this->obUser = new User();
63
        $this->array = array();
64
    }
65
66
    /**
67
     * Fetch data from DB and show to user.
68
     *
69
     * @param string  $msg  To store message
70
     * @param boolean $para To store True/False
71
     *
72
     * @return string
73
     */
74
    public function conversationLoad($msg, $para)
75
    {
76
        $msg = json_decode($msg);
77
        if (!empty($msg)) {
78
            $userId = $msg->userId;
79
            $add_load = 0;
80
            $details = $msg->details;
81
            $load = $msg->load;
82
83
            if ($para == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
84
                $details = convert_uudecode(hex2bin($details));
85
            }
86
            $fetch = $this->obUser->userDetails($details, $para);
0 ignored issues
show
$para is of type boolean, but the function expects a object<ChatApp\boollen>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
87
88
            if ($fetch != null) {
89
                $login_id = (int)$fetch['login_id'];
90
91
                // Unique Identifier
92
                if ($login_id > $userId) {
93
                    $identifier = $userId.':'.$login_id;
94
                } else {
95
                    $identifier = $login_id.':'.$userId;
96
                }
97
98
                $query = "SELECT total_messages from total_message
99
                            where identifier = '$identifier'";
100
                if ($result = $this->connect->query($query)) {
101
                    if ($result->num_rows > 0) {
102
                        $total = $result->fetch_assoc();
103
                        $total = $total['total_messages'];
104
                        if ($total - $load > 0) {
105
                            if ($total - $load > 10) {
106
                                $add_load = $load + 10;
107
                            } else {
108
                                $add_load = $total;
109
                            }
110
                        }
111
                    }
112
                }
113
114
                $query = "SELECT message, time, sent_by FROM messages WHERE
115
                            identifier_message_number = '$identifier'
116
                            ORDER BY id DESC limit ".$load;
117
118
                if ($result = $this->connect->query($query)) {
119
                    if ($result->num_rows > 0) {
120
                        while ($row = $result->fetch_assoc()) {
121
                            $row['time'] = $this->obTime->timeConversion(
122
                                $row['time']
123
                            );
124
                            $row = array_merge($row, ['start' => $userId]);
125
                            $this->array = array_merge($this->array, [$row]);
126
                        }
127
128
                        $this->array = array_merge(
129
                            [[
130
                            'name' => $fetch['name'],
131
                            'username' => $fetch['username'],
132
                            'id' => bin2hex(convert_uuencode($fetch['login_id'])),
133
                            'load' => $add_load,
134
                            'login_status' => $fetch['login_status'],
135
                            'type' => 1
136
                            ]],
137
                            $this->array
138
                        );
139
                        return json_encode($this->array);
140
                    } else {
141
                        return json_encode(
142
                            [[
143
                            'name' => $fetch['name'],
144
                            'username' => $fetch['username'],
145
                            'id' => bin2hex(convert_uuencode($fetch['login_id'])),
146
                            'login_status' => $fetch['login_status'],
147
                            'type' => 0
148
                            ]]
149
                        );
150
                    }
151
                }
152
                return "Query Failed";
153
            }
154
            return "Query Failed";
155
        }
156
        return "Empty";
157
    }
158
}
159