Issues (1)

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/Compress.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
 * Jaeger
4
 *
5
 * @copyright	Copyright (c) 2015-2016, mithra62
6
 * @link		http://jaeger-app.com
7
 * @version		1.0
8
 * @filesource 	./Compress.php
9
 */
10
namespace JaegerApp;
11
12
use JaegerApp\Exceptions\CompressException;
13
14
/**
15
 * Jaeger - Compress Object
16
 *
17
 * Handles compressing and decompressing files into various formats
18
 *
19
 * @package Compression
20
 * @author Eric Lamb <[email protected]> 
21
 */
22
class Compress
23
{
24
25
    /**
26
     * Returns an instance of the archive object
27
     * 
28
     * @var \ZipArchive
29
     */
30
    protected $archiver = null;
31
32
    /**
33
     * Flag to determine whether the orignial file should be kept
34
     * 
35
     * @var bool
36
     */
37
    protected $keep_original = true;
38
39
    /**
40
     * The name of the completed archive file
41
     * 
42
     * @var string
43
     */
44
    protected $archive_name = 'archive.zip';
45
46
    /**
47
     * Returns an instance of the Archiver
48
     * 
49
     * @return ZipArchive
50
     */
51
    public function getArchiver()
52
    {
53
        if (is_null($this->archiver)) {
54
            $this->archiver = new \ZipArchive();
55
        }
56
        
57
        return $this->archiver;
58
    }
59
60
    /**
61
     * Extracts a compressed file to the destination
62
     * 
63
     * @param string $file
64
     *            The full path to the file to extract
65
     * @param string $destination
66
     *            The destination to extract to
67
     * @return bool
68
     */
69
    public function extract($file, $destination = false)
70
    {
71
        $archive = $this->getArchiver()->open($file);
72
        if ($archive) {
73
            $this->getArchiver()->extractTo($destination);
74
            return $this->getArchiver()->close();
75
        }
76
    }
77
78
    /**
79
     * Sets the archive file name
80
     * 
81
     * @param string $name            
82
     * @return \mithra62\Compress
83
     */
84
    public function setArchiveName($name)
85
    {
86
        $this->archive_name = $name . '.zip';
87
        return $this;
88
    }
89
90
    /**
91
     * Returns the archive file name
92
     * 
93
     * @return string
94
     */
95
    public function getArchiveName()
96
    {
97
        return $this->archive_name;
98
    }
99
100
    /**
101
     * Starts the process of creating an archive
102
     * 
103
     * @param string $name            
104
     * @return \mithra62\Compress
105
     */
106
    public function create($name)
107
    {
108
        $this->setArchiveName($name);
109
        $this->getArchiver()->open($this->getArchiveName(), \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
110
        return $this;
111
    }
112
113
    /**
114
     * Adds a file to the archive
115
     * 
116
     * @param string $path            
117
     * @param string $relative            
118
     * @return \mithra62\Compress
119
     */
120
    public function add($path, $relative)
121
    {
122
        $this->getArchiver()->addFile($path, $relative);
123
        return $this;
124
    }
125
126
    /**
127
     * Closes the zip archive object
128
     * 
129
     * @return string The path to the archive
130
     */
131
    public function close()
132
    {
133
        $this->getArchiver()->close();
134
        return $this->getArchiveName();
135
    }
136
137
    /**
138
     * Compresses a single file
139
     * 
140
     * @param string $file
141
     *            the full path to the file to compress
142
     * @param string $desination
143
     *            optional the full path to the destination. If none is given then $file is used with the extension appended
144
     */
145
    public function archiveSingle($file, $desination = false)
146
    {
147
        if ($file == '') {
148
            throw new CompressException('__exception_compress_file_value_empty');
149
        }
150
        
151
        if (! file_exists($file)) {
152
            throw new CompressException('__exception_compress_file_not_exist');
153
        }
154
        
155
        if (! is_readable($file)) {
156
            throw new CompressException('__exception_compress_file_not_readable');
157
        }
158
        
159
        // work out path stuff
160
        $old_cwd = getcwd();
161
        $path = dirname($file);
162
        chdir($path);
163
        
164
        $name = $this->getArchiveName();
165
        $zip = $this->getArchiver();
166
        $zip->open($name, \ZipArchive::CREATE);
167
        if (file_exists($file)) {
168
            $zip->addFile(basename($file));
169
        }
170
        
171
        if ($zip->status != '0') {
172
            throw new CompressException('__exception_compression');
173
        }
174
        
175
        $zip->close();
176
        
177
        if (! $this->getKeepOriginal() && file_exists($file)) {
178
            unlink($file);
179
        }
180
        
181
        if ($desination) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $desination of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false 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...
182
            $desination = realpath($desination) . DIRECTORY_SEPARATOR . $name;
183
            copy($name, $desination);
184
            unlink($name);
185
            
186
            $name = $desination;
187
        } else {
188
            $name = $path . DIRECTORY_SEPARATOR . $name;
189
        }
190
        
191
        // reset path
192
        chdir($old_cwd);
193
        
194
        return $name;
195
    }
196
197
    /**
198
     * Sets whether the original file should be removed once compressed
199
     * 
200
     * @param bool $flag            
201
     * @return \mithra62\Compress
202
     */
203
    public function setKeepOriginal($flag = true)
204
    {
205
        $this->keep_original = $flag;
206
        return $this;
207
    }
208
209
    /**
210
     * Returns whether the original file should be kept once compressed
211
     * 
212
     * @return \mithra62\bool
213
     */
214
    public function getKeepOriginal()
215
    {
216
        return $this->keep_original;
217
    }
218
}