Issues (3)

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

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 PhpStorm.
4
 * User: egorov
5
 * Date: 03.12.2014
6
 * Time: 20:26
7
 */
8
namespace samsonphp\fs;
9
10
/**
11
 * Abstract IFileService implementation
12
 * with higher level functions implemented
13
 * @package samsonphp\fs
14
 */
15
abstract class AbstractFileService implements IFileSystem
16
{
17
    /** @var array Collection of mime => extension */
18
    public static $mimes = array
19
    (
20
        'text/css' 					=> 'css',
21
        'application/x-font-woff' 	=> 'woff',
22
        'application/x-javascript' 	=> 'js',
23
        'text/html;charset=utf-8'	=>'htm',
24
        'text/x-component' 		=> 'htc',
25
        'image/jpeg' 			=> 'jpg',
26
        'image/pjpeg' 			=> 'jpg',
27
        'image/png' 			=> 'png',
28
        'image/x-png' 			=> 'png',
29
        'image/jpg' 			=> 'jpg',
30
        'image/gif' 			=> 'gif',
31
        'text/plain' 			=> 'txt',
32
        'application/pdf' 		=> 'pdf',
33
        'application/zip' 		=> 'zip',
34
        'application/rtf' 		=> 'rtf',
35
        'application/msword' 	=> 'doc',
36
        'application/msexcel' 	=> 'xls',
37
        'application/vnd.ms-excel'  => 'xls',
38
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx',
39
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx',
40
        'application/octet-stream' 	=> 'sql',
41
        'audio/mpeg'	=> 'mp3',
42
        'text/x-c++'    => 'php',
43
    );
44
45
    /**
46
     * File service initialization stage
47
     */
48
    public function initialize()
49
    {
50
        // Should be overloaded
51
    }
52
53
    /**
54
     * Get file mime type in current file system
55
     * @param $filePath string Path to file
56
     * @return false|integer|string false if mime not found, otherwise file mime type
57
     */
58
    public function mime($filePath)
59
    {
60
        // Get file extension from path
61
        $extension = $this->extension($filePath);
62
63
        // Search mimes array and return mime for file otherwise false
64
        return array_search($extension, self::$mimes);
65
    }
66
67
    /**
68
     * Get relative path from $path
69
     * @param string $fullPath  Full file path
70
     * @param string $fileName  File name
71
     * @param string $basePath  Base path, must end WITHOUT '/', if not passed
72
     *                          $fullPath one level top directory is used.
73
     * @return string Relative path to file
74
     */
75
    public function relativePath($fullPath, $fileName, $basePath = null)
76
    {
77
        // If no basePath is passed consider that we must go ne level up from $fullPath
78
        $basePath = !isset($basePath) ? dirname($fullPath) : $basePath;
79
80
        // Get dir from path and remove file name of it if no dir is present
81
        return str_replace($basePath.'/', '', str_replace($fileName, '', $fullPath));
82
    }
83
84
    /**
85
     * Copy folder to selected location.
86
     * Copy can be performed from file($filePath) to file($newPath),
87
     * also copy can be performed from folder($filePath) to folder($newPath),
88
     * currently copying from file($filePath) to folder($newPath) is not supported.
89
     *
90
     * @param string $filePath      Source path or file path
91
     * @param string $newPath       New path or file path
92
     * @return bool|null False if failed otherwise true if file/folder has been copied
93
     */
94
    protected function copyFolder($filePath, $newPath)
95
    {
96
        // Read directory
97
        foreach ($this->dir($filePath) as $file) {
98
            // Get file name
99
            $fileName = basename($file);
100
            // Read source file and write to new location
101
            $this->write(
102
                $this->read($file, $fileName),
103
                $fileName,
104
                $newPath
105
            );
106
        }
107
    }
108
109
    /**
110
     * Copy file to selected location.
111
     * Copy can be performed from file($filePath) to file($newPath),
112
     * also copy can be performed from folder($filePath) to folder($newPath),
113
     * currently copying from file($filePath) to folder($newPath) is not supported.
114
     *
115
     * @param string $filePath      Source path or file path
116
     * @param string $newPath       New path or file path
117
     */
118
    protected function copyFile($filePath, $newPath)
119
    {
120
        // Get file name
121
        $fileName = basename($newPath);
122
123
        // Read and write file
124
        $this->write(
125
            $this->read($filePath, $fileName),
126
            $fileName,
127
            dirname($newPath)
128
        );
129
    }
130
131
    /**
132
     * Copy file/folder to selected location.
133
     * Copy can be performed from file($filePath) to file($newPath),
134
     * also copy can be performed from folder($filePath) to folder($newPath),
135
     * currently copying from file($filePath) to folder($newPath) is not supported.
136
     *
137
     * @param string $filePath      Source path or file path
138
     * @param string $newPath       New path or file path
139
     * @return boolean False if failed otherwise true if file/folder has been copied
140
     */
141
    public function copyPath($filePath, $newPath)
142
    {
143
        // Check if source file exists
144
        if ($this->exists($filePath)) {
145
            // If this is directory
146
            if ($this->isDir($filePath)) {
147
                $this->copyFolder($filePath, $newPath);
148
            } else { // Read source file and write to new location
149
                $this->copyFile($filePath, $newPath);
150
            }
151
152
            // Return success
153
            return true;
154
        } else { // Signal error
155
            return e(
0 ignored issues
show
Deprecated Code introduced by
The function e() has been deprecated with message: Use custom exceptions

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
156
                'Cannot copy file[##] to [##] - Source file does not exists',
157
                E_SAMSON_CORE_ERROR,
158
                array($filePath, $newPath)
159
            );
160
        }
161
    }
162
163
    /**
164
     * Create catalog in selected location
165
     * @param string    $path   Path for new catalog
166
     * @return boolean  Result of catalog creating
167
     */
168
    abstract public function mkDir($path);
169
}
170