Issues (5)

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/Config.php (2 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
namespace Puppy\Config;
3
4
use Puppy\Config\FileReader\IFileReader;
5
use Puppy\Config\FileReader\PhpFileReader;
6
7
/**
8
 * Class Config
9
 * @package Puppy\Config
10
 * @author Raphaël Lefebvre <[email protected]>
11
 */
12
class Config extends ArrayConfig
13
{
14
    /**
15
     * @var string
16
     */
17
    private $env;
18
    /**
19
     * @var FileParams
20
     */
21
    private $fileParams;
22
    /**
23
     * @var IFileReader
24
     */
25
    private $fileReader;
26
27
    /**
28
     * @param string $env
29
     * @param FileParams $fileParams
0 ignored issues
show
Should the type for parameter $fileParams not be null|FileParams?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
30
     * @param IFileReader $fileReader
0 ignored issues
show
Should the type for parameter $fileReader not be null|IFileReader?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
31
     */
32 10
    public function __construct($env = '', FileParams $fileParams = null, IFileReader $fileReader = null)
33
    {
34 10
        $this->setEnv($env);
35 10
        $this->setFileParams($fileParams ? : new FileParams());
36 10
        $this->setFileReader($fileReader ? : new PhpFileReader());
37 10
        parent::__construct($this->getData());
38 10
    }
39
40
    /**
41
     * Getter of $env
42
     *
43
     * @return string
44
     */
45 10
    public function getEnv()
46
    {
47 10
        return $this->env;
48
    }
49
50
    /**
51
     * Getter of $fileParams
52
     *
53
     * @return FileParams
54
     */
55 10
    public function getFileParams()
56
    {
57 10
        return $this->fileParams;
58
    }
59
60
    /**
61
     * Getter of $fileReader
62
     *
63
     * @return IFileReader
64
     */
65 10
    public function getFileReader()
66
    {
67 10
        return $this->fileReader;
68
    }
69
70
    /**
71
     * @return string
72
     */
73 10
    public function getMainFilePath()
74
    {
75 10
        return $this->getFileParams()->getDirPath()
76
                . DIRECTORY_SEPARATOR
77 10
                . $this->getFileParams()->getMainConfigFileName()
78 10
                . $this->getFileReader()->getFileExtension();
79
    }
80
81
    /**
82
     * @return string
83
     */
84 10
    public function getEnvFilePath()
85
    {
86 10
        return $this->getFileParams()->getDirPath()
87
                . DIRECTORY_SEPARATOR
88 10
                . $this->getEnv()
89 10
                . $this->getFileReader()->getFileExtension();
90
    }
91
92
    /**
93
     * @return string
94
     */
95 10
    public function getLocalFilePath()
96
    {
97 10
        return $this->getFileParams()->getDirPath()
98
                . DIRECTORY_SEPARATOR
99 10
                . $this->getFileParams()->getLocalConfigFileName()
100 10
                . $this->getFileReader()->getFileExtension();
101
    }
102
103
    /**
104
     * @return array
105
     */
106 10
    private function getData()
107
    {
108 10
        return $this->getFilesContent(
109
            [
110 10
                $this->getMainFilePath(),
111 10
                $this->getEnvFilePath(),
112 10
                $this->getLocalFilePath(),
113
            ]
114 10
        );
115
    }
116
117
    /**
118
     * @param string[] $filePaths
119
     * @return array
120
     */
121 10
    private function getFilesContent(array $filePaths)
122
    {
123 10
        $result = [];
124 10
        foreach ($filePaths as $filePath) {
125 10
            $filePath = $this->getRealPath($filePath);
126 10
            if ($filePath) {
127 8
                $result = array_merge($result, $this->getFileReader()->read($filePath));
128 8
            }
129 10
        }
130 10
        return $result;
131
    }
132
133
    /**
134
     * @param string $filePath
135
     * @return string
136
     */
137 10
    private function getRealPath($filePath)
138
    {
139 10
        $filePath = stream_resolve_include_path($filePath);
140 10
        if ($filePath && is_readable($filePath)) {
141 8
            return $filePath;
142
        }
143 7
        return '';
144
    }
145
146
    /**
147
     * Setter of $env
148
     *
149
     * @param string $env
150
     */
151 10
    private function setEnv($env)
152
    {
153 10
        $this->env = (string)$env;
154 10
    }
155
156
    /**
157
     * Setter of $fileParams
158
     *
159
     * @param FileParams $fileParams
160
     */
161 10
    private function setFileParams(FileParams $fileParams)
162
    {
163 10
        $this->fileParams = $fileParams;
164 10
    }
165
166
    /**
167
     * Setter of $fileReader
168
     *
169
     * @param IFileReader $fileReader
170
     */
171 10
    private function setFileReader(IFileReader $fileReader)
172
    {
173 10
        $this->fileReader = $fileReader;
174 10
    }
175
}
176
 
177