Issues (1191)

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.

php/DatabaseConnect.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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 3 and the first side effect is on line 14.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
class DatabaseConnect extends mysqli
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
 // The database connection
6
	public function __construct()
7
	{
8
		$config = parse_ini_file('config/config.ini.php'); 
9
		
10
		parent::__construct($config['host'], $config['username'], $config['password'], $config['dbname']);
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class mysqli as the method __construct() does only exist in the following sub-classes of mysqli: DatabaseConnect. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
11
	}
12
13
}
14
$db = new DatabaseConnect();
15
16
if($db->connect_errno == 1203)  // 1203 == ER_TOO_MANY_USER_CONNECTIONS (mysqld_error.h)
17
{
18
	error_log('ER_TOO_MANY_USER_CONNECTIONS');
19
	sleep(1);
20
	header('location: '.$_SERVER['PHP_SELF']);
21
}
22
23
if ($db->connect_errno)
24
{
25
	error_log('Sorry, die Verbindung zu unserem 
26
        Server ist hops gegangen. Wegen '. $db -> connect_error);
27
	echo 'Sorry, die Verbindung zu unserem 
28
        Server ist hops gegangen. Wegen '. $db -> connect_error;
29
}
30
31
32
/* Uncomment if you start first time
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
$query = "CREATE TABLE IF NOT EXISTS `accounts` (
34
			 `id` int(11) unsigned NOT NULL auto_increment,
35
			 `access_token` varchar(55) NOT NULL default '',
36
			 `refresh_token` varchar(55) NOT NULL default '',
37
			 `token_type` varchar(55) NOT NULL default 'bearer',
38
			 `expires_in` INT NOT NULL,
39
			 `expiration_date` INT NOT NULL,
40
			 `device_uid` varchar(255) NOT NULL default '',
41
			 `client_id` varchar(255) NOT NULL default '81e8a76e-1e02-4d17-9ba0-8a7020261b26',
42
			 `distinct_id` varchar(255) NOT NULL default '',
43
			 `city` varchar(100) default '',
44
			 `country` varchar(10) default 'DE',
45
			 `loc_accuracy` varchar(50) default '0.0',
46
			 `lat` varchar(255) default '',
47
			 `lng` varchar(255) default '',
48
			 `name` varchar(100) default '',
49
			 `X-Client-Type` varchar(50) NOT NULL default 'android_4.24.2',
50
			 `User-Agent` varchar(150) NOT NULL default 'Jodel/4.4.9 Dalvik/2.1.0 (Linux; U; Android 5.1.1; )',
51
			 `X-Api-Version` varchar(10) NOT NULL default '0.2',
52
			 PRIMARY KEY  (`id`)
53
			 ) DEFAULT CHARSET=utf8";
54
$query2 = "CREATE TABLE IF NOT EXISTS `votes` (
55
			 `id` int(11) unsigned NOT NULL auto_increment,
56
			 `device_uid` varchar(255) NOT NULL,
57
			 `postId` varchar(255) NOT NULL,
58
			 `type` varchar(255) NOT NULL,
59
			 PRIMARY KEY  (`id`)
60
			 ) DEFAULT CHARSET=utf8";
61
62
$query3	 = "CREATE TABLE IF NOT EXISTS `users` (
63
			 `id` int(11) unsigned NOT NULL auto_increment,
64
			 `device_uid` varchar(255) NOT NULL,
65
			 `rights` varchar(255) NOT NULL,
66
			 `user_token` varchar(255) NOT NULL,
67
			 `remaining_votes` INT NOT NULL,
68
			 PRIMARY KEY  (`id`)
69
			 ) DEFAULT CHARSET=utf8";
70
71
$queryCitys	 = "CREATE TABLE IF NOT EXISTS `citys` (
72
			 `id` int(11) unsigned NOT NULL auto_increment,
73
			 `name` varchar(255) NOT NULL,
74
			 `lat` varchar(255) NOT NULL,
75
			 `lng` varchar(255) NOT NULL,
76
			 `country` INT NOT NULL,
77
			 PRIMARY KEY  (`id`)
78
			 ) DEFAULT CHARSET=utf8";
79
		 
80
  if(!$db->query($query) || !$db->query($query2) || !$db->query($query3) || !$db->query($queryCitys))
81
  {
82
    throw new Exception($db->error($mysqli));
83
  }
84
*/