Issues (6)

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/FileLocator.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
 * File locater
4
 *
5
 * @package SugiPHP.Config
6
 * @author  Plamen Popov <[email protected]>
7
 * @license http://opensource.org/licenses/mit-license.php (MIT License)
8
 */
9
10
namespace SugiPHP\Config;
11
12
/**
13
 * File Locator searches for a file in registered search paths.
14
 */
15
class FileLocator implements LocatorInterface
16
{
17
    /**
18
     * Search for a file in one or more directories.
19
     * @var array
20
     */
21
    protected $paths;
22
23
    /**
24
     * File Locator creator.
25
     *
26
     * @param array|string $paths
27
     *
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30
    public function __construct($paths)
31
    {
32
        $this->addPath($paths);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function locate($resource)
39
    {
40
        // empty string
41
        if (empty($resource)) {
42
            return ;
43
        }
44
        if ($this->isFullPath($resource)) {
45
            if (is_file($resource)) {
46
                return $resource;
47
            }
48
        } else {
49
            foreach ($this->paths as $path) {
50
                $file = "{$path}{$resource}";
51
                if (is_file($file)) {
52
                    return $file;
53
                }
54
            }
55
        }
56
    }
57
58
    /**
59
     * Adds a search paths.
60
     *
61
     * @param string|array $path or several paths
62
     *
63
     * @return void
64
     */
65
    public function addPath($path)
66
    {
67
        $paths = (array) $path;
68
        foreach ($paths as $path) {
69
            $this->paths[] = rtrim($path, "\\/") . DIRECTORY_SEPARATOR;
70
        }
71
    }
72
73
    /**
74
     * Remove last search path.
75
     *
76
     * @return void
77
     */
78
    public function popPath()
79
    {
80
        array_pop($this->paths);
81
    }
82
83
    /**
84
     * @deprecated Use unshiftPath() method
85
     */
86
    public function prependPath($path)
87
    {
88
        return $this->unshiftPath($path);
89
    }
90
91
    /**
92
     * Prepends one path to the beginning of the search paths.
93
     *
94
     * @param string $path
95
     *
96
     * @return void
97
     */
98
    public function unshiftPath($path)
99
    {
100
        array_unshift($this->paths, rtrim($path, "\\/") . DIRECTORY_SEPARATOR);
101
    }
102
103
    /**
104
     * Remove first path from the search paths.
105
     *
106
     * @return void
107
     */
108
    public function shiftPath()
109
    {
110
        array_shift($this->paths);
111
    }
112
113
    /**
114
     * Returns all registered search paths.
115
     *
116
     * @return array
117
     */
118
    public function getPaths()
119
    {
120
        return $this->paths;
121
    }
122
123
    /**
124
     * Check if the file/path is given with absolute path.
125
     *
126
     * @param string $path
127
     *
128
     * @return bool
129
     */
130
    protected function isFullPath($path)
131
    {
132
        // *nix style
133
        if ($path[0] == "/") {
134
            return true;
135
        }
136
137
        // windows style
138
        if (preg_match("#[A-Z]:\\.+#U", $path)) {
139
            return true;
140
        }
141
142
        return false;
143
    }
144
}
145