Issues (58)

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/Adapters/BuzzAdapter.php (6 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 Laravel SMSFactor.
5
 *
6
 * (c) Filippo Galante <[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 IlGala\SMSFactor\Adapters;
13
14
use Buzz\Browser;
15
use Buzz\Client\Curl;
16
use Buzz\Client\FileGetContents;
17
use Buzz\Message\Response;
18
use IlGala\SMSFactor\Exceptions\HttpException;
19
20
/**
21
 * @author Filippo Galante <[email protected]>
22
 */
23
class BuzzAdapter implements AdapterInterface
24
{
25
26
    /**
27
     * @var Browser
28
     */
29
    protected $browser;
30
31
    /**
32
     * @var string
33
     */
34
    protected $username;
35
36
    /**
37
     * @var string
38
     */
39
    protected $password;
40
41
    /**
42
     * @var string
43
     */
44
    protected $accept;
45
46
    /**
47
     * @param string                 $username
48
     * @param string                 $password
49
     * @param string                 $accept
50
     * @param Browser|null           $browser
51
     */
52
    public function __construct($username, $password, $accept, Browser $browser = null)
53
    {
54
        $this->browser = $browser ?: new Browser(function_exists('curl_exec') ? new Curl() : new FileGetContents());
55
        $this->username = $username;
56
        $this->password = $password;
57
        $this->accept = $accept;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function get($url)
64
    {
65
        $headers = [
66
            'sfusername: ' . $this->username,
67
            'sfpassword: ' . $this->password,
68
            'Accept: ' . $this->accept,
69
        ];
70
        $response = $this->browser->get($url, $headers);
71
        $this->handleResponse($response);
0 ignored issues
show
$response of type object<Buzz\Message\MessageInterface> is not a sub-type of object<Buzz\Message\Response>. It seems like you assume a concrete implementation of the interface Buzz\Message\MessageInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
72
        return $response->getContent();
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function delete($url)
79
    {
80
        $response = $this->browser->delete($url);
81
        $this->handleResponse($response);
0 ignored issues
show
$response of type object<Buzz\Message\MessageInterface> is not a sub-type of object<Buzz\Message\Response>. It seems like you assume a concrete implementation of the interface Buzz\Message\MessageInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 View Code Duplication
    public function put($url, $content = '')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $headers = [
90
            'sfusername: ' . $this->username,
91
            'sfpassword: ' . $this->password,
92
            'Accept: ' . $this->accept,
93
        ];
94
        if (is_array($content)) {
95
            $content = json_encode($content);
96
            $headers[] = 'Content-Type: application/json';
97
        }
98
        $response = $this->browser->put($url, $headers, $content);
99
        $this->handleResponse($response);
0 ignored issues
show
$response of type object<Buzz\Message\MessageInterface> is not a sub-type of object<Buzz\Message\Response>. It seems like you assume a concrete implementation of the interface Buzz\Message\MessageInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
100
        return $response->getContent();
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 View Code Duplication
    public function post($url, $content = '')
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108
        $headers = [
109
            'sfusername: ' . $this->username,
110
            'sfpassword: ' . $this->password,
111
            'Accept: ' . $this->accept,
112
        ];
113
        if (is_array($content)) {
114
            $content = json_encode($content);
115
            $headers[] = 'Content-Type: application/json';
116
        }
117
        $response = $this->browser->post($url, $headers, $content);
118
        $this->handleResponse($response);
0 ignored issues
show
$response of type object<Buzz\Message\MessageInterface> is not a sub-type of object<Buzz\Message\Response>. It seems like you assume a concrete implementation of the interface Buzz\Message\MessageInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
119
        return $response->getContent();
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    public function getLatestResponseHeaders()
126
    {
127
        if (null === $response = $this->browser->getLastResponse()) {
128
            return;
129
        }
130
        return [
131
            'reset' => (int) $response->getHeader('RateLimit-Reset'),
132
            'remaining' => (int) $response->getHeader('RateLimit-Remaining'),
133
            'limit' => (int) $response->getHeader('RateLimit-Limit'),
134
        ];
135
    }
136
137
    /**
138
     * @param Response $response
139
     *
140
     * @throws HttpException
141
     */
142
    protected function handleResponse(Response $response)
143
    {
144
        if ($response->isSuccessful()) {
145
            return;
146
        }
147
        $this->handleError($response);
148
    }
149
150
    /**
151
     * @param Response $response
152
     *
153
     * @throws HttpException
154
     */
155
    protected function handleError(Response $response)
156
    {
157
        $body = (string) $response->getContent();
158
        $code = (int) $response->getStatusCode();
159
        $content = json_decode($body);
160
        throw new HttpException(isset($content->message) ? $content->message : 'Request not processed.', $code);
161
    }
162
}
163