Issues (158)

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.

lib/och/db/usermapper.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
 * Copyright (c) 2014, Tobia De Koninck hey--at--ledfan.be
4
 * This file is licensed under the AGPL version 3 or later.
5
 * See the COPYING file.
6
 */
7
8
namespace OCA\Chat\OCH\Db;
9
10
use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureFederationsSynchronizer;
11
use \OCP\AppFramework\Db\Mapper;
12
use \OCP\IDb;
13
use \OCP\AppFramework\Db\Entity;
14
use \OCP\AppFramework\Db\DoesNotExistException;
15
16
class UserMapper extends Mapper {
17
	
18
	private $userOnlineTable = '*PREFIX*chat_och_users_online';
0 ignored issues
show
The property $userOnlineTable is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
19
20
	public function __construct(IDb $api) {
21
		parent::__construct($api, 'chat_och_users_in_conversation');
22
		$this->table = '*PREFIX*chat_och_users_in_conversation';
23
	}
24
25
	public function findSessionsByConversation($conversationId){
26
		$sql = <<<SQL
27
			SELECT
28
				$this->table.user,
29
				$this->userOnlineTable.session_id,
30
				$this->table.conversation_id,
31
				$this->table.joined,
32
				$this->userOnlineTable.id
33
			FROM
34
				$this->table
35
			INNER JOIN
36
				$this->userOnlineTable
37
			ON
38
				$this->table.user = $this->userOnlineTable.user
39
			AND
40
				$this->table.conversation_id = ?
41
SQL;
42
		$result = $this->findEntities($sql, array($conversationId));
43
		return $result;
44
	}
45
46
	public function findByUser($user){
47
		$sql = <<<SQL
48
			SELECT
49
				*
50
			FROM
51
				$this->table
52
			WHERE
53
				`user` = ?
54
SQL;
55
		$result = $this->findEntities($sql, array($user));
56
		return $result;
57
	}
58
	
59
	 public function findConvsIdByUser($user){
60
		$sql = 'SELECT conversation_id FROM `' . $this->getTableName() . '` ' .
61
				'WHERE `user` = ? ';
62
63
		$result = $this->execute($sql, array($user));
64
65
		$ids = array();
66
		while($row = $result->fetch()){
67
			array_push($ids, $row['conversation_id']);
68
		}
69
70
		$ids = array_unique($ids);
71
		return $ids;
72
	}
73
		
74
75
	public function findUsersInConv($id){
76
		$sql = 'SELECT `user` FROM `' . $this->getTableName() . '` ' .
77
				'WHERE `conversation_id` = ? ';
78
79
		$result = $this->execute($sql, array($id));
80
81
		$users = array();
82
		while($row = $result->fetch()){
83
			array_push($users, $row['user']);
84
		}
85
86
		$users = array_unique($users);
87
		return $users;
88
	}
89
90
	public function insertUnique(Entity $entity){
91
		// First check $entity is already in DB
92
		$sql = <<<SQL
93
			SELECT
94
				`user`
95
			FROM
96
				`*PREFIX*chat_och_users_in_conversation`
97
			WHERE
98
				`user` = ?
99
			AND
100
				`conversation_id` = ?
101
SQL;
102
		try {
103
			$result = $this->findOneQuery($sql, array($entity->getUser(), $entity->getConversationId()));
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...
104
			// The user already joined the conv -> nothing to do
105
		} catch (\Exception $exception) {
106
			// The user isn't in this conversation -> add it
107
			$sql = <<<SQL
108
			INSERT
109
			INTO `*PREFIX*chat_och_users_in_conversation`
110
			(
111
				`user`,
112
				`conversation_id`,
113
				`joined`
114
			) VALUES (
115
				?,
116
				?,
117
				?
118
			)
119
SQL;
120
			$this->execute($sql, array(
121
				$entity->getUser(),
122
				$entity->getConversationId(),
123
				$entity->getJoined()
124
			));
125
		}
126
	}
127
128
	public function findAll(){
129
		$sql = 'SELECT * FROM `' . $this->getTableName() . '`';
130
		return $this->findEntities($sql, array());
131
	}
132
133
}