Issues (9)

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/Api/LoadBalancer.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
 * This file is part of the DigitalOceanV2 library.
5
 *
6
 * (c) Antoine Corcy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DigitalOceanV2\Api;
13
14
use DigitalOceanV2\Entity\AbstractEntity;
15
use DigitalOceanV2\Entity\ForwardingRule as ForwardRuleEntity;
16
use DigitalOceanV2\Entity\HealthCheck as HealthCheckEntity;
17
use DigitalOceanV2\Entity\LoadBalancer as LoadBalancerEntity;
18
use DigitalOceanV2\Exception\HttpException;
19
20
/**
21
 * @author Jacob Holmes <[email protected]>
22
 */
23
class LoadBalancer extends AbstractApi
24
{
25
    /**
26
     * @return LoadBalancerEntity[]
27
     */
28
    public function getAll()
29
    {
30
        $loadBalancers = $this->adapter->get(sprintf('%s/load_balancers', $this->endpoint));
31
32
        $loadBalancers = json_decode($loadBalancers);
33
34
        $this->extractMeta($loadBalancers);
35
36
        return array_map(function ($key) {
37
            return new LoadBalancerEntity($key);
38
        }, $loadBalancers->load_balancers);
39
    }
40
41
    /**
42
     * @param string $id
43
     *
44
     * @throws HttpException
45
     *
46
     * @return LoadBalancerEntity
47
     */
48
    public function getById($id)
49
    {
50
        $loadBalancer = $this->adapter->get(sprintf('%s/load_balancers/%s', $this->endpoint, $id));
51
52
        $loadBalancer = json_decode($loadBalancer);
53
54
        return new LoadBalancerEntity($loadBalancer->load_balancer);
55
    }
56
57
    /**
58
     * @param string                      $name
59
     * @param string                      $region
60
     * @param array|ForwardRuleEntity[]   $forwardRules
61
     * @param string                      $algorithm
62
     * @param array|HealthCheckEntity[]   $healthCheck
63
     * @param array|StickySessionEntity[] $stickySessions
64
     * @param array                       $dropletIds
65
     * @param bool                        $httpsRedirect
66
     *
67
     * @throws HttpException
68
     *
69
     * @return LoadBalancerEntity
70
     */
71
    public function create(
72
        $name,
73
        $region,
74
        $forwardRules = null,
75
        $algorithm = 'round_robin',
76
        $healthCheck = [],
77
        $stickySessions = [],
78
        $dropletIds = [],
79
        $httpsRedirect = false
80
    ) {
81
        $data = [
82
            'name' => $name,
83
            'algorithm' => $algorithm,
84
            'region' => $region,
85
            'forwarding_rules' => $this->formatForwardRules($forwardRules),
0 ignored issues
show
It seems like $forwardRules defined by parameter $forwardRules on line 74 can also be of type null; however, DigitalOceanV2\Api\LoadB...r::formatForwardRules() does only seem to accept array|object<DigitalOcea...\Entity\AbstractEntity>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
86
            'health_check' => $this->formatConfigurationOptions($healthCheck),
87
            'sticky_sessions' => $this->formatConfigurationOptions($stickySessions),
88
            'droplet_ids' => $dropletIds,
89
            'redirect_http_to_https' => $httpsRedirect,
90
        ];
91
92
        $loadBalancer = $this->adapter->post(sprintf('%s/load_balancers', $this->endpoint), $data);
93
94
        $loadBalancer = json_decode($loadBalancer);
95
96
        return new LoadBalancerEntity($loadBalancer->load_balancer);
97
    }
98
99
    /**
100
     * @param string                   $id
101
     * @param array|LoadBalancerEntity $loadBalancerSpec
102
     *
103
     * @throws HttpException
104
     *
105
     * @return LoadBalancerEntity
106
     */
107
    public function update($id, $loadBalancerSpec)
108
    {
109
        $data = $this->formatConfigurationOptions($loadBalancerSpec);
110
111
        $loadBalancer = $this->adapter->put(sprintf('%s/load_balancers/%s', $this->endpoint, $id), $data);
0 ignored issues
show
It seems like $data defined by $this->formatConfigurati...ions($loadBalancerSpec) on line 109 can also be of type object<DigitalOceanV2\Entity\AbstractEntity>; however, DigitalOceanV2\Adapter\AdapterInterface::put() does only seem to accept string|array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
112
113
        $loadBalancer = json_decode($loadBalancer);
114
115
        return new LoadBalancerEntity($loadBalancer->load_balancer);
116
    }
117
118
    /**
119
     * @param string $id
120
     *
121
     * @throws HttpException
122
     */
123
    public function delete($id)
124
    {
125
        $this->adapter->delete(sprintf('%s/load_balancers/%s', $this->endpoint, $id));
126
    }
127
128
    /**
129
     * @param array|AbstractEntity $forwardRules
130
     *
131
     * @return array
132
     */
133
    private function formatForwardRules($forwardRules)
134
    {
135
        if (isset($forwardRules)) {
136
            return array_map(function ($rule) {
137
                return $this->formatConfigurationOptions($rule);
138
            }, $forwardRules);
139
        } else {
140
            return [
141
                (new ForwardRuleEntity())->setStandardHttpRules()->toArray(),
142
                (new ForwardRuleEntity())->setStandardHttpsRules()->toArray(),
143
            ];
144
        }
145
    }
146
147
    /**
148
     * @param array|AbstractEntity $config
149
     *
150
     * @return array|AbstractEntity
151
     */
152
    private function formatConfigurationOptions($config)
153
    {
154
        return $config instanceof AbstractEntity ? $config->toArray() : $config;
155
    }
156
}
157