Issues (5)

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/PHPushbullet.php (4 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 PHPushbullet;
4
5
/**
6
 * @method array address(string $name, string|array $address)
7
 * @method array file(string $file_name, string $file_url, string $body = null)
8
 * @method array link(string $title, string $url, string $body = null)
9
 * @method array list(string $title, array $items)
10
 * @method array note(string $title, string $body)
11
 */
12
13
class PHPushbullet
14
{
15
    /**
16
     * An instance of the Guzzle client to make requests
17
     *
18
     * @var \GuzzleHttp\Client $api
19
     */
20
    protected $api;
21
22
    /**
23
     * The set of devices we are currently pushing to
24
     *
25
     * @var array $devices
26
     */
27
    protected $devices = [];
28
29
    /**
30
     * The set of users we are currently pushing to,
31
     * an array of emails
32
     *
33
     * @var array $users
34
     */
35
    protected $users = [];
36
37
    /**
38
     * The set of channels we are currntly pushing to
39
     *
40
     * @var array $channels
41
     */
42
    protected $channels = [];
43
44
    /**
45
     * An array of all devices available
46
     *
47
     * @var array $all_devices
48
     */
49
    protected $all_devices = [];
50
51 27
    public function __construct($access_token = null, Connection $connection =  null, array $config = [])
52
    {
53 27
        $access_token = $access_token ?: getenv('pushbullet.access_token');
54
55 27
        if (!$access_token) {
56
            throw new \Exception('Your Pushbullet access token is not set.');
57
        }
58
59 27
        $connection = $connection ?: new Connection($access_token, null, $config);
60
61 27
        $this->api = $connection->client();
62 27
    }
63
64
    /**
65
     * Get a list of all of the devices available
66
     *
67
     * @return array
68
     */
69 12
    public function devices()
70
    {
71 12
        if (empty($this->all_devices)) {
72 12
            $response = $this->fromJson($this->api->get('devices'));
73
74 12
            $this->all_devices = array_map(function ($device) {
75 12
                return new Device($device);
76 12
            }, $response['devices']);
77 12
        }
78
79 12
        return $this->all_devices;
80
    }
81
82 1
    public function user()
83
    {
84 1
        $this->users = array_merge($this->argsToArray(func_get_args()), $this->users);
0 ignored issues
show
func_get_args() is of type array, but the function expects a object<PHPushbullet\type>.

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...
85 1
        $this->users = array_filter($this->users);
86 1
        $this->users = array_unique($this->users);
87
88 1
        return $this;
89
    }
90
91
    /**
92
     * Set the passed in device(s) for the current push
93
     *
94
     * @return \PHPushbullet\PHPushbullet
95
     */
96 11
    public function device()
97
    {
98 11
        $devices = $this->argsToArray(func_get_args());
0 ignored issues
show
func_get_args() is of type array, but the function expects a object<PHPushbullet\type>.

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...
99
100 11
        foreach ($devices as $destination) {
101 11
            $device = $this->getDeviceIden($destination);
102
103 11
            if (!$device) {
104 1
                throw new \Exception("{$destination} is not a valid device.");
105
            }
106
107 10
            $this->devices[] = $device;
108 10
        }
109
110 10
        return $this;
111
    }
112
113
    /**
114
     * Set the passed in channel(s) for the current push
115
     *
116
     * @return \PHPushbullet\PHPushbullet
117
     */
118 2
    public function channel()
119
    {
120 2
        $this->channels = array_merge($this->argsToArray(func_get_args()));
0 ignored issues
show
func_get_args() is of type array, but the function expects a object<PHPushbullet\type>.

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...
121
122 2
        return $this;
123
    }
124
125
    /**
126
     * Set all of the devices for the current push
127
     *
128
     * @return \PHPushbullet\PHPushbullet
129
     */
130
    public function all()
131
    {
132
        foreach ($this->devices() as $device) {
133
            if ($device->pushable == true) {
134
                $this->devices[] = $device->iden;
135
            }
136
        }
137
138
        return $this;
139
    }
140
141
    /**
142
     * Actually send the push
143
     *
144
     * @return array
145
     */
146 14
    public function push($request)
147
    {
148 14
        if (empty($this->devices) && empty($this->users) && empty($this->channels)) {
149 1
            throw new \Exception('You must specify something to push to.');
150
        }
151
152 13
        $responses = [];
153
154
        $destinations = [
155 13
            'devices'  => 'device_iden',
156 13
            'users'    => 'email',
157 13
            'channels' => 'channel_tag',
158 13
        ];
159
160 13
        foreach ($destinations as $destination => $key) {
161 13
            foreach ($this->{$destination} as $dest) {
162 13
                $responses[] = $this->pushRequest($request, [$key => $dest]);
163 13
            }
164 13
        }
165
166 13
        $this->devices  = [];
167 13
        $this->users    = [];
168 13
        $this->channels = [];
169
170 13
        return $responses;
171
    }
172
173
    public function getClient()
174
    {
175
        return $this->api;
176
    }
177
178
    /**
179
     * Create push request and... push it
180
     *
181
     * @param array $request
182
     * @param array $merge
183
     *
184
     * @return array
185
     */
186 13
    protected function pushRequest($request, $merge)
187
    {
188 13
        $request  = array_merge($request, $merge);
189 13
        $response = $this->api->post('pushes', ['json' => $request]);
190
191 13
        return $this->fromJson($response);
192
    }
193
194
    /**
195
     * Get the `iden` for the device by either the iden or nickname
196
     *
197
     * @param string $device
198
     *
199
     * @return mixed (boolean|string)
200
     */
201 11
    protected function getDeviceIden($device)
202
    {
203 11
        foreach ($this->devices() as $available_device) {
204 11
            foreach (['iden', 'nickname'] as $field) {
205 11
                if ($available_device->$field == $device) {
206 10
                    return $available_device->iden;
207
                }
208 11
            }
209 11
        }
210
211 1
        return false;
212
    }
213
214
    /**
215
     * @param type $args
216
     *
217
     * @return array
218
     */
219 14
    protected function argsToArray($args)
220
    {
221 14
        if (is_array($args[0])) {
222
            return $args[0];
223
        }
224
225 14
        return $args;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $args; (PHPushbullet\type) is incompatible with the return type documented by PHPushbullet\PHPushbullet::argsToArray of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
226
    }
227
228 15
    protected function fromJson($response)
229
    {
230 15
        return json_decode((string) $response->getBody(), true);
231
    }
232
233
    /**
234
     * Magic method, figures out what sort of push the user is trying to do
235
     */
236 14
    public function __call($method, $arguments)
237
    {
238 14
        $request_class = 'PHPushbullet\Request\Push' . ucwords($method);
239
240 14
        if (!class_exists($request_class)) {
241
            throw new \Exception(sprintf('Unknown method "%s"', $method));
242
        }
243
244 14
        $class   = new \ReflectionClass($request_class);
245 14
        $request = $class->newInstanceArgs($arguments);
246
247 14
        return $this->push($request->request());
248
    }
249
}
250