Issues (23)

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/Pinterest/Http/BuzzClient.php (3 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 Pinterest PHP library.
5
 *
6
 * (c) Hans Ott <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.md.
10
 *
11
 * Source: https://github.com/hansott/pinterest-php
12
 */
13
14
namespace Pinterest\Http;
15
16
use Exception;
17
use Buzz\Browser;
18
use Pinterest\Image;
19
use Buzz\Client\Curl;
20
use Buzz\Message\Form\FormUpload;
21
use Buzz\Message\Form\FormRequest;
22
use Buzz\Exception\RequestException;
23
use Buzz\Message\Response as BuzzResponse;
24
25
/**
26
 * The implemented http client class (uses Buzz).
27
 *
28
 * @link https://github.com/kriswallsmith/Buzz
29
 *
30
 * @author Toon Daelman <[email protected]>
31
 */
32
class BuzzClient implements ClientInterface
33
{
34
    /**
35
     * Buzz browser.
36
     *
37
     * @var Browser
38
     */
39
    private $client;
40
41
    /**
42
     * Creates a new buzz client.
43
     *
44
     * @param \Buzz\Client\ClientInterface|null $client
45
     */
46 60
    public function __construct(\Buzz\Client\ClientInterface $client = null)
47
    {
48 60
        if ($client instanceof ClientInterface) {
49
            $this->client = $client;
50
        } else {
51
            // Backwards compatible
52 60
            $curl = new Curl();
53 60
            $this->client = new Browser($curl);
54
        }
55 60
    }
56
57
    /**
58
     * Converts a buzz response to a pinterest response.
59
     *
60
     * @param Request      $request      The request.
61
     * @param BuzzResponse $buzzResponse The buzz response.
62
     *
63
     * @return Response The response.
64
     */
65 20
    private static function convertResponse(Request $request, BuzzResponse $buzzResponse)
66
    {
67 20
        $statusCode = $buzzResponse->getStatusCode();
68 20
        $rawBody = (string) $buzzResponse->getContent();
69
70 20
        $rawHeaders = $buzzResponse->getHeaders();
71 20
        $headers = array();
72 20
        foreach ($rawHeaders as $header) {
73 20
            if (stristr($header, 'HTTP/1.')) {
74 20
                continue;
75
            }
76
77 20
            $parts = explode(': ', $header);
78
79 20
            if (count($parts) !== 2) {
80
                $headers[$parts[0]] = '';
81
                continue;
82
            }
83
84 20
            list ($key, $value) = $parts;
85 20
            $headers[$key] = $value;
86 10
        }
87
88 20
        return new Response($request, $statusCode, $rawBody, $headers);
89
    }
90
91
    /**
92
     * Executes a http request.
93
     *
94
     * @param Request $request The http request.
95
     *
96
     * @return Response The http response.
97
     */
98 20
    public function execute(Request $request)
99
    {
100 20
        $method = $request->getMethod();
101 20
        $endpoint = $request->getEndpoint();
102 20
        $params = $request->getParams();
103 20
        $headers = $request->getHeaders();
104
105
        try {
106 20
            if ($method === 'GET') {
107 10
                $buzzResponse = $this->client->call(
108 10
                    $endpoint.'?'.http_build_query($params),
109 10
                    $method,
110 10
                    $headers,
111 10
                    array()
0 ignored issues
show
array() is of type array, but the function expects a string.

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...
112 5
                );
113 5
            } else {
114 10
                $buzzRequest = new FormRequest();
115 10
                $buzzRequest->fromUrl($endpoint);
116 10
                $buzzRequest->setMethod($method);
117 10
                $buzzRequest->setHeaders($headers);
118 10
                foreach ($params as $key => $value) {
119 10
                    if ($value instanceof Image) {
120 2
                        $value = new FormUpload($value->getData());
121 1
                    }
122
123 10
                    $buzzRequest->setField($key, $value);
124 5
                }
125
126 10
                $buzzResponse = new BuzzResponse();
127 15
                $this->client->send($buzzRequest, $buzzResponse);
128
            }
129 10
        } catch (RequestException $e) {
130
            throw new Exception($e->getMessage());
131
        }
132
133 20
        return static::convertResponse($request, $buzzResponse);
0 ignored issues
show
Since convertResponse() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of convertResponse() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
$buzzResponse 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...
134
    }
135
}
136