Issues (4)

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/Bitly.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
namespace LeadThread\Bitly;
4
5
use LeadThread\Bitly\Exceptions\BitlyAuthException;
6
use LeadThread\Bitly\Exceptions\BitlyErrorException;
7
use LeadThread\Bitly\Exceptions\BitlyRateLimitException;
8
use GuzzleHttp\Client;
9
10
class Bitly
11
{
12
    const V3 = 'v3';
13
14
    protected $host;
15
    protected $version;
16
    protected $client;
17
    protected $token;
18
19
    /**
20
     * Creates a Bitly instance that can register and unregister webhooks with the API
21
     * @param string $token   The API token to authenticate with
22
     * @param string $version The API version to use
23
     * @param string $host    The Host URL
24
     * @param string $client  The Client instance that will handle the http request
25
     */
26 27
    public function __construct($token, $version = self::V3, $host = "api-ssl.bitly.com", Client $client = null){
27 27
        $this->client = $client;
28 27
        $this->token = $token;
29 27
        $this->version = $version;
30 27
        $this->host = $host;
31 27
    }
32
33 12
    public function shorten($url, $encode = true)
34
    {
35 12
        if (empty($url)) {
36 3
            throw new BitlyErrorException("The URL is empty!");
37
        }
38
39 9
        $url = $this->fixUrl($url, $encode);
40
41 9
        $data = $this->exec($this->buildRequestUrl($url));
42
            
43 6
        return $data['data']['url'];
44
    }
45
46
    /**
47
     * Returns the response data or throws an Exception if it was unsuccessful
48
     * @param  string $raw The data from the response
49
     * @return array
50
     */
51 9
    protected function handleResponse($raw){
52 9
        $data = json_decode($raw,true);
53
54 9
        if(!isset($data['status_code'])){
55
            return $raw;
56
        }
57
58 9
        if($data['status_code']>=300 || $data['status_code']<200){
59 3
            switch ($data['status_txt']) {
60 3
                case 'RATE_LIMIT_EXCEEDED':
61
                    throw new BitlyRateLimitException;
62
                    break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
63
64 3
                case 'INVALID_LOGIN':
65
                    throw new BitlyAuthException;
66
                    break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
67
68 3
                default:
69 3
                    throw new BitlyErrorException($data['status_txt']);
70
                    break;
0 ignored issues
show
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
71 3
            }
72
        }
73 6
        return $data;
74
    }
75
76
    /**
77
     * Returns a corrected URL
78
     * @param  string  $url    The URL to modify
79
     * @param  boolean $encode Whether or not to encode the URL
80
     * @return string          The corrected URL
81
     */
82 18
    protected function fixUrl($url, $encode){
83 18
        if(strpos($url, "http") !== 0){
84 12
            $url = "http://".$url;
85 12
        }
86
87 18
        if($encode){
88 12
            $url = urlencode($url);
89 12
        }
90
91 18
        return $url;
92
    }
93
94
    /**
95
     * Builds the request URL to the Bitly API for a specified action
96
     * @param  string $action The long URL
97
     * @param  string $action The API action
98
     * @return string         The URL
99
     */
100 12
    protected function buildRequestUrl($url,$action = "shorten"){
101 12
        return "https://{$this->host}/{$this->version}/{$action}?access_token={$this->token}&format=json&longUrl={$url}";
102
    }
103
104
    /**
105
     * Returns the Client instance
106
     * @return Client
107
     */
108 9
    protected function getRequest(){
109 9
        $client = $this->client;
110 9
        if(!$client instanceof Client){
111
            $client = new Client();
112
        }
113 9
        return $client;
114
    }
115
116
    /**
117
     * Executes a CURL request to the Bitly API
118
     * @param  string $url    The URL to send to
119
     * @return mixed          The response data
120
     */ 
121 9
    protected function exec($url)
122
    {
123 9
        $client = $this->getRequest();
124 9
        $response = $client->request('GET',$url);
125 9
        return $this->handleResponse($response->getBody());
126
    }
127
}
128