Issues (21)

Security Analysis    not enabled

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/Providers/ProviderBase.php (2 issues)

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
namespace SocialLinks\Providers;
4
5
use SocialLinks\Page;
6
use DOMDocument;
7
8
/**
9
 * Base class extended by all providers.
10
 *
11
 * @property string   $shareUrl
12
 * @property null|int $shareCount
13
 */
14
abstract class ProviderBase
15
{
16
    protected $page;
17
18
    const RFC1738 = 1;
19
    const RFC3986 = 2;
20
21
    /**
22
     * Constructor.
23
     *
24
     * @param Page $page
25
     */
26
    public function __construct(Page $page)
27
    {
28
        $this->page = $page;
29
    }
30
31
    /**
32
     * Magic method to calculate and store the properties.
33
     */
34
    public function __get($key)
35
    {
36
        switch ($key) {
37
            case 'shareUrl':
38
                return $this->shareUrl = $this->shareUrl();
39
40
            case 'shareCount':
41
                $request = $this->shareCountRequest();
0 ignored issues
show
Are you sure the assignment to $request is correct as $this->shareCountRequest() (which targets SocialLinks\Providers\Pr...se::shareCountRequest()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
43
                if ($request !== null) {
44
                    $response = curl_exec($request) ?: '';
45
                    curl_close($request);
46
47
                    return $this->shareCount = $this->shareCount($response);
0 ignored issues
show
Are you sure the assignment to $this->shareCount is correct as $this->shareCount($response) (which targets SocialLinks\Providers\ProviderBase::shareCount()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
48
                }
49
50
                return $this->shareCount = null;
51
        }
52
    }
53
54
    /**
55
     * Default shareCount function for providers without count api.
56
     *
57
     * {@inheritdoc}
58
     */
59
    public function shareCount($response)
60
    {
61
        return;
62
    }
63
64
    /**
65
     * Default shareCountRequest function for providers without count api.
66
     *
67
     * {@inheritdoc}
68
     */
69
    public function shareCountRequest()
70
    {
71
        return;
72
    }
73
74
    /**
75
     * Generates a valid url.
76
     *
77
     * @param string $url
78
     * @param array  $pageParams parameters to be taken from page fields as $paramName  => $paramNameInTheURL
79
     * @param array  $getParams  extra parameters as $key => $value
80
     * @param int    $encoding   Type of encoding used. It can be static::RFC3986 or static::RFC1738
81
     */
82
    protected function buildUrl($url, array $pageParams = null, array $getParams = array(), $encoding = self::RFC1738)
83
    {
84
        if ($pageParams) {
85
            $getParams += $this->page->get($pageParams);
86
        }
87
88
        if (empty($getParams)) {
89
            return $url;
90
        }
91
92
        if ($encoding === static::RFC1738) {
93
            return $url.'?'.http_build_query($getParams);
94
        }
95
96
        $get = array();
97
98
        foreach ($getParams as $name => $value) {
99
            $get[] = $name.'='.rawurlencode($value);
100
        }
101
102
        return $url.'?'.implode(ini_get('arg_separator.output'), $get);
103
    }
104
105
    /**
106
     * Build a curl request.
107
     *
108
     * @param string      $url
109
     * @param bool|string $post
110
     * @param array       $headers
111
     *
112
     * @return resource
113
     */
114
    protected static function request($url, $post = false, array $headers = null)
115
    {
116
        $connection = curl_init();
117
118
        curl_setopt_array($connection, array(
119
            CURLOPT_URL => $url,
120
            CURLOPT_RETURNTRANSFER => true,
121
            CURLOPT_FOLLOWLOCATION => true,
122
            CURLOPT_MAXREDIRS => 20,
123
            CURLOPT_CONNECTTIMEOUT => 10,
124
            CURLOPT_TIMEOUT => 10,
125
            CURLOPT_SSL_VERIFYPEER => false,
126
            CURLOPT_SSL_VERIFYHOST => false,
127
            CURLOPT_ENCODING => '',
128
            CURLOPT_AUTOREFERER => true,
129
            CURLOPT_USERAGENT => 'SocialLinks PHP Library',
130
        ));
131
132
        if (!empty($post)) {
133
            curl_setopt($connection, CURLOPT_POST, true);
134
135
            if (is_string($post)) {
136
                curl_setopt($connection, CURLOPT_POSTFIELDS, $post);
137
            }
138
        }
139
140
        if (!empty($headers)) {
141
            curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
142
        }
143
144
        return $connection;
145
    }
146
147
    /**
148
     * Handle JSON responses.
149
     *
150
     * @param string $content
151
     *
152
     * @return array|false
153
     */
154
    protected static function jsonResponse($content)
155
    {
156
        return json_decode($content, true);
157
    }
158
159
    /**
160
     * Handle JSONP responses.
161
     *
162
     * @param string $content
163
     *
164
     * @return array|false
165
     */
166
    protected static function jsonpResponse($content)
167
    {
168
        preg_match("/^\w+\((.*)\)$/", $content, $matches);
169
170
        return json_decode($matches[1], true);
171
    }
172
173
    /**
174
     * Handle HTML responses.
175
     *
176
     * @param string $content
177
     *
178
     * @return DOMDocument
179
     */
180
    protected static function htmlResponse($content)
181
    {
182
        $errors = libxml_use_internal_errors(true);
183
        $document = new DOMDocument();
184
        $document->loadHTML($content);
185
        libxml_use_internal_errors($errors);
186
187
        return $document;
188
    }
189
}
190