Issues (11)

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

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 Rezdy;
4
5
use ErrorException;
6
7
class Config
8
{
9
    /**
10
     * List of allowed parameters
11
     */
12
    public const ALLOWED = [
13
        'api_key',
14
        'proxy',
15
        'base_uri',
16
        'user_agent',
17
        'timeout',
18
        'tries',
19
        'seconds',
20
        'debug',
21
        'track_redirects'
22
    ];
23
24
    /**
25
     * List of minimal required parameters
26
     */
27
    public const REQUIRED = [
28
        'user_agent',
29
        'base_uri',
30
        'timeout',
31
        'api_key',
32
    ];
33
34
    /**
35
     * List of configured parameters
36
     *
37
     * @var array
38
     */
39
    private $_parameters;
40
41
    /**
42
     * Config constructor.
43
     *
44
     * @param array $parameters List of parameters which can be set on object creation stage
45
     *
46
     * @throws \ErrorException
47
     */
48
    public function __construct(array $parameters = [])
49
    {
50
        // Set default parameters of client
51
        $this->_parameters = [
52
            // Errors must be disabled by default, because we need to get error codes
53
            // @link http://docs.guzzlephp.org/en/stable/request-options.html#http-errors
54
            'http_errors'     => false,
55
56
            // Wrapper settings
57
            'tries'           => 2,  // Count of tries
58
            'seconds'         => 10, // Waiting time per each try
59
60
            // Optional parameters
61
            'debug'           => false,
62
            'track_redirects' => false,
63
64
            // Main parameters
65
            'timeout'         => 20,
66
            'user_agent'      => 'Rezdy PHP Client',
67
            'base_uri'        => 'https://api.rezdy.com/v1'
68
        ];
69
70
        // Overwrite parameters by client input
71
        foreach ($parameters as $key => $value) {
72
            $this->set($key, $value);
73
        }
74
    }
75
76
    /**
77
     * Magic setter parameter by name
78
     *
79
     * @param string               $name  Name of parameter
80
     * @param string|bool|int|null $value Value of parameter
81
     *
82
     * @throws \ErrorException
83
     */
84
    public function __set(string $name, $value)
85
    {
86
        $this->set($name, $value);
87
    }
88
89
    /**
90
     * Check if parameter if available
91
     *
92
     * @param string $name Name of parameter
93
     *
94
     * @return bool
95
     */
96
    public function __isset($name): bool
97
    {
98
        return isset($this->_parameters[$name]);
99
    }
100
101
    /**
102
     * Get parameter via magic call
103
     *
104
     * @param string $name Name of parameter
105
     *
106
     * @return bool|int|string|null
107
     * @throws ErrorException
108
     */
109
    public function __get($name)
110
    {
111
        return $this->get($name);
112
    }
113
114
    /**
115
     * Remove parameter from array
116
     *
117
     * @param string $name Name of parameter
118
     */
119
    public function __unset($name)
120
    {
121
        unset($this->_parameters[$name]);
122
    }
123
124
    /**
125
     * Set parameter by name
126
     *
127
     * @param string               $name  Name of parameter
128
     * @param string|bool|int|null $value Value of parameter
129
     *
130
     * @return $this
131
     * @throws ErrorException
132
     */
133
    public function set(string $name, $value): self
134
    {
135
        if (!in_array($name, self::ALLOWED, false)) {
136
            throw new ErrorException("Parameter \"$name\" is not in available list [" . implode(',', self::ALLOWED) . ']');
137
        }
138
139
        // Add parameters into array
140
        $this->_parameters[$name] = $value;
141
        return $this;
142
    }
143
144
    /**
145
     * Get available parameter by name
146
     *
147
     * @param string $name Name of parameter
148
     *
149
     * @return bool|int|string|null
150
     * @throws ErrorException
151
     */
152
    public function get(string $name)
153
    {
154
        if (!isset($this->_parameters[$name])) {
155
            throw new ErrorException("Parameter \"$name\" is not in set");
156
        }
157
158
        return $this->_parameters[$name];
159
    }
160
161
    /**
162
     * Get all available parameters
163
     *
164
     * @return array
165
     */
166
    public function all(): array
167
    {
168
        return $this->_parameters;
169
    }
170
171
    /**
172
     * Return all ready for Guzzle parameters
173
     *
174
     * @return array
175
     * @throws ErrorException
176
     */
177
    public function guzzle(): array
178
    {
179
        $options = [
180
            // 'base_uri'        => $this->get('base_uri'), // By some reasons base_uri option is not work anymore
181
            'timeout'         => $this->get('timeout'),
182
            'track_redirects' => $this->get('track_redirects'),
183
            'debug'           => $this->get('debug'),
184
            'headers'         => [
185
                'User-Agent' => $this->get('user_agent'),
186
                'apiKey'     => $this->get('api_key'),
187
            ]
188
        ];
189
190
        // Proxy is optional
191
        if (isset($this->proxy)) {
192
            $options['proxy'] = $this->proxy;
0 ignored issues
show
The property proxy does not exist on object<Rezdy\Config>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
193
        }
194
195
        return $options;
196
    }
197
}
198