Issues (318)

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/Http/Client.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
namespace SevenShores\Hubspot\Http;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use Psr\Http\Message\ResponseInterface;
7
use SevenShores\Hubspot\Exceptions\BadRequest;
8
use SevenShores\Hubspot\Exceptions\InvalidArgument;
9
10
class Client
11
{
12
    /** @var string */
13
    public $key;
14
    /** @var bool */
15
    public $oauth;
16
17
    /** @var bool */
18
    public $oauth2;
19
20
    /** @var int */
21
    public $userId;
22
23
    /** @var \GuzzleHttp\Client */
24
    public $client;
25
26
    /**
27
     * Guzzle allows options into its request method. Prepare for some defaults
28
     * @var array
29
     */
30
    protected $clientOptions = [];
31
32
    /**
33
     * if set to false, no Response object is created, but the one from Guzzle is directly returned
34
     * comes in handy own error handling
35
     *
36
     * @var bool
37
     */
38
    protected $wrapResponse = true;
39
40
    /** @var string */
41
    private $user_agent = "SevenShores_Hubspot_PHP/1.0.0-rc.1 (https://github.com/ryanwinchester/hubspot-php)";
42
43
    /**
44
     * Make it, baby.
45
     *
46
     * @param  array $config Configuration array
47
     * @param  GuzzleClient $client The Http Client (Defaults to Guzzle)
48
     * @param array $clientOptions options to be passed to Guzzle upon each request
49
     * @param bool $wrapResponse wrap request response in own Response object
50
     */
51
    public function __construct($config = [], $client = null, $clientOptions = [], $wrapResponse = true)
52
    {
53
        $this->clientOptions = $clientOptions;
54
        $this->wrapResponse = $wrapResponse;
55
56
        $this->key = isset($config["key"]) ? $config["key"] : getenv("HUBSPOT_SECRET");
57
        if (empty($this->key)) {
58
            throw new InvalidArgument("You must provide a Hubspot api key or token.");
59
        }
60
61
        if (isset($config['userId'])) {
62
            $this->userId = $config['userId'];
63
        }
64
65
        $this->oauth = isset($config["oauth"]) ? $config["oauth"] : false;
66
        $this->oauth2 = isset($config["oauth2"]) ? $config["oauth2"] : false;
67
        if ($this->oauth && $this->oauth2) {
68
            throw new InvalidArgument("Cannot sign requests with both OAuth1 and OAuth2");
69
        }
70
71
        $this->client = $client ?: new GuzzleClient();
72
    }
73
74
    /**
75
     * Send the request...
76
     *
77
     * @param  string $method The HTTP request verb
78
     * @param  string $endpoint The Hubspot API endpoint
79
     * @param  array $options An array of options to send with the request
80
     * @param  string $query_string A query string to send with the request
81
     * @param  boolean $requires_auth Whether or not this HubSpot API endpoint requires authentication
82
     * @return \SevenShores\Hubspot\Http\Response|ResponseInterface
83
     * @throws \SevenShores\Hubspot\Exceptions\BadRequest
84
     */
85
    public function request($method, $endpoint, $options = [], $query_string = null, $requires_auth = true)
86
    {
87
        $url = $this->generateUrl($endpoint, $query_string, $requires_auth);
88
89
        $options = array_merge($this->clientOptions, $options);
90
        $options["headers"]["User-Agent"] = $this->user_agent;
91
92
        if ($this->oauth2) {
93
            $options["headers"]["Authorization"] = "Bearer " . $this->key;
94
        }
95
96
        try {
97
            if ($this->wrapResponse === false) {
98
                return $this->client->request($method, $url, $options);
99
            }
100
            return new Response($this->client->request($method, $url, $options));
101
        } catch (\GuzzleHttp\Exception\BadResponseException $e) {
102
            throw new BadRequest(\GuzzleHttp\Psr7\str($e->getResponse()), $e->getCode(), $e);
0 ignored issues
show
It seems like $e->getResponse() can be null; however, GuzzleHttp\Psr7\str() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
103
        } catch (\Exception $e) {
104
            throw new BadRequest($e->getMessage(), $e->getCode(), $e);
105
        }
106
    }
107
108
    /**
109
     * Generate the full endpoint url, including query string.
110
     *
111
     * @param  string  $endpoint      The HubSpot API endpoint.
112
     * @param  string  $query_string  The query string to send to the endpoint.
113
     * @param  boolean $requires_auth Whether or not this HubSpot API endpoint requires authentication
114
     * @return string
115
     */
116
    protected function generateUrl($endpoint, $query_string = null, $requires_auth = true)
117
    {
118
        $url = $endpoint."?";
119
120
        if ($requires_auth) {
121
            $authType = $this->oauth ? "access_token" : "hapikey";
122
123
            if (!$this->oauth2) {
124
                $url .= $authType."=".$this->key;
125
126
                if ($this->userId) {
127
                    $url .= "&userId={$this->userId}";
128
                }
129
            } else {
130
                if ($this->userId) {
131
                    $url .= "userId={$this->userId}";
132
                }
133
            }
134
        }
135
136
        return $url.$query_string;
137
    }
138
}
139