Issues (2)

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/DotEnv.php (2 issues)

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 Arrilot\DotEnv;
4
5
use Arrilot\DotEnv\Exceptions\MissingVariableException;
6
7
class DotEnv
8
{
9
    /**
10
     * Key-value storage.
11
     *
12
     * @var array
13
     */
14
    protected static $variables = [];
15
16
    /**
17
     * Required variables.
18
     *
19
     * @var array
20
     */
21
    protected static $required = [];
22
23
    /**
24
     * Were variables loaded?
25
     *
26
     * @var bool
27
     */
28
    protected static $isLoaded = false;
29
30
    /**
31
     * Load .env.php file or array.
32
     *
33
     * @param string|array $source
34
     *
35
     * @return void
36
     */
37
    public static function load($source)
38
    {
39
        self::$variables = is_array($source) ? $source : require $source;
40
        self::$isLoaded = true;
41
42
        self::checkRequiredVariables();
43
    }
44
45
    /**
46
     * Copy all variables to putenv().
47
     *
48
     * @param string $prefix
49
     */
50
    public static function copyVarsToPutenv($prefix = 'PHP_')
51
    {
52
        foreach (self::all() as $key => $value) {
53
            if (is_object($value) || is_array($value)) {
54
                $value = serialize($value);
55
            }
56
57
            putenv("{$prefix}{$key}={$value}");
58
        }
59
    }
60
61
    /**
62
     * Copy all variables to $_ENV.
63
     */
64
    public static function copyVarsToEnv()
0 ignored issues
show
copyVarsToEnv uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
65
    {
66
        foreach (self::all() as $key => $value) {
67
            $_ENV[$key] = $value;
68
        }
69
    }
70
71
    /**
72
     * Copy all variables to $_SERVER.
73
     */
74
    public static function copyVarsToServer()
0 ignored issues
show
copyVarsToServer uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
75
    {
76
        foreach (self::all() as $key => $value) {
77
            $_SERVER[$key] = $value;
78
        }
79
    }
80
81
    /**
82
     * Get env variables.
83
     *
84
     * @return array
85
     */
86
    public static function all()
87
    {
88
        return self::$variables;
89
    }
90
91
    /**
92
     * Get env variable.
93
     *
94
     * @param string $key
95
     * @param mixed  $default
96
     *
97
     * @return mixed
98
     */
99
    public static function get($key, $default = null)
100
    {
101
        return isset(self::$variables[$key]) ? self::$variables[$key] : $default;
102
    }
103
104
    /**
105
     * Set env variable.
106
     *
107
     * @param string|array $keys
108
     * @param mixed        $value
109
     *
110
     * @return void
111
     */
112
    public static function set($keys, $value = null)
113
    {
114
        if (is_array($keys)) {
115
            self::$variables = array_merge(self::$variables, $keys);
116
        } else {
117
            self::$variables[$keys] = $value;
118
        }
119
    }
120
121
    /**
122
     * Set required variables.
123
     *
124
     * @param array $variables
125
     */
126
    public static function setRequired(array $variables)
127
    {
128
        self::$required = $variables;
129
130
        if (self::$isLoaded) {
131
            self::checkRequiredVariables();
132
        }
133
    }
134
135
    /**
136
     * Delete all variables.
137
     *
138
     * @return void
139
     */
140
    public static function flush()
141
    {
142
        self::$variables = [];
143
        self::$isLoaded = false;
144
    }
145
146
    /**
147
     * Throw exception if any of required variables was not loaded.
148
     *
149
     * @throws MissingVariableException
150
     *
151
     * @return void
152
     */
153
    protected static function checkRequiredVariables()
154
    {
155
        foreach (self::$required as $key) {
156
            if (!isset(self::$variables[$key])) {
157
                throw new MissingVariableException(".env variable '{$key}' is missing");
158
            }
159
        }
160
    }
161
}
162