Issues (19)

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.

src/Connection.php (3 issues)

Labels
Severity

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 Ganga\Potato;
4
5
use PDO;
6
7
/**
8
 * Class to define connection to sqlite database;
9
 */
10
class Connection
11
{
12
    protected static $conn;
13
    public static $dbType;
14
    public static $dbName;
15
16
    /**
17
     * Constructor
18
     * Declare an instance of SQLite class
19
     */
20
    public function __construct($config)
21
    {
22
        if (! is_array($config)) {
23
            throw new PotatoException("Database Config must be an array");
24
        }
25
26
        if (! array_key_exists('type', $config) || empty($config['type'])) {
27
            throw new PotatoException("You must specify a database type in the config");
28
        }
29
30
        if (! array_key_exists('database', $config) || empty($config['database'])) {
31
            throw new PotatoException("You must provide a database in the config");
32
        }
33
34
        self::$dbName = $config['database'];
35
        self::$dbType = strtolower($config['type']);
36
37
        switch (self::$dbType) {
38
            case 'sqlite':
39
                self::$conn = $this->connectSQLite($config);
40
                break;
41
            case 'mssql':
42
                self::$conn = $this->connectMSSQL($config);
43
                break;
44
            default:
45
                self::$conn = $this->connectSQL($config);
46
        }
47
    }
48
49
    /**
50
     * Get an instance of the db connection
51
     * @return SQLite3 connection
52
     */
53
    public static function db()
54
    {
55
        self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
56
        return self::$conn;
57
    }
58
59
    public static function close()
60
    {
61
        self::$conn = null;
62
    }
63
64
    private function checkParam($config)
65
    {
66
        if (! array_key_exists('host', $config) || empty($config['host'])) {
67
            throw new PotatoException("You must provide a host to connect to database");
68
        }
69
70
        if (! array_key_exists('user', $config) || empty($config['user'])) {
71
            throw new PotatoException("You must provide a user for database");
72
        }
73
74
        if (! array_key_exists('password', $config)) {
75
            throw new PotatoException("You must provide a password for  database");
76
        }
77
    }
78
79
    public function connectSQLite($config)
80
    {
81
        try {
82
            $db =  new PDO("sqlite:".$config['database']);
83
        } catch (PDOException $e) {
0 ignored issues
show
The class Ganga\Potato\PDOException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
84
            throw new PotatoException($e->getMessage());
85
        }
86
87
        return $db;
88
    }
89
90
    public function connectMSSQL($config)
91
    {
92
        $this->checkParam($config);
93
94
        try {
95
            $db = new PDO("mssql:host=".$config['host'].";dbname=".$config['database'].", ".$config['user'].", ".$config['password']);
96
        } catch (PDOException $e) {
0 ignored issues
show
The class Ganga\Potato\PDOException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
97
            throw new PotatoException($e->getMessage());
98
        }
99
100
        return $db;
101
    }
102
103
    public function connectSQL($config)
104
    {
105
        $this->checkParam($config);
106
107
        try {
108
            $db = new PDO($config['type'].":host=".$config['host'].$this->checkPort($config).";dbname=".$config['database'], $config['user'], $config['password']);
109
        } catch (PDOException $e) {
0 ignored issues
show
The class Ganga\Potato\PDOException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
110
            throw new PotatoException($e->getMessage());
111
        }
112
113
        return $db;
114
    }
115
116
    /**
117
     * Check if PORT is provided in the database config
118
     * @param  array $config database configuration array
119
     * @return void
120
     */
121
    private function checkPort($config)
122
    {
123
        return array_key_exists('port', $config) ? ";port=".$config['port'] : '';
124
    }
125
}
126