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

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
declare(strict_types=1);
4
5
namespace GitWrapper;
6
7
final class GitCommand
8
{
9
    /**
10
     * Path to the directory containing the working copy. If this variable is
11
     * set, then the process will change into this directory while the Git
12
     * command is being run.
13
     *
14
     * @var string|null
15
     */
16
    private $directory;
17
18
    /**
19
     * The command being run, e.g. "clone", "commit", etc.
20
     *
21
     * @var string
22
     */
23
    private $command = '';
24
25
    /**
26
     * Whether command execution should be bypassed.
27
     *
28
     * @var bool
29
     */
30
    private $bypass = false;
31
32
    /**
33
     * Whether to execute the raw command without escaping it. This is useful
34
     * for executing arbitrary commands, e.g. "status -s". If this is true,
35
     * any options and arguments are ignored.
36
     *
37
     * @var bool
38
     */
39
    private $executeRaw = false;
40
41
    /**
42
     * @var mixed[]
43
     */
44
    private $options = [];
45
46
    /**
47
     * @var mixed[]
48
     */
49
    private $args = [];
50
51
    /**
52
     * @param mixed ...$argsAndOptions
53
     */
54
    public function __construct(string $command = '', ...$argsAndOptions)
55
    {
56
        $this->command = $command;
57
58
        foreach ($argsAndOptions as $argOrOption) {
59
            if (is_array($argOrOption)) {
60
                // If item is array, set it as the options
61
                $this->setOptions($argOrOption);
62
            } else {
63
                // Pass all other as the Git command arguments
64
                $this->addArgument($argOrOption);
65
            }
66
        }
67
    }
68
69
    /**
70
     * Returns Git command being run, e.g. "clone", "commit", etc.
71
     * @api
72
     */
73
    public function getCommand(): string
74
    {
75
        return $this->command;
76
    }
77
78
    public function setDirectory(?string $directory): void
79
    {
80
        $this->directory = $directory;
81
    }
82
83
    public function getDirectory(): ?string
84
    {
85
        return $this->directory;
86
    }
87
88
    /**
89
     * A bool flagging whether to skip running the command.
90
     */
91
    public function bypass(bool $bypass = true): void
92
    {
93
        $this->bypass = $bypass;
94
    }
95
96
    /**
97
     * Set whether to execute the command as-is without escaping it.
98
     */
99
    public function executeRaw(bool $executeRaw = true): void
100
    {
101
        $this->executeRaw = $executeRaw;
102
    }
103
104
    /**
105
     * Returns true if the Git command should be run.
106
     */
107
    public function notBypassed(): bool
108
    {
109
        return ! $this->bypass;
110
    }
111
112
    /**
113
     * @param mixed[]|string|true $value The option's value, pass true if the options is a flag.
114
     */
115
    public function setOption(string $option, $value): void
116
    {
117
        $this->options[$option] = $value;
118
    }
119
120
    /**
121
     * @api
122
     * @param mixed[] $options
123
     */
124
    public function setOptions(array $options): void
125
    {
126
        foreach ($options as $option => $value) {
127
            $this->setOption($option, $value);
128
        }
129
    }
130
131
    public function setFlag(string $option): void
132
    {
133
        $this->setOption($option, true);
0 ignored issues
show
true is of type boolean, but the function expects a array<integer,*>|string|object<GitWrapper\true>.

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...
134
    }
135
136
    /**
137
     * @api
138
     */
139
    public function getOption(string $option, $default = null)
140
    {
141
        return $this->options[$option] ?? $default;
142
    }
143
144
    public function addArgument(string $arg): void
145
    {
146
        $this->args[] = $arg;
147
    }
148
149
    /**
150
     * Renders the arguments and options for the Git command.
151
     *
152
     * @return string|string[]
153
     */
154
    public function getCommandLine()
155
    {
156
        if ($this->executeRaw) {
157
            return $this->command;
158
        }
159
160
        $command = [];
161
        $parts = array_merge([$this->command], $this->buildOptions(), $this->args);
162
163
        foreach ($parts as $part) {
164
            $value = (string) $part;
165
            if (strlen($value) > 0) {
166
                $command[] = $value;
167
            }
168
        }
169
170
        return $command;
171
    }
172
173
    /**
174
     * Builds the command line options for use in the Git command.
175
     *
176
     * @return mixed[]
177
     */
178
    private function buildOptions(): array
179
    {
180
        $options = [];
181
        foreach ($this->options as $option => $values) {
182
            foreach ((array) $values as $value) {
183
                // Render the option.
184
                $prefix = strlen($option) !== 1 ? '--' : '-';
185
                $options[] = $prefix . $option;
186
187
                // Render apend the value if the option isn't a flag.
188
                if ($value !== true) {
189
                    $options[] = $value;
190
                }
191
            }
192
        }
193
194
        return $options;
195
    }
196
}
197