Issues (15)

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/Module.php (4 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
 * Yii2 Dumpling.
4
 *
5
 * This file contains Dumpling module.
6
 *
7
 * @author  Alexei Korotin <[email protected]>
8
 */
9
10
namespace herroffizier\yii2dumpling;
11
12
use Yii;
13
use yii\base\BootstrapInterface;
14
use yii\base\InvalidParamException;
15
use yii\base\NotSupportedException;
16
use yii\db\Connection;
17
18
/**
19
 * Dumpling module.
20
 *
21
 * Acts like a facade for actual dumpers.
22
 */
23
class Module extends \yii\base\Module implements BootstrapInterface
24
{
25
    /**
26
     * Default database component.
27
     *
28
     * @var string
29
     */
30
    public $defaultDbComponent = 'db';
31
32
    /**
33
     * Default name for dump file.
34
     *
35
     * Aliases supported.
36
     *
37
     * @var string
38
     */
39
    public $defaultDumpFile = '@app/runtime/dump.sql';
40
41
    /**
42
     * Array of dumpers for different databases.
43
     *
44
     * Keys must be a valid DSN prefix.
45
     *
46
     * Values must be either a string which represents dumper class name
47
     * or an array with 'class' field.
48
     * Values are passed to Yii::createObject() method.
49
     *
50
     * @var mixed
51
     */
52
    public $dumpers = [
53
        'mysql' => [
54
            'class' => 'herroffizier\yii2dumpling\dumpers\MysqlDumper',
55
        ],
56
    ];
57
58
    /**
59
     * @param mixed $app
60
     * @codeCoverageIgnore
61
     */
62
    public function bootstrap($app)
63
    {
64
        $app->set($this->id, $this);
65
66
        if ($app instanceof \yii\console\Application) {
67
            $app->controllerMap[$this->id] = [
68
                'class' => 'herroffizier\yii2dumpling\commands\Controller',
69
                'module' => $this,
70
            ];
71
        }
72
    }
73
74
    /**
75
     * Parse DSN string into array.
76
     *
77
     * @param string $dsn
78
     *
79
     * @return string[]
80
     */
81 15
    protected function parseDsn($dsn)
82
    {
83 15
        list($driverName, $dsn) = explode(':', $dsn, 2);
84
85 15
        $values = ['driverName' => $driverName];
86 15
        $options = explode(';', $dsn);
87 15
        foreach ($options as $option) {
88
            // Some options in DSN may be a single string.
89 15
            if (mb_strpos($option, '=') !== false) {
90 12
                list($key, $value) = explode('=', $option, 2);
91 12
                $values[$key] = $value;
92 8
            } else {
93 7
                $values[] = $option;
94
            }
95 10
        }
96
97 15
        return $values;
98
    }
99
100 15
    protected function createDumper(Connection $dbComponent)
101
    {
102 15
        $dsn = $this->parseDsn($dbComponent->dsn);
103
104 15
        if (!isset($this->dumpers[$dsn['driverName']])) {
105 3
            throw new NotSupportedException('Cannot handle '.$dsn['driverName'].' db');
106
        }
107
108 12
        $dumper = Yii::createObject(
109 12
            $this->dumpers[$dsn['driverName']],
110
            [
111 12
                $dsn,
112 12
                $dbComponent->username,
113 12
                $dbComponent->password,
114
            ]
115 8
        );
116
117 12
        return $dumper;
118
    }
119
120 15
    protected function getDbComponent($db)
121
    {
122 15
        if (!$db) {
123 12
            $db = $this->defaultDbComponent;
124 8
        }
125
126 15
        $component = Yii::$app->{$db};
127
128 15
        if (!($component instanceof Connection)) {
129 3
            throw new InvalidParamException($db.' is not an '.Connection::className().' instance');
130
        }
131
132 15
        return $component;
133
    }
134
135 15
    protected function getDumpFilePath($file)
136
    {
137 15
        if (!$file) {
138 6
            $file = $this->defaultDumpFile;
139 4
        }
140
141 15
        return Yii::getAlias($file);
142
    }
143
144
    /**
145
     * Dump database to file.
146
     *
147
     * If file or db params are not specified, default values will be used.
148
     *
149
     * @param string $file
0 ignored issues
show
Should the type for parameter $file not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
150
     * @param string $db
0 ignored issues
show
Should the type for parameter $db not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
151
     */
152 9 View Code Duplication
    public function dump($file = null, $db = null)
153
    {
154 9
        $dbComponent = $this->getDbComponent($db);
155 9
        $filePath = $this->getDumpFilePath($file);
156
157 9
        $dumper = $this->createDumper($dbComponent);
158
159 6
        $dumper->dump($filePath);
160 6
    }
161
162
    /**
163
     * Restore database from file.
164
     *
165
     * If file or db params are not specified, default values will be used.
166
     *
167
     * @param string $file
0 ignored issues
show
Should the type for parameter $file not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
168
     * @param string $db
0 ignored issues
show
Should the type for parameter $db not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
169
     */
170 6 View Code Duplication
    public function restore($file = null, $db = null)
171
    {
172 6
        $dbComponent = $this->getDbComponent($db);
173 6
        $filePath = $this->getDumpFilePath($file);
174
175 6
        $dumper = $this->createDumper($dbComponent);
176
177 6
        $dumper->restore($filePath);
178 6
    }
179
}
180