Issues (1177)

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.

application/libraries/ClassLoader.php (1 issue)

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
/**
4
 * require_once APPPATH . 'libraries' . DIRECTORY_SEPARATOR . 'ClassLoader.php';
5
 * ClassLoader::getInstance()
6
 *     ->registerNamespacedPath(APPPATH)
7
 *     ->registerNamespacedPath(APPPATH . 'modules');
8
 *
9
 * @author ailok <[email protected]>
10
 *
11
 */
12
class ClassLoader
0 ignored issues
show
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
13
{
14
15
    const EXT = '.php';
16
    const DS = DIRECTORY_SEPARATOR;
17
18
    private static $instance;
19
20
    private $namespacedPaths = [];
21
22
    private $aliases = [];
23
24
    private $classesPaths = [];
25
26
    private function __construct() {
27
        spl_autoload_register([$this, 'autoload'], false);
28
    }
29
30
    private function __clone() {
31
32
    }
33
34
    /**
35
     *
36
     * @return ClassLoader
37
     */
38
    public static function getInstance() {
39
        if (self::$instance == null) {
40
            self::$instance = new self;
41
        }
42
        return self::$instance;
43
    }
44
45
    /**
46
     *
47
     * @param array $array
48
     * @param string $path
49
     * @param string (optional) $key
50
     * @param string $key
51
     * @throws \Exception
52
     */
53
    private function addPath(array &$array, $path, $key = null) {
54
        if (!is_dir($path)) {
55
            throw new \Exception('Error registering [' . $path . '] - folder do not exist');
56
        }
57
        if (in_array($path, $array)) {
58
            return;
59
        }
60
61
        if ($key == null) {
62
            $array[] = $path;
63
        } else {
64
            $array[$key] = $path;
65
        }
66
    }
67
68
    /**
69
     *
70
     * @param string $path
71
     * @return \ClassLoader
72
     */
73
    public function registerNamespacedPath($path) {
74
        $this->addPath($this->namespacedPaths, $path);
75
        return $this;
76
    }
77
78
    /**
79
     *
80
     * @param string $path
81
     * @return \ClassLoader
82
     */
83
    public function registerClassesPath($path) {
84
        $this->addPath($this->classesPaths, $path);
85
        return $this;
86
    }
87
88
    /**
89
     *
90
     * @param string $path
91
     * @param string $name
92
     * @return \ClassLoader
93
     */
94
    public function registerAlias($path, $name) {
95
        $this->addPath($this->aliases, $path, $name);
96
        return $this;
97
    }
98
99
    /**
100
     * Function for registering in spl_autoload_register()
101
     * @param string $className
102
     */
103
    public function autoload($className) {
104
        $className = ltrim($className, '\\');
105
        if (strpos($className, '\\') > 0) {
106
            $this->loadNamespacedClass($className);
107
        } else {
108
            $this->loadClass($className);
109
        }
110
    }
111
112
    /**
113
     * @param string $className
114
     */
115
    private function lookInAliases($className) {
116
        // getting first element of namespace path and search it in namespaces
117
        list($namespace, $fileName) = $this->splitClassName($className);
118
        if (array_key_exists($namespace, $this->aliases) && strpos($namespace, '\\') > 0) {
119
            $classPath = $this->aliases[$namespace] . '/' . $fileName . self::EXT;
120
            $this->includeClass($classPath);
121
            return true;
122
        }
123
124
        $parts = explode('\\', $className);
125
        $alias = array_shift($parts);
126
        if (!array_key_exists($alias, $this->aliases)) {
127
            return false;
128
        }
129
        $pathToNamepace = rtrim($this->aliases[$alias], self::DS) . self::DS;
130
        $classPath = $pathToNamepace . implode(self::DS, $parts) . self::EXT;
131
        return $this->includeClass($classPath);
132
    }
133
134
    /**
135
     *
136
     * @param string $className
137
     * @return array [namespace, fileName]
138
     */
139
    private function splitClassName($className) {
140
        $parts = explode('\\', $className);
141
        $fileName = array_pop($parts);
142
        return [implode('\\', $parts), $fileName];
143
    }
144
145
    /**
146
     * @param string $className
147
     */
148
    private function loadNamespacedClass($className) {
149
        if (true == $this->lookInAliases($className)) {
150
            return;
151
        }
152
        $namespacedClassPath = str_replace('\\', self::DS, $className);
153
        $namespacedPathsCount = count($this->namespacedPaths);
154 View Code Duplication
        for ($i = 0; $i < $namespacedPathsCount; $i++) {
155
            $classPath = rtrim($this->namespacedPaths[$i], self::DS) . self::DS . $namespacedClassPath . self::EXT;
156
            if (true == $this->includeClass($classPath)) {
157
                return;
158
            }
159
        }
160
    }
161
162
    /**
163
     * @param string $className
164
     */
165
    private function loadClass($className) {
166
        $classesPathsCount = count($this->classesPaths);
167
168 View Code Duplication
        for ($i = 0; $i < $classesPathsCount; $i++) {
169
            $classPath = rtrim($this->classesPaths[$i], self::DS) . self::DS . $className . self::EXT;
170
            if (true == $this->includeClass($classPath)) {
171
                return;
172
            }
173
        }
174
    }
175
176
    /**
177
     * @param string $classPath
178
     */
179
    private function includeClass($classPath) {
180
        if (file_exists($classPath)) {
181
            include_once $classPath;
182
            return true;
183
        }
184
        return false;
185
    }
186
187
}