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/Reply.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
 * Reply 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
require_once dirname(__DIR__).'/vendor/autoload.php';
15
use mysqli;
16
use Dotenv\Dotenv;
17
$dotenv = new Dotenv(dirname(__DIR__));
18
$dotenv->load();
19
20
21
/**
22
 * Store Message in the Database
23
 *
24
 * @category PHP
25
 * @package  OpenChat
26
 * @author   Ankit Jain <[email protected]>
27
 * @license  The MIT License (MIT)
28
 * @link     https://github.com/ankitjain28may/openchat
29
 */
30
class Reply
31
{
32
    /*
33
    |--------------------------------------------------------------------------
34
    | Reply Class
35
    |--------------------------------------------------------------------------
36
    |
37
    | Store Message in the Database
38
    |
39
    */
40
41
    protected $connect;
42
43
    /**
44
     * Create a new class instance.
45
     *
46
     * @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...
47
     */
48 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...
49
    {
50
        $this->connect = new mysqli(
51
            getenv('DB_HOST'),
52
            getenv('DB_USER'),
53
            getenv('DB_PASSWORD'),
54
            getenv('DB_NAME')
55
        );
56
57
        date_default_timezone_set('Asia/Kolkata');
58
    }
59
60
    /**
61
     * Store Message in Db so as to send message to other members
62
     *
63
     * @param object $msg To store user id and massage
64
     *
65
     * @return string
66
     */
67
    public function replyTo($msg)
68
    {
69
        if (!empty($msg)) {
70
            // checks for the value send
71
            $userId = $msg->userId;
72
            // stores id of the person whom message is to be sent
73
            $receiverID = $msg->name;
74
            $identifier;
0 ignored issues
show
The variable $identifier seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
75
76
            if ($receiverID > $userId) {
77
                // geneate specific unique code to store messages
78
                $user1 = $userId;
79
                $user2 = $receiverID;
80
                $identifier = $userId.":".$receiverID;
81
            } else {
82
                $user1 = $receiverID;
83
                $user2 = $userId;
84
                $identifier = $receiverID.":".$userId;
85
            }
86
87
            // stores the message sent by the user.
88
            $reply = addslashes(trim($msg->reply));
89
            // current time
90
            $time = date("D d M Y H:i:s");
91
            // echo $time;
92
            // to sort the array on the basis of time
93
            $time_id = date("YmdHis");
94
95
            // the sender id must not be equal to current session id
96
            if ($reply != "" && $receiverID != $userId) {
97
                // check whether the receiver is authorized or registered
98
                $query = "SELECT * from login where login_id = '$receiverID'";
99
100
                $result = $this->connect->query($query);
101
                if ($result->num_rows > 0) {
102
                    // check whether he is sending message
103
                    // for the first time or he has sent messages before
104
                    $query = "SELECT * from total_message where
105
                                identifier = '$identifier'";
106
                    $result = $this->connect->query($query);
107
                    if ($result->num_rows > 0) {
108
                        // if he has sent messages before Update Total_Message Table
109
                        $query = "UPDATE total_message SET
110
                                total_messages = total_messages + 1,
111
                                time = '$time', unread = 1,
112
                                id = '$time_id' WHERE identifier = '$identifier'";
113
114
                        return $this->updateMessages(
115
                            $query, $identifier, $reply, $userId, $time
116
                        );
117
118
                    } else {
119
                        // if he sends message for the first time
120
                        // insert Details in Total_Message Table
121
                        $query = "INSERT into total_message values(
122
                            '$identifier', 1, '$user1', '$user2', 1,
123
                            '$time', '$time_id'
124
                        )";
125
                        return $this->updateMessages(
126
                            $query, $identifier, $reply, $userId, $time
127
                        );
128
                    }
129
                }
130
                // if he is unauthorized echo message is failed
131
                return "Invalid Authentication";
132
            }
133
        }
134
        return "Failed";
135
    }
136
137
    /**
138
     * To Store Message in DB Based on Identifier
139
     *
140
     * @param string $query      To store the query performed
141
     * @param string $identifier To store unique id
142
     * @param string $reply      To store message
143
     * @param string $userId     To store userid
144
     * @param string $time       To store time
145
     *
146
     * @return string
147
     */
148
    public function updateMessages($query, $identifier, $reply, $userId, $time)
149
    {
150
        if ($result = $this->connect->query($query)) {
0 ignored issues
show
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
151
            //insert message in db
152
            $query = "INSERT into messages values(
153
                '$identifier', '$reply', '$userId', '$time', null
154
            )";
155
            if ($this->connect->query($query)) {
156
                // if query is executed return true
157
                return "Messages is sent\n";
158
            }
159
            return "Message is failed\n";
160
        }
161
    }
162
163
164
}
165
166