Issues (14)

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/Watcher/Environment.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
3
/*
4
 * janitor (http://juliangut.com/janitor).
5
 * Effortless maintenance management.
6
 *
7
 * @license BSD-3-Clause
8
 * @link https://github.com/juliangut/janitor
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
namespace Janitor\Watcher;
13
14
/**
15
 * Environment variable maintenance status watcher.
16
 */
17
class Environment implements WatcherInterface
18
{
19
    /**
20
     * Environment variable.
21
     *
22
     * @var array
23
     */
24
    protected $vars;
25
26
    /**
27
     * Environment constructor.
28
     *
29
     * @param array|string $vars
30
     * @param mixed        $value
31
     */
32
    public function __construct($vars, $value = null)
33
    {
34
        if ($vars !== null && !is_array($vars)) {
35
            $vars = [$vars => $value];
36
        }
37
38
        if (is_array($vars)) {
39
            foreach ($vars as $varName => $varValue) {
40
                $this->addVariable($varName, $varValue);
41
            }
42
        }
43
    }
44
45
    /**
46
     * Set environment variable.
47
     *
48
     * @param string $var
49
     * @param mixed  $value
50
     *
51
     * @return $this
52
     */
53
    public function addVariable($var, $value = null)
54
    {
55
        if (trim($var) !== '') {
56
            $this->vars[trim($var)] = $value;
57
        }
58
59
        return $this;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function isActive()
66
    {
67
        if (!count($this->vars)) {
68
            throw new \RuntimeException('At least one environment variable must be defined');
69
        }
70
71
        foreach ($this->vars as $variable => $value) {
72
            if ($value === null && $this->isEnvVariableDefined($variable)) {
73
                return true;
74
            } elseif ($value !== null && $this->getEnvVariableValue($variable) === $value) {
75
                return true;
76
            }
77
        }
78
79
        return false;
80
    }
81
82
    /**
83
     * Test for environment variable.
84
     *
85
     * @param string $var
0 ignored issues
show
There is no parameter named $var. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
86
     *
87
     * @return bool
88
     */
89
    protected function isEnvVariableDefined($variable)
90
    {
91
        return getenv($variable) !== false;
92
    }
93
94
    /**
95
     * Get environment variable value.
96
     *
97
     * @param string $variable
98
     *
99
     * @return mixed
0 ignored issues
show
Consider making the return type a bit more specific; maybe use null|boolean|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
100
     */
101
    protected function getEnvVariableValue($variable)
102
    {
103
        $value = getenv($variable);
104
105
        if ($value === false) {
106
            return;
107
        }
108
109
        switch (strtolower($value)) {
110
            case 'true':
111
                return true;
112
113
            case 'false':
114
                return false;
115
        }
116
117
        if (preg_match('/^[\'"](.*)[\'"]$/', $value, $matches)) {
118
            return $matches[1];
119
        }
120
121
        return $value;
122
    }
123
}
124