Issues (25)

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/File.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
namespace BigFileTools;
4
5
use BigFileTools\Driver\ISizeDriver;
6
7
class File
8
{
9
	/**
10
	 * Full path to file
11
	 * @var string
12
	 */
13
	private $path;
14
15
	/**
16
	 * @var ISizeDriver
17
	 */
18
	private $sizeDriver;
19
20
	/**
21
	 * File constructor.
22
	 * @param string $absoluteFilePath **absolute** path to file
23
	 * @param ISizeDriver $sizeDriver Driver used for determining file size
24
	 */
25
	public function __construct($absoluteFilePath, ISizeDriver $sizeDriver)
26
	{
27
		$this->path = $absoluteFilePath;
28
		$this->sizeDriver = $sizeDriver;
29
	}
30
31
	/**
32
	 * @return \Brick\Math\BigInteger
33
	 * @throws Driver\Exception
34
	 */
35
	public function getSize()
36
	{
37
		return $this->sizeDriver->getFileSize($this->path);
38
	}
39
40
	/**
41
	 * Absolute path to file
42
	 * @return string
43
	 */
44
	public function getPath()
45
	{
46
		return $this->path;
47
	}
48
49
	/**
50
	 * Returns PHP's file info (some values can be incorrect due to platform limitations)
51
	 * @return \SplFileInfo
52
	 */
53
	public function getFileInfo()
54
	{
55
		return new \SplFileInfo($this->path);
56
	}
57
58
	/**
59
	 * Returns if file exists and is readable
60
	 * @return bool
61
	 */
62
	public function isReadableFile()
63
	{
64
		// Do not use is_file
65
		// @link https://bugs.php.net/bug.php?id=27792
66
		// $readable = is_readable($file); // does not always return correct value for directories
67
68
		$fp = @fopen($this->path, "r"); // must be file and must be readable
69
		if($fp) {
70
			fclose($fp);
71
			return true;
72
		}
73
		return false;
74
	}
75
76
	/**
77
	 * Moves file to new location / rename
78
	 * @param string $destination path
79
	 * @return bool
80
	 * @throws Exception
81
	 */
82
	function move($destination)
83
	{
84
		if (move_uploaded_file($this->path, $destination)) {
85
			$this->path = $destination;
86
			return;
87
		}
88
89
		@unlink($destination); // needed in PHP < 5.3 & Windows; intentionally @
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
90
		if (rename($this->path, $destination)) {
91
			$this->path = $destination;
92
			return;
93
		}
94
95
		if (copy($this->path, $destination)) {
96
			unlink($this->path); // delete file
97
			$this->path = $destination;
98
			return;
99
		}
100
101
		throw new Exception("File cannot be moved. All supported methods failed.");
102
	}
103
}