Issues (36)

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/Api/WuBookApi.php (6 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 Laravel WuBook.
5
 *
6
 * (c) Filippo Galante <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace IlGala\LaravelWubook\Api;
13
14
use IlGala\LaravelWubook\Api\WuBookAuth;
15
use IlGala\LaravelWubook\Exceptions\WuBookException;
16
17
/**
18
 * This is the WuBook api abstract class.
19
 *
20
 * @author ilgala
21
 */
22
abstract class WuBookApi
23
{
24
25
    /**
26
     * @var array
27
     */
28
    protected $config;
29
30
    /**
31
     * @var Illuminate\Cache\Repository
32
     */
33
    protected $cache;
34
35
    /**
36
     * @var fXmlRpc\Client
37
     */
38
    protected $client;
39
40
    /**
41
     * @var IlGala\LaravelWubook\Api\WuBookAuth
42
     */
43
    protected $auth;
44
45
    /**
46
     * Creates a new WuBookAuth instance.
47
     *
48
     * @param array $config
49
     * @param Illuminate\Cache\Repository $cache
50
     * @param fXmlRpc\Client $client
51
     */
52
    public function __construct($config, Repository $cache, Client $client)
53
    {
54
        $this->config = $config;
55
        $this->cache = $cache;
0 ignored issues
show
Documentation Bug introduced by
It seems like $cache of type object<IlGala\LaravelWubook\Api\Repository> is incompatible with the declared type object<IlGala\LaravelWub...inate\Cache\Repository> of property $cache.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
        $this->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type object<IlGala\LaravelWubook\Api\Client> is incompatible with the declared type object<IlGala\LaravelWubook\Api\fXmlRpc\Client> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
57
        $this->auth = new WuBookAuth($config, $cache, $client);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \IlGala\LaravelWuboo...onfig, $cache, $client) of type object<IlGala\LaravelWubook\Api\WuBookAuth> is incompatible with the declared type object<IlGala\LaravelWub...lWubook\Api\WuBookAuth> of property $auth.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
58
    }
59
60
    /**
61
     * Prepends token and lcode or custom parameters
62
     *
63
     * @param mixed $params
64
     */
65
    protected function setup_client($params)
66
    {
67
        if (!is_array($params)) {
68
            // Setup params
69
            $params = [
0 ignored issues
show
$params is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
                $this->get_token($params),
71
                $this->config['lcode']
72
            ];
73
        }
74
75
        $this->client->prependParams($token);
0 ignored issues
show
The variable $token does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
76
    }
77
78
    /**
79
     * Validate and, if necessary, retrieves a token or the cached token
80
     *
81
     * @param string $token
82
     * @return string
83
     * @throws WuBookException
84
     */
85
    protected function get_token($token)
86
    {
87
        // Check token
88
        if (empty($token) && $this->config['cache_token']) {
89
            $token = $this->cache->get('wubook.token');
90
        }
91
92
        $response = $this->auth->is_token_valid($token, $this->config['cache_token']);
93
94
        if (is_int($response)) {
95
            // If response is integer => valid token
96
            return $token;
97
        } elseif (is_string($response)) {
98
            // If response is string => new token
99
            return $response;
100
        } else {
101
            // Error
102
            throw new WuBookException('Token is empty or invalid');
103
        }
104
    }
105
106
    /**
107
     * Calls a wired API function.
108
     *
109
     * @param string $token
110
     * @param string $method
111
     * @param array $data
112
     * @return array
113
     * @throws WuBookException
114
     */
115
    protected function call_method($token, $method, $data = [])
116
    {
117
        if ($this->config['cache_token']) {
118
            // Check total operations
119
            $operations = $this->cache->get('wubook.token.ops');
120
            $operations++;
121
122
            if ($operations >= 60) {
123
                // Exceeded max ops, renew token
124
                $this->auth->release_token($this->get_token($token));
125
                $this->auth->acquire_token();
126
            }
127
        }
128
129
        // Setup client
130
        $this->setup_client($token);
131
132
        try {
133
            // Retrieve response
134
            $response = $this->client->call($method, $data);
135
136
            return [
137
                'has_error' => $response[0] != 0,
138
                'data' => $response[1]
139
            ];
140
        } catch (AbstractTransportException $error) {
0 ignored issues
show
The class IlGala\LaravelWubook\Api...tractTransportException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
141
            throw new WuBookException($error->getMessage(), $error->getCode(), $error);
142
        } finally {
143
            if ($this->config['cache_token']) {
144
                // Increment total operations
145
                $this->cache->increment('wubook.token.ops');
146
            }
147
        }
148
    }
149
}
150