Issues (61)

Security Analysis    not enabled

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.

lib/Mongo/MongoGridFSFile.php (2 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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 */
15
16
if (class_exists('MongoGridFSFile', false)) {
17
    return;
18
}
19
20
class MongoGridFSFile
21
{
22
    /**
23
     * @link http://php.net/manual/en/class.mongogridfsfile.php#mongogridfsfile.props.file
24
     * @var array
25
     */
26
    public $file;
27
28
    /**
29
     * @link http://php.net/manual/en/class.mongogridfsfile.php#mongogridfsfile.props.gridfs
30
     * @var $gridfs
31
     */
32
    protected $gridfs;
33
34
    /**
35
     * @link http://php.net/manual/en/mongogridfsfile.construct.php
36
     *
37
     * @param MongoGridFS $gridfs The parent MongoGridFS instance
38
     * @param array $file A file from the database
39
     */
40
    public function __construct(MongoGridFS $gridfs, array $file)
41
    {
42
        $this->gridfs = $gridfs;
43
        $this->file = $file;
44
    }
45
46
    /**
47
     * Returns this file's filename
48
     * @link http://php.net/manual/en/mongogridfsfile.getfilename.php
49
     * @return string Returns the filename
50
     */
51
    public function getFilename()
52
    {
53
        return isset($this->file['filename']) ? $this->file['filename'] : null;
54
    }
55
56
    /**
57
     * Returns this file's size
58
     * @link http://php.net/manual/en/mongogridfsfile.getsize.php
59
     * @return int Returns this file's size
60
     */
61
    public function getSize()
62
    {
63
        return $this->file['length'];
64
    }
65
66
    /**
67
     * Writes this file to the filesystem
68
     * @link http://php.net/manual/en/mongogridfsfile.write.php
69
     * @param string $filename The location to which to write the file (path+filename+extension). If none is given, the stored filename will be used.
70
     * @return int Returns the number of bytes written
71
     */
72
    public function write($filename = null)
73
    {
74
        if ($filename === null) {
75
            $filename = $this->getFilename();
76
        }
77
        if (empty($filename)) {
78
            $filename = 'file';
79
        }
80
81
        if (! $handle = fopen($filename, 'w')) {
82
            trigger_error('Can not open the destination file', E_USER_ERROR);
83
            return 0;
84
        }
85
86
        $written = $this->copyToResource($handle);
87
        fclose($handle);
88
89
        return $written;
90
    }
91
92
    /**
93
     * This will load the file into memory. If the file is bigger than your memory, this will cause problems!
94
     * @link http://php.net/manual/en/mongogridfsfile.getbytes.php
95
     * @return string Returns a string of the bytes in the file
96
     */
97
    public function getBytes()
98
    {
99
        $result = '';
100
        foreach ($this->getChunks() as $chunk) {
101
            $result .= $chunk['data']->bin;
102
        }
103
104
        return $result;
105
    }
106
107
    /**
108
     * This method returns a stream resource that can be used to read the stored file with all file functions in PHP.
109
     * The contents of the file are pulled out of MongoDB on the fly, so that the whole file does not have to be loaded into memory first.
110
     * At most two GridFSFile chunks will be loaded in memory.
111
     *
112
     * @link http://php.net/manual/en/mongogridfsfile.getresource.php
113
     * @return resource Returns a resource that can be used to read the file with
114
     */
115
    public function getResource()
116
    {
117
        $handle = fopen('php://temp', 'w+');
118
        $this->copyToResource($handle);
119
        rewind($handle);
120
121
        return $handle;
122
    }
123
124
    private function copyToResource($handle)
125
    {
126
        $written = 0;
127
        foreach ($this->getChunks() as $chunk) {
128
            $written += fwrite($handle, $chunk['data']->bin);
129
        }
130
131
        return $written;
132
    }
133
134
    private function getChunks()
135
    {
136
        return $chunks = $this->gridfs->chunks->find(
0 ignored issues
show
$chunks 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...
137
            ['files_id' => $this->file['_id']],
138
            ['data' => 1],
139
            ['n' => 1]
0 ignored issues
show
The call to MongoCollection::find() has too many arguments starting with array('n' => 1).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
140
        );
141
    }
142
}
143