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.

controller/och/apicontroller.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
 * 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\Controller\OCH;
9
10
use \OCA\Chat\OCH\Responses\Success;
11
use \OCA\Chat\OCH\Responses\Error;
12
use \OCA\Chat\OCH\Exceptions\RequestDataInvalid;
13
use \OCP\AppFramework\Http\JSONResponse;
14
use \OCP\AppFramework\Controller;
15
use \OCP\IRequest;
16
use \OCA\Chat\Db\DBException;
17
use \OCA\Chat\App\Chat;
18
use \OCA\Chat\App\Container;
19
20
class ApiController extends Controller {
21
22
	/**
23
	 * Error codes used by the API
24
	 */
25
	const INVALID_HTTP_TYPE = 0;
26
	const COMMAND_NOT_FOUND = 1;
27
	const PUSH_ACTION_NOT_FOUND = 2;
28
	const DATA_ACTION_NOT_FOUND = 3;
29
	const NO_SESSION_ID = 6;
30
	const USER_NOT_EQUAL_TO_OC_USER = 7;
31
	const NO_TIMESTAMP = 8;
32
	const NO_CONV_ID = 9;
33
	const NO_USER_TO_INVITE = 10;
34
	const USER_EQUAL_TO_USER_TO_INVITE = 11;
35
	const USER_TO_INVITE_NOT_OC_USER = 12;
36
	const NO_CHAT_MSG = 13;
37
	const NO_USER = 14;
38
    const NOT_OWNER_OF_FILE =15;
39
	const TIME_EXCEEDED = 16;
40
41
	public function __construct($appName, IRequest $request,  Chat $app, Container $container){
42
		parent::__construct($appName, $request);
43
		$this->app = $app;
44
		$this->container = $container;
45
	}
46
47
	/**
48
	 * Routes the API Request to the correct Class
49
	 * There are 3 types: command, data and push
50
	 * @param string $type
51
	 * @param array $data
52
	 * @return JSONResponse
53
	 * @NoAdminRequired
54
	 */
55
	public function route($type, $data){
56
		session_write_close();
57
		list($requestType, $action, $httpType) = explode("::", $type);
58
59
		if($httpType === "request"){
60
			if(!empty($data['session_id'])){
61
				if(!empty($data['user'])){
62
					if($data['user']['id'] === $this->app->getUserId()){
63
						try{
64
							switch($requestType){
65
								case "command":
66
									$possibleCommands = array('greet', 'join', 'invite', 'send_chat_msg', 'online', 'offline', 'start_conv', 'delete_init_conv', 'attach_file', 'remove_file');
67
									if(in_array($action, $possibleCommands)){
68
										$commandClass = $this->container->query($this->convertClassName($action) . 'Command');
69
										$commandClass->setRequestData($data);
70
										$data = $commandClass->execute();
71
										if($data){
72
											return new Success("command", $action, $data);
73
										} else {
74
											return new Success("command", $action);
75
										}
76
									} else {
77
										return new Error("command", $action, self::COMMAND_NOT_FOUND);
78
									}
79
									break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
80
								case "push":
81
									$possibleCommands = array('get', 'delete');
82
									if(in_array($action, $possibleCommands)){
83
										$pushClass = $this->container->query($this->convertClassName($action) . 'Push');
84
										$pushClass->setRequestData($data);
85
										return $pushClass->execute();
86
									} else {
87
										return new Error("push", $action, self::PUSH_ACTION_NOT_FOUND);
88
									}
89
									break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
90
								case "data":
91
									$possibleCommands = array('messages', 'get_users');
92
									if(in_array($action, $possibleCommands)){
93
										$dataClass = $this->container->query($this->convertClassName($action) . 'Data');
94
										$dataClass->setRequestData($data);
95
										$data = $dataClass->execute();
96
										if($data){
97
											return new Success("data", $action, $data);
98
										} else {
99
											return new Success("data", $action);
100
										}
101
									} else {
102
										return new Error("data", $action, self::DATA_ACTION_NOT_FOUND);
103
									}
104
									break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
105
							}
106
						}catch(DBException $e){
107
							return new Error($requestType, $action, "ERROR::DB::" . $e->getMessage());
108
						}
109
						catch(RequestDataInvalid $e){
110
							return new Error($requestType, $action, $e->getMessage());
111
						}
112
					} else {
113
						return new Error($requestType, $action, self::USER_NOT_EQUAL_TO_OC_USER);
114
					}
115
				} else {
116
					return new Error($requestType, $action,  self::NO_USER);
117
				}
118
			} else {
119
				return new Error($requestType, $action,  self::NO_SESSION_ID);
120
			}
121
		} else {
122
			return new Error($requestType, $action, self::INVALID_HTTP_TYPE);
123
		}
124
	}
125
126
	/**
127
	 * Helper function to transform the $action to a correct classname
128
	 * @param $class
129
	 * @return string
130
	 */
131
	private function convertClassName($class){
132
		$newClass = '';
133
		$parts = explode("_", $class);
134
		foreach($parts as $part){
135
			$newClass .= ucfirst($part);
136
		}
137
		return $newClass;
138
	}
139
}
140