Issues (43)

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.

controller/main.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
namespace florinp\messenger\controller;
4
5
use Symfony\Component\HttpFoundation\Response;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
8
use phpbb\request\request;
9
use phpbb\user;
10
use florinp\messenger\models\main_model;
11
use phpbb\notification\manager;
12
use florinp\messenger\libs\upload;
13
use florinp\messenger\libs\download;
14
15
class main
16
{
17
18
	protected $user;
19
	protected $model;
20
	protected $request;
21
	protected $notification_manager;
22
	protected $upload;
23
	protected $download;
24
25
	public function __construct(
26
		request $request,
27
		user $user,
28
		main_model $model,
29
		manager $notification_manager,
30
		upload $upload,
31
		download $download
32
	)
33
	{
34
		$this->request = $request;
35
		$this->user = $user;
36
		$this->model = $model;
37
		$this->notification_manager = $notification_manager;
38
		$this->upload = $upload;
39
		$this->download = $download;
40
	}
41
42
	public function handle()
43
	{
44
	}
45
46
	public function index()
47
	{
48
49
	}
50
51
	public function publish()
52
	{
53
		$text = $this->request->variable('text', '', true);
54
		$receiver_id = $this->request->variable('receiver_id', 0);
55
		$sender_id = $this->user->data['user_id'];
56
57
		$response = array();
58
		if ($receiver_id != 0 && trim($text) != '') {
59
			$text = htmlspecialchars($text);
60
			$text = str_replace(array("\n", "\r"), '', $text);
61
62
			$message = array(
63
				'sender_id' => $sender_id,
64
				'receiver_id' => $receiver_id,
65
				'text' => $text,
66
				'sentAt' => time()
67
			);
68
69
			if ($id = $this->model->sendMessage($message)) {
70
				$lastMessage = $this->model->getMessageById($id);
71
				$response = array('success' => true, 'message' => $lastMessage);
72
			} else {
73
				$response = array(
74
					'succes' => false,
75
					'error' => 'An error has been ocurred!'
76
				);
77
			}
78
		}
79
80
		return new JsonResponse($response, 200);
81
	}
82
83
	public function getFile($id)
84
	{
85
		$id = explode('_', $id)[1];
86
		$file = $this->model->getFileById($id);
87
		$this->download->setFile($file['file']);
88
		$this->download->sendDownload();
89
	}
90
91
	public function sendFile()
92
	{
93
		$receiver_id = $this->request->variable('receiver_id', 0);
94
		$sender_id = $this->user->data['user_id'];
95
96
		$response = array();
97
		$file = $this->request->file('file');
98
		if ($receiver_id != 0 && !empty($file)) {
99
			if ($file['error'] == 0) {
100
				$this->upload->file($file);
101
				$this->upload->set_allowed_mime_types(array(
102
					'image/gif',
103
					'image/jpeg',
104
					'image/png',
105
					'application/pdf',
106
					'application/x-rar-compressed',
107
					'application/zip',
108
					'application/x-7z-compressed',
109
					'text/plain'
110
				));
111
				$results = $this->upload->upload();
112
				if (isset($results['errors']) && count($results['errors'])) {
113
					$response = array(
114
						'success' => false,
115
						'errors' => $results['errors']
116
					);
117
				} else {
118
					$data = array(
119
						'sender_id' => $sender_id,
120
						'receiver_id' => $receiver_id,
121
						'fileName' => $results['original_filename'],
122
						'file' => $results['filename'],
123
						'type' => $results['mime'],
124
					);
125
					if ($id = $this->model->sendFile($data)) {
126
						$lastFile = $this->model->getFileById($id);
127
						$response = array(
128
							'success' => true,
129
							'file' => $lastFile
130
						);
131
					} else {
132
						$response = array(
133
							'succes' => false,
134
							'error' => 'An error has been ocurred!'
135
						);
136
					}
137
				}
138
			} else {
139
				$response = array(
140
					'succes' => false,
141
					'error' => $file['error']
142
				);
143
			}
144
		}
145
146
		return new JsonResponse($response, 200);
147
	}
148
149 View Code Duplication
	public function load()
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...
150
	{
151
		$friend_id = $this->request->variable('friend_id', 0);
152
153
		if ($friend_id > 0) {
154
			$messages = $this->model->getMessages($friend_id);
155
			return new JsonResponse($messages, 200);
156
		}
157
		return new JsonResponse(array('success' => false, 'error' => 'The request is invalid'), 200);
158
	}
159
160 View Code Duplication
	public function updateMessages()
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...
161
	{
162
		$friend_id = $this->request->variable('friend_id', 0);
163
		if ($friend_id > 0) {
164
			$newVal = $this->model->updateMessagesStatus($friend_id);
165
			return new JsonResponse(array('success' => true, 'newVal' => $newVal), 200);
166
		}
167
		return new JsonResponse(array('success' => false), 200);
168
	}
169
170 View Code Duplication
	public function checkForNewMessages()
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...
171
	{
172
		$friend_id = $this->request->variable('friend_id', 0);
173
		if ($friend_id > 0) {
174
			$messages = $this->model->getInboxFromId($friend_id);
175
			return new JsonResponse(array('success' => true, 'messages' => $messages), 200);
176
		}
177
		return new JsonResponse(array('success' => false), 200);
178
	}
179
180
	public function getFriends()
181
	{
182
		$friends = $this->model->getFriends();
183
		$friends_online = array_filter($friends, function($friend) {
184
			return $friend['user_status'] != 0;
185
		});
186
187
		$response = array(
188
			'friends_online' => count($friends_online),
189
			'friends_list' => $friends
190
		);
191
192
		return new JsonResponse($response, 200);
193
	}
194
195
	public function getEmoticons()
196
	{
197
		$response = array();
198
		return new JsonResponse($response, 200);
199
	}
200
201
}
202