Issues (7)

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/Application.php (1 issue)

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 Popstas\Transmission\Console;
4
5
use GuzzleHttp;
6
use InfluxDB;
7
use Popstas\Transmission\Console\Command;
8
use Psr\Log\LoggerInterface;
9
use Stecman\Component\Symfony\Console\BashCompletion;
10
use Symfony\Component\Console\Application as BaseApplication;
11
12
class Application extends BaseApplication
13
{
14
    const VERSION = 'dev';
15
16
    /**
17
     * @var Config $config
18
     */
19
    private $config;
20
21
    /**
22
     * @var LoggerInterface $logger
23
     */
24
    private $logger;
25
26
    /**
27
     * @var TransmissionClient $client
28
     */
29
    private $client;
30
31
    /**
32
     * @var WeburgClient
33
     */
34
    private $weburgClient;
35
36
    /**
37
     * @var InfluxDbClient
38
     */
39
    private $influxDbClient;
40
41
    public function __construct($name = 'Transmission CLI', $version = '@git-version@')
42
    {
43
        parent::__construct($name, $version);
44
    }
45
46
    /**
47
     * @return array|\Symfony\Component\Console\Command\Command[]
48
     */
49
    protected function getDefaultCommands()
50
    {
51
        $commands = array_merge(parent::getDefaultCommands(), [
52
            new BashCompletion\CompletionCommand(),
53
54
            new Command\Docs(),
55
            new Command\StatsGet(),
56
            new Command\StatsSend(),
57
            new Command\TorrentAdd(),
58
            new Command\TorrentList(),
59
            new Command\TorrentRemove(),
60
            new Command\TorrentRemoveDuplicates(),
61
            new Command\WeburgDownload(),
62
            new Command\WeburgInfo(),
63
            new Command\WeburgSeriesAdd(),
64
        ]);
65
        return $commands;
0 ignored issues
show
The expression return $commands; seems to be an array, but some of its elements' types (Stecman\Component\Symfon...Command\WeburgSeriesAdd) are incompatible with the return type of the parent method Symfony\Component\Consol...ion::getDefaultCommands of type array<Symfony\Component\...le\Command\ListCommand>.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
66
    }
67
68
    public function getLongVersion()
69
    {
70
        if (('@' . 'git-version@') !== $this->getVersion()) {
71
            return sprintf(
72
                '<info>%s</info> version <comment>%s</comment> build <comment>%s</comment>',
73
                $this->getName(),
74
                $this->getVersion(),
75
                '@git-commit@'
76
            );
77
        }
78
        return '<info>' . $this->getName() . '</info> (repo)';
79
    }
80
81
    /**
82
     * @return TransmissionClient
83
     */
84
    public function getClient()
85
    {
86
        return $this->client;
87
    }
88
89
    /**
90
     * @param TransmissionClient $client
91
     */
92
    public function setClient($client)
93
    {
94
        $this->client = $client;
95
    }
96
97
    /**
98
     * @return LoggerInterface
99
     */
100
    public function getLogger()
101
    {
102
        return $this->logger;
103
    }
104
105
    /**
106
     * @param LoggerInterface $logger
107
     */
108
    public function setLogger($logger)
109
    {
110
        $this->logger = $logger;
111
    }
112
113
    /**
114
     * @return Config
115
     */
116
    public function getConfig()
117
    {
118
        return $this->config;
119
    }
120
121
    /**
122
     * @param Config $config
123
     */
124
    public function setConfig($config)
125
    {
126
        $this->config = $config;
127
    }
128
129
    public function getWeburgClient()
130
    {
131
        if (!isset($this->weburgClient)) {
132
            $this->weburgClient = $this->createWeburgClient();
133
        }
134
        return $this->weburgClient;
135
    }
136
137
    public function setWeburgClient($weburgClient)
138
    {
139
        $this->weburgClient = $weburgClient;
140
    }
141
142
    public function createWeburgClient()
143
    {
144
        $config = $this->getConfig();
145
        $requestDelay = $config->get('weburg-request-delay');
146
        $httpClient = new GuzzleHttp\Client([
147
            'allow_redirects' => [
148
                'max'             => 10,
149
                'strict'          => false,
150
                'referer'         => false,
151
                'protocols'       => ['http', 'https'],
152
                'track_redirects' => false,
153
            ],
154
        ]);
155
        return new WeburgClient($httpClient, $requestDelay);
156
    }
157
158
    /**
159
     * @param $host
160
     * @param $port
161
     * @param $user
162
     * @param $password
163
     * @param $databaseName
164
     * @return InfluxDbClient
165
     * @throws InfluxDB\Database\Exception
166
     */
167
    public function getInfluxDbClient($host, $port, $user, $password, $databaseName)
168
    {
169
        if (!isset($this->influxDbClient)) {
170
            $this->influxDbClient = $this->createInfluxDbClient($host, $port, $user, $password, $databaseName);
171
        }
172
        return $this->influxDbClient;
173
    }
174
175
    /**
176
     * @param InfluxDbClient $influxDbClient
177
     */
178
    public function setInfluxDbClient($influxDbClient)
179
    {
180
        $this->influxDbClient = $influxDbClient;
181
    }
182
183
    /**
184
     * @param $host
185
     * @param $port
186
     * @param $user
187
     * @param $password
188
     * @param $databaseName
189
     * @return InfluxDbClient
190
     * @throws InfluxDB\Database\Exception
191
     */
192
    public function createInfluxDbClient($host, $port, $user, $password, $databaseName)
193
    {
194
        $influxDb = new InfluxDB\Client($host, $port, $user, $password);
195
        $connect = ['host' => $host, 'port' => $port, 'user' => $user, 'password' => $password];
196
        $this->logger->debug('Connect InfluxDB using: {user}:{password}@{host}:{port}', $connect);
197
198
        if (!$databaseName) {
199
            throw new \RuntimeException('InfluxDb database not defined');
200
        }
201
202
        $influxDbClient = new InfluxDbClient($influxDb, $databaseName);
203
        $influxDbClient->setLogger($this->logger);
204
205
        return $influxDbClient;
206
    }
207
}
208