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/Base/ConfigManager.php (1 issue)

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 Vinelab\UrlShortener\Base;
4
5
use Illuminate\Config\Repository;
6
use Symfony\Component\Finder\Finder;
7
8
/**
9
 * Extends the Laravel `Illuminate\Config\Repository` thus it can be used as in Laravel.
10
 * it also contains some helper functions to facilitate reading the configuration from this package.
11
 * Once an object of this class is initialized it will automatically read the package config file.
12
 *
13
 * Yes this class is doing multiple things it could be easily splited into multiple classes, however
14
 * I preferred to keep it as portable as possible.
15
 *
16
 * @category Manager Class (of the configuration)
17
 *
18
 * @author   Mahmoud Zalt <[email protected]>
19
 */
20
class ConfigManager extends Repository
21
{
22
    /**
23
     * the config file name of this package.
24
     */
25
    const CONFIG_FILE_NAME = 'url-shortener';
26
27
    /**
28
     * load the configuration files.
29
     */
30
    public function __construct()
31
    {
32
        $path = $this->configurationPath();
33
34
        $this->loadConfigurationFiles($path);
35
    }
36
37
    /**
38
     * extend the functionality of the default get() of the Repository
39
     * but always prepend the keys with the config file name.
40
     *
41
     * @param $key
42
     *
43
     * @return mixed
44
     */
45
    public function read($key)
46
    {
47
        return $this->get(self::CONFIG_FILE_NAME.'.'.$key);
48
    }
49
50
    /**
51
     * helper function to return the driver default name.
52
     *
53
     * @return mixed
54
     */
55
    public function driverName()
56
    {
57
        return $this->read('default');
58
    }
59
60
    /**
61
     * helper function to return the parameters of the driver $name.
62
     *
63
     * @param $name
64
     *
65
     * @return mixed
66
     */
67
    public function driverParameters($name)
68
    {
69
        return $this->read('drivers'.'.'.$name);
70
    }
71
72
    /**
73
     * Initialize the paths.
74
     * check if this package is used inside of laravel project,
75
     * if it is laravel project then try to load the config file
76
     * from the laravel config directory.
77
     * if the file was not found (not published) ten load the config
78
     * file form the package directory.
79
     *
80
     * @return string
81
     */
82
    private function configurationPath()
83
    {
84
        // the config file of the package directory
85
        $config_path = str_replace('/Base', '/Config', __DIR__);
86
87
        // check if this laravel specific function `config_path()` exist (means this package is used inside
88
        // a laravel framework). If so then load then try to load the laravel config file if it exist.
89
        if (function_exists('config_path')) {
90
            $config_file = config_path().'/'.self::CONFIG_FILE_NAME.'.php';
91
92
            if (file_exists($config_file)) {
93
                // override the path by the laravel specific config directory 
94
                $config_path = config_path();
95
            }
96
        }
97
98
        return $config_path;
99
    }
100
101
    /**
102
     * Load the configuration items from all of the files.
103
     *
104
     * @param $path
105
     */
106
    private function loadConfigurationFiles($path)
107
    {
108
        $this->configPath = $path;
0 ignored issues
show
The property configPath does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
109
110
        foreach ($this->getConfigurationFiles() as $fileKey => $path) {
111
            $this->set($fileKey, require $path);
112
        }
113
114
        foreach ($this->getConfigurationFiles() as $fileKey => $path) {
115
            $envConfig = require $path;
116
117
            foreach ($envConfig as $envKey => $value) {
118
                $this->set($fileKey.'.'.$envKey, $value);
119
            }
120
        }
121
    }
122
123
    /**
124
     * Get the configuration files for the selected environment.
125
     *
126
     * @return array
127
     */
128
    private function getConfigurationFiles()
129
    {
130
        $path = $this->configPath;
131
132
        if (!is_dir($path)) {
133
            return [];
134
        }
135
136
        $files = [];
137
        $phpFiles = Finder::create()->files()->name('*.php')->in($path)->depth(0);
138
139
        foreach ($phpFiles as $file) {
140
            $files[basename($file->getRealPath(), '.php')] = $file->getRealPath();
141
        }
142
143
        return $files;
144
    }
145
}
146