Issues (10)

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/Databases/MongoDb.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 Spatie\DbDumper\Databases;
4
5
use Spatie\DbDumper\DbDumper;
6
use Spatie\DbDumper\Exceptions\CannotStartDump;
7
use Symfony\Component\Process\Process;
8
9
class MongoDb extends DbDumper
10
{
11
    protected $port = 27017;
12
13
    /** @var null|string */
14
    protected $collection = null;
15
16
    /** @var null|string */
17
    protected $authenticationDatabase = null;
18
19
    /**
20
     * Dump the contents of the database to the given file.
21
     *
22
     * @param string $dumpFile
23
     *
24
     * @throws \Spatie\DbDumper\Exceptions\CannotStartDump
25
     * @throws \Spatie\DbDumper\Exceptions\DumpFailed
26
     */
27 View Code Duplication
    public function dumpToFile(string $dumpFile)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $this->guardAgainstIncompleteCredentials();
30
31
        $command = $this->getDumpCommand($dumpFile);
32
33
        $process = Process::fromShellCommandline($command, null, null, null, $this->timeout);
34
35
        $process->run();
36
37
        $this->checkIfDumpWasSuccessFul($process, $dumpFile);
38
    }
39
40
    /**
41
     * Verifies if the dbname and host options are set.
42
     *
43
     * @throws \Spatie\DbDumper\Exceptions\CannotStartDump
44
     * @return void
45
     */
46
    protected function guardAgainstIncompleteCredentials()
47
    {
48 View Code Duplication
        foreach (['dbName', 'host'] as $requiredProperty) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
            if (strlen($this->$requiredProperty) === 0) {
50
                throw CannotStartDump::emptyParameter($requiredProperty);
51
            }
52
        }
53
    }
54
55
    /**
56
     * @param string $collection
57
     *
58
     * @return \Spatie\DbDumper\Databases\MongoDb
59
     */
60
    public function setCollection(string $collection)
61
    {
62
        $this->collection = $collection;
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param string $authenticationDatabase
69
     *
70
     * @return \Spatie\DbDumper\Databases\MongoDb
71
     */
72
    public function setAuthenticationDatabase(string $authenticationDatabase)
73
    {
74
        $this->authenticationDatabase = $authenticationDatabase;
75
76
        return $this;
77
    }
78
79
    /**
80
     * Generate the dump command for MongoDb.
81
     *
82
     * @param string $filename
83
     *
84
     * @return string
85
     */
86
    public function getDumpCommand(string $filename): string
87
    {
88
        $quote = $this->determineQuote();
89
90
        $command = [
91
            "{$quote}{$this->dumpBinaryPath}mongodump{$quote}",
92
            "--db {$this->dbName}",
93
            '--archive',
94
        ];
95
96
        if ($this->userName) {
97
            $command[] = "--username '{$this->userName}'";
98
        }
99
100
        if ($this->password) {
101
            $command[] = "--password '{$this->password}'";
102
        }
103
104
        if (isset($this->host)) {
105
            $command[] = "--host {$this->host}";
106
        }
107
108
        if (isset($this->port)) {
109
            $command[] = "--port {$this->port}";
110
        }
111
112
        if (isset($this->collection)) {
113
            $command[] = "--collection {$this->collection}";
114
        }
115
116
        if ($this->authenticationDatabase) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->authenticationDatabase of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
117
            $command[] = "--authenticationDatabase {$this->authenticationDatabase}";
118
        }
119
120
        return $this->echoToFile(implode(' ', $command), $filename);
121
    }
122
}
123