Issues (40)

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

Labels
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
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/PhpPulse/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\DaPulse\Objects;
9
10
use allejo\DaPulse\PulseUser;
11
12
/**
13
 * A class representing a Pulse object which supports subscribers
14
 *
15
 * @internal
16
 * @package allejo\DaPulse\Objects
17
 * @since   0.1.0
18
 */
19
abstract class SubscribableObject extends ApiObject
20
{
21
    /**
22
     * @var PulseUser[]
23
     */
24
    protected $subscribers;
25
26
    /**
27
     * The objects's unique identifier.
28
     *
29
     * @return int
30
     */
31 52
    public function getId ()
32
    {
33 52
        return $this->id;
34
    }
35
36
    /**
37
     * Get the users who are subscribed to this object
38
     *
39
     * ```
40
     * array['page']     int - Page offset to fetch
41
     *      ['per_page'] int - Number of results to return per page
42
     *      ['offset']   int - Pad a number of results
43
     * ```
44
     *
45
     * @api
46
     *
47
     * @param  array $params     GET parameters passed to the URL (see above)
48
     * @param  bool  $forceFetch When set to true, this will force an API call to retrieve the subscribers. Otherwise,
49
     *                           this'll return the cached subscribers.
50
     *
51
     * @since  0.1.0
52
     *
53
     * @return PulseUser[]
54
     */
55 5
    public function getSubscribers ($params = [], $forceFetch = false)
56
    {
57 5
        if (is_null($this->subscribers) || $forceFetch)
58
        {
59 5
            $url               = sprintf("%s/%d/subscribers.json", $this::apiEndpoint(), $this->getId());
60 5
            $this->subscribers = self::fetchAndCastToObjectArray($url, "PulseUser", $params);
61
        }
62
63 5
        self::lazyCastAll($this->subscribers, 'PulseUser');
64
65 5
        return $this->subscribers;
66
    }
67
68
    /**
69
     * Subscriber a user to a object
70
     *
71
     * @api
72
     *
73
     * @param  int|PulseUser $userId  The user that will be subscribed to the board
74
     * @param  bool|null     $asAdmin Set to true if the user will be an admin of the board
75
     *
76
     * @since  0.3.0 A PulseUser object of the newly added subscriber is returned
77
     * @since  0.1.0
78
     *
79
     * @return PulseUser
80
     */
81 1
    public function addSubscriber ($userId, $asAdmin = null)
82
    {
83 1
        $userId = ($userId instanceof PulseUser) ? $userId->getId() : $userId;
84 1
        $url    = sprintf("%s/%d/subscribers.json", self::apiEndpoint(), $this->getId());
85
        $params = [
86 1
            "user_id" => $userId
87
        ];
88
89 1
        self::setIfNotNullOrEmpty($params, "as_admin", $asAdmin);
90 1
        $newSubscriber = self::sendPut($url, $params);
91
92
        // Save the user to the local cache
93 1
        if (is_null($this->subscribers))
94
        {
95 1
            $this->getSubscribers();
96
        }
97
98 1
        $user                = new PulseUser($newSubscriber);
99 1
        $this->subscribers[] = $user;
100
101 1
        return $user;
102
    }
103
104
    /**
105
     * Unsubscribe a user from this object
106
     *
107
     * @api
108
     *
109
     * @param  int|PulseUser $userId The user that will be unsubscribed from the board
110
     *
111
     * @since  0.3.0 A PulseUser object of the removed subscriber is returned
112
     * @since  0.1.0
113
     *
114
     * @return PulseUser
115
     */
116 1
    public function removeSubscriber ($userId)
117
    {
118 1
        $userId = ($userId instanceof PulseUser) ? $userId->getId() : $userId;
119 1
        $url    = sprintf("%s/%d/subscribers/%d.json", self::apiEndpoint(), $this->getId(), $userId);
120 1
        $result = self::sendDelete($url);
121
122
        // Remove the user from the local cache
123 1
        if (is_null($this->subscribers))
124
        {
125 1
            $this->getSubscribers();
126
        }
127
128 1
        foreach ($this->subscribers as $key => $subscriber)
0 ignored issues
show
The expression $this->subscribers of type null|array<integer,objec...ejo\DaPulse\PulseUser>> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
129
        {
130 1
            if ($subscriber->getId() == $result['id'])
131
            {
132 1
                unset($this->subscribers[$key]);
133
            }
134
        }
135
136 1
        return (new PulseUser($result));
137
    }
138
}