Issues (569)

Security Analysis    not enabled

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/GlobalOptionsEventListener.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
namespace Robo;
4
5
use Symfony\Component\Console\ConsoleEvents;
6
use Symfony\Component\Console\Event\ConsoleCommandEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
use Robo\Contract\ConfigAwareInterface;
9
use Robo\Common\ConfigAwareTrait;
10
use Robo\Config\GlobalOptionDefaultValuesInterface;
11
12
class GlobalOptionsEventListener implements EventSubscriberInterface, ConfigAwareInterface
13
{
14
    use ConfigAwareTrait;
15
16
    /**
17
     * @var \Robo\Application
18
     */
19
    protected $application;
20
21
    /**
22
     * @var string
23
     */
24
    protected $prefix;
25
26
    /**
27
     * GlobalOptionsEventListener listener
28
     */
29
    public function __construct()
30
    {
31
        $this->prefix = 'options';
32
    }
33
34
    /**
35
     * Add a reference to the Symfony Console application object.
36
     *
37
     * @param \Robo\Application $application
38
     *
39
     * @return $this
40
     */
41
    public function setApplication($application)
42
    {
43
        $this->application = $application;
44
        return $this;
45
    }
46
47
    /**
48
     * Stipulate the prefix to use for option injection.
49
     *
50
     * @param string $prefix
51
     *
52
     * @return $this
53
     */
54
    public function setGlobalOptionsPrefix($prefix)
55
    {
56
        $this->prefix = $prefix;
57
        return $this;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public static function getSubscribedEvents()
64
    {
65
        return [ConsoleEvents::COMMAND => 'handleCommandEvent'];
66
    }
67
68
    /**
69
     * Run all of our individual operations when a command event is received.
70
     */
71
    public function handleCommandEvent(ConsoleCommandEvent $event)
72
    {
73
        $this->setGlobalOptions($event);
74
        $this->setConfigurationValues($event);
75
    }
76
77
    /**
78
     * Before a Console command runs, examine the global
79
     * commandline options from the event Input, and set
80
     * configuration values as appropriate.
81
     *
82
     * @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event
83
     */
84
    public function setGlobalOptions(ConsoleCommandEvent $event)
85
    {
86
        $config = $this->getConfig();
87
        $input = $event->getInput();
88
89
        $globalOptions = $config->get($this->prefix, []);
0 ignored issues
show
array() is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
90
        if ($config instanceof \Consolidation\Config\GlobalOptionDefaultValuesInterface) {
91
            $globalOptions += $config->getGlobalOptionDefaultValues();
92
        }
93
94
        $globalOptions += $this->applicationOptionDefaultValues();
95
96
        // Set any config value that has a defined global option (e.g. --simulate)
97
        foreach ($globalOptions as $option => $default) {
98
            $value = $input->hasOption($option) ? $input->getOption($option) : null;
99
            // Unfortunately, the `?:` operator does not differentate between `0` and `null`
100
            if (!isset($value)) {
101
                $value = $default;
102
            }
103
            $config->set($this->prefix . '.' . $option, $value);
104
        }
105
    }
106
107
    /**
108
     * Examine the commandline --define / -D options, and apply the provided
109
     * values to the active configuration.
110
     *
111
     * @param \Symfony\Component\Console\Event\ConsoleCommandEvent $event
112
     */
113
    public function setConfigurationValues(ConsoleCommandEvent $event)
114
    {
115
        $config = $this->getConfig();
116
        $input = $event->getInput();
117
118
        // Also set any `-Dconfig.key=value` options from the commandline.
119
        if ($input->hasOption('define')) {
120
            $configDefinitions = $input->getOption('define');
121
            foreach ($configDefinitions as $value) {
0 ignored issues
show
The expression $configDefinitions of type string|array<integer,string>|boolean|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
122
                list($key, $value) = $this->splitConfigKeyValue($value);
123
                $config->set($key, $value);
124
            }
125
        }
126
    }
127
128
    /**
129
     * Split up the key=value config setting into its component parts. If
130
     * the input string contains no '=' character, then the value will be 'true'.
131
     *
132
     * @param string $value
133
     *
134
     * @return array
135
     */
136
    protected function splitConfigKeyValue($value)
137
    {
138
        $parts = explode('=', $value, 2);
139
        $parts[] = true;
140
        return $parts;
141
    }
142
143
    /**
144
     * Get default option values from the Symfony Console application, if
145
     * it is available.
146
     *
147
     * @return array
148
     */
149
    protected function applicationOptionDefaultValues()
150
    {
151
        if (!$this->application) {
152
            return [];
153
        }
154
155
        $result = [];
156
        foreach ($this->application->getDefinition()->getOptions() as $key => $option) {
157
            $result[$key] = $option->acceptValue() ? $option->getDefault() : null;
158
        }
159
        return $result;
160
    }
161
}
162