Issues (446)

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.

php5/Filesystem.inc (5 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
 * Created by:	Marko Kungla @ OkramLabs on Aug 6, 2012 - 9:21:34
4
 * Contact:		[email protected] - https://okramlabs.com
5
 * @copyright:	2015 OkramLabs - https://okramlabs.com
6
 * @license		MIT
7
 *
8
 * Package name:libhowi-filesystem
9
 * @category	HOWI3
10
 * @package		libhowi
11
 * @subpackage	filesystem
12
 * 
13
 * Lang:		PHP
14
 * Encoding:	UTF-8
15
 * File:		Filesystem.inc
16
 * @link		https://
17
 ********************************************************************
18
 * Contributors:
19
 * @author		Marko Kungla <[email protected]>
20
 *  	Github:	https://github.com/mkungla
21
 ********************************************************************
22
 * Comments:
23
 */
24
namespace HOWI3\libhowi\Filesystem\php5;
25
26
use \HOWI3\libhowi\Filesystem\Commons\AbstractFilesystem;
27
use \HOWI3\libhowi\Filesystem\Commons\FilesystemInterface;
28
use \HOWI3\libhowi\Filesystem\Commons\SharedMethodsInterface;
29
use \HOWI3\libhowi\Filesystem\Commons\TraitForResponse;
30
use \HOWI3\libhowi\Filesystem\php5\Objects\DirectoryPlaceholderObject;
31
use \HOWI3\libhowi\Filesystem\php5\Objects\DirectoryTreeObject;
32
use \HOWI3\libhowi\Filesystem\php5\Objects\FileObject;
33
use \HOWI3\libhowi\Filesystem\php5\Objects\InfoObject;
34
use \HOWI3\libhowi\Filesystem\php5\Objects\TmpObject;
35
use \HOWI3\libhowi\Filesystem\php5\Objects\LinkObject;
36
use \HOWI3\libhowi\Filesystem\php5\TraitForFileSystem;
37
use \HOWI3\libhowi\Filesystem\php5\TraitForSharedMethods;
38
39 View Code Duplication
class Filesystem extends AbstractFilesystem implements FilesystemInterface, SharedMethodsInterface
40
{
41
    use TraitForResponse;
42
    use TraitForFileSystem;
43
    use TraitForSharedMethods;
44
45
    /**
46
     *
47
     * {@inheritDoc}
48
     *
49
     */
50 490
    public function __construct($setCwd = false)
51
    {
52 490
        $this->debug(801);
53 490
        $this->setStatus(true);
54 490
        if (! $this->setCwd($setCwd)) {
55 2
            $append = error_get_last();
56 2
            $this->warning(500, $append['message']);
57 2
        }
58
        
59 490
        $this->tmp()->setTmp();
60 490
    }
61
62
    /**
63
     *
64
     * {@inheritDoc}
65
     *
66
     */
67 110
    public function dir($directory = false, $dirname = false, $recursive = true, $mode = false, $context = false)
68
    {
69 110
        $response = null;
70 110
        if (empty($directory)) {
71 2
            return false;
72
        }
73
        // ///////////
74 108
        $this->debug(807);
75 108
        if (array_key_exists($directory, $this->dirkeys) &&
76 108
             array_key_exists($this->dirkeys[$directory], $this->dirs) &&
77 108
             is_object($this->dirs[$this->dirkeys[$directory]])) {
78 92
            $response = $this->dirs[$this->dirkeys[$directory]];
79 92
            $this->response = $this->dirs[$this->dirkeys[$directory]]->response();
80 108
        } elseif (! empty($directory) && ! empty($dirname)) {
81
            
82 108
            $dir = $this->makeAbsolute($dirname . DIRECTORY_SEPARATOR . $directory);
83 108
            $HID = md5($dir);
84 108
            $this->dirkeys[$directory] = $HID;
85 108
            $this->dirs[$HID] = $this->isDir($dir) ? new DirectoryTreeObject($dir, 
0 ignored issues
show
It seems like $dir defined by $this->makeAbsolute($dir...SEPARATOR . $directory) on line 82 can also be of type string; however, HOWI3\libhowi\Filesystem...rSharedMethods::isDir() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
86 108
                DirectoryTreeObject::SKIP_DOTS) : new DirectoryPlaceholderObject($dir, $recursive, $mode, 
0 ignored issues
show
It seems like $dir defined by $this->makeAbsolute($dir...SEPARATOR . $directory) on line 82 can also be of type string; however, HOWI3\libhowi\Filesystem...erObject::__construct() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
87 12
                $context, $this->getLogFile(), $this->getLogLevel(), $this->getUID(), $this->getUsername());
88
            
89 108
            if ($this->dirs[$HID] instanceof DirectoryPlaceholderObject) {
90 12
                $this->setStatus($this->dirs[$HID]->getStatus());
91 12
                $this->setCode($this->dirs[$HID]->getCode());
92 12
            }
93
            
94 108
            if ($this->dirs[$HID] instanceof DirectoryTreeObject) {
95 98
                $this->dirs[$HID]->setFileClass('\HOWI3\libhowi\Filesystem\php5\Objects\FileObject');
96 98
                $this->dirs[$HID]->setInfoClass('\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject');
97 98
                $this->dirs[$HID]->setLogFile($this->getLogFile());
98 98
                $this->dirs[$HID]->setLogLevel($this->getLogLevel());
99 98
                $this->dirs[$HID]->setUID($this->getUID());
100 98
                $this->dirs[$HID]->setUsername($this->getUsername());
101
                
102 98
                $this->response->setStatus(true);
103 98
            } else {
104
                
105
                /* We don't need DirectoryPlaceholderObject anymore for this directory */
106 12
                if ($this->isDir($dir)) {
0 ignored issues
show
It seems like $dir defined by $this->makeAbsolute($dir...SEPARATOR . $directory) on line 82 can also be of type string; however, HOWI3\libhowi\Filesystem...rSharedMethods::isDir() does only seem to accept boolean, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
107
                    
108 10
                    $this->dirs[$HID] = new DirectoryTreeObject($dir, DirectoryTreeObject::SKIP_DOTS);
109 10
                    $this->dirs[$HID]->setFileClass('\HOWI3\libhowi\Filesystem\php5\Objects\FileObject');
110 10
                    $this->dirs[$HID]->setInfoClass('\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject');
111 10
                    $this->dirs[$HID]->setLogFile($this->getLogFile());
112 10
                    $this->dirs[$HID]->setLogLevel($this->getLogLevel());
113 10
                    $this->dirs[$HID]->setUID($this->getUID());
114 10
                    $this->dirs[$HID]->setUsername($this->getUsername());
115 10
                }
116
            }
117
            
118 108
            $response = $this->dirs[$HID];
119 108
        }
120
        
121 108
        return $response;
122
    }
123
124
    /**
125
     *
126
     * {@inheritDoc}
127
     *
128
     */
129 120
    public function file($filename = false, $dirname = false, $data = '', $flags = FILE_APPEND, $context = null)
130
    {
131 120
        if (! empty($filename) && array_key_exists($filename, $this->files) &&
132 114
             is_object($this->files[$filename]))
133 120
            return $this->files[$filename];
134
        
135 120
        $this->debug(808);
136 120
        if (empty($filename)) {
137 2
            $this->notice(601);
138 2
            return false;
139
        }
140
        
141 120
        $dirname = empty($dirname) ? $this->getCwd() : $this->makeAbsolute($dirname);
142 120
        $real = $dirname . DIRECTORY_SEPARATOR . $filename;
143 120
        $real = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $real);
144
        
145 120
        if (! $this->exists($real) && ! $this->isWritable(dirname($real))) {
146 2
            $this->warning(503, $real);
147 2
            return false;
148 120
        } elseif (! $this->exists($real) && $this->isWritable(dirname($real))) {
149 8
            $result = empty($context) || ! is_resource($context) ? file_put_contents($real, $data, $flags) : file_put_contents(
150 8
                $real, $data, $flags, $context);
151 8
            $result = $result !== false ? $this->info(703, $real) : $this->warning(504, $real);
152 8
        }
153
        
154 120
        if ($this->exists($real)) {
155 120
            $this->files[$filename] = new FileObject($real, 'r+');
156 120
            $this->files[$filename]->setFileClass('\HOWI3\libhowi\Filesystem\php5\Objects\FileObject');
157 120
            $this->files[$filename]->setInfoClass("\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject");
158 120
            $result = $this->files[$filename];
159 120
        }
160
        
161 120
        return $result;
0 ignored issues
show
The variable $result does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
162
    }
163
164
    /**
165
     *
166
     * {@inheritDoc}
167
     *
168
     */
169 66
    public function infoObject($basename = false, $directory = false)
170
    {
171 66
        if (! empty($basename) && array_key_exists($basename, $this->infos) && is_object(
172 64
            $this->infos[$basename]))
173 66
            return $this->infos[$basename];
174
        
175 66
        $this->debug(809);
176 66
        if (empty($basename)) {
177 2
            $this->notice(602);
178 2
            return false;
179
        }
180
        
181 66
        $dirname = empty($directory) ? $this->getCwd() : $this->makeAbsolute($directory);
182 66
        $real = $dirname . DIRECTORY_SEPARATOR . $basename;
183 66
        $real = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $real);
184
        
185
        
186 66
        if (! $this->exists($real) && ! $this->isReadable($real)) {
187 2
            $this->warning(504, $real);
188 2
            $result = false;
189 66
        } elseif ($this->exists($real)) {
190 66
            $this->infos[$basename] = new InfoObject($real);
191 66
            $this->infos[$basename]->setFileClass('\HOWI3\libhowi\Filesystem\php5\Objects\FileObject');
192 66
            $this->infos[$basename]->setInfoClass("\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject");
193 66
            $result = $this->infos[$basename];
194 66
        }
195 66
        return $result;
0 ignored issues
show
The variable $result does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
196
    }
197
198
    /**
199
     *
200
     * {@inheritDoc}
201
     *
202
     */
203 490
    public function tmp($keyword = 'tmp')
204
    {
205 490
        if (array_key_exists($keyword, $this->tmp) && is_object($this->tmp[$keyword]) &&
206 490
             $this->tmp[$keyword] instanceof \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\TmpInterface) {
207 16
            return $this->tmp[$keyword];
208
        } else {
209 490
            $this->tmp[$keyword] = new TmpObject();
210 490
            return $this->tmp[$keyword];
211
        }
212
    }
213
214
    /**
215
     *
216
     * {@inheritDoc}
217
     *
218
     */
219 16
    public function link($keyword = 'link')
220
    {
221 16
        if (array_key_exists($keyword, $this->link) && is_object($this->link[$keyword]) &&
222 16
             $this->link[$keyword] instanceof \HOWI3\libhowi\Filesystem\Commons\ObjectInterfaces\LinkInterface) {
223 10
            return $this->link[$keyword];
224
        } else {
225 16
            $this->link[$keyword] = new LinkObject();
226 16
            return $this->link[$keyword];
227
        }
228
    }
229
}
230