Issues (76)

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.

app/Library/Sftp.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 App\Library;
4
5
define('NET_SFTP_LOGGING', 2);
6
7
class Sftp
8
{
9
    
10
	protected $connectionName;
11
12
	/**
13
	 * Constructor
14
	 *
15
	 * @param string $connectionName
16
	 */
17
	public function __construct($connectionName)
18
	{
19
		$this->connectionName = $connectionName;
20
	}
21
22
	/**
23
	 * Gets all XML files from a remote folder
24
	 * 
25
	 * @param  string $remoteDir 
26
	 * @param  string $localDir 
27
	 * @return array
28
	 */
29
   	public function getFiles($remoteDir, $localDir)
30
   	{    	
31
		$files = $this->remoteListPackaged($remoteDir);
32
33
		foreach ($files as $file) {			
34
			$this->getFile($file['fullFileName'], $localDir . '/' . $file['fileName']);
35
		}
36
37
		return $files;
38
  	}
39
40
	/**
41
	 * Gets all XML files from a remote folder
42
	 * 
43
	 * @param  string 	$dir 
44
	 * @param  bool     $sorted 
45
	 * @param  string   $sortOrder 
46
	 * @return array
47
	 */
48
   	public function remoteListPackaged($dir, $sorted = true, $sortOrder = 'desc')
49
   	{    	
50
		$files = [];
51
		$all = $this->remoteList($dir, $sorted, $sortOrder);
52
		
53
		foreach ($all as $file=>$val) {
54
			if ($this->isValidExtension($val['filename'])) {
55
				$files[] = [
56
					'fileName' => $val['filename'], 
57
					'fullFileName' => $dir . '/' . $val['filename'],
58
					'size' => $val['size'],
59
					'modified' => gmdate("m/d/Y H:i:s", $val['mtime']),
60
				];
61
			}
62
		}
63
64
		return $files;
65
	}
66
67
	/**
68
	 * Retrieves a file from a SSH/SFTP server
69
	 * 
70
	 * @param  string $remoteFile 
71
	 * @param  string $localFile 
72
	 * @return \Symfony\Component\Console\Output\OutputInterface
73
	 */
74
	public function getFile($remoteFile, $localFile)
75
	{	
76
		return \SSH::into($this->connectionName)->get($remoteFile, $localFile);    
77
	}
78
79
	/**
80
	 * Places a file on a remote SSH/SFTP server
81
	 * 
82
	 * @param  string $remoteFile 
83
	 * @param  string $localFile 
84
	 * @return \Symfony\Component\Console\Output\OutputInterface
85
	 */
86
	public function putFile($remoteFile, $localFile)
87
	{
88
		return \SSH::into($this->connectionName)->put($localFile, $remoteFile);
89
	}
90
91
	/**
92
	 * Retrieves a listing from directory
93
	 * 
94
	 * @param  string 	$dir 
95
	 * @param  bool     $sorted 
96
	 * @param  string   $sortOrder 
97
	 * @return array 	array of files and folders	
98
	 */
99
	public function remoteList($dir, $sorted = true, $sortOrder = 'desc')
100
	{
101
		$conn = $this->getConnection();
102
		$conn->chdir($dir);
103
		$list = $conn->rawlist();
104
105
		if ($sorted) {
106
			$list = $this->sortList($list, $sortOrder);
107
		}
108
    	
109
		return $list;    
110
	}
111
112
	/**
113
	 * Retrieves a listing from directory
114
	 * 
115
	 * @param  array    $list 
116
	 * @param  string   $sortOrder 
117
	 * @return array    sorted array of a folder
118
	 */
119
	public function sortList($list, $sortOrder = 'desc')
120
	{
121
		usort($list, function($a, $b) { return $a['mtime'] - $b['mtime']; }); 
122
123
		return $sortOrder == 'asc' ? $list : array_reverse($list);
124
	}
125
126
	/**
127
	 * Retrieves a listing from directory
128
	 * 
129
	 * @param  string   $remoteFileFrom 
130
	 * @param  string   $remoteFileTo 
131
	 * @return boolean  success
132
	 */
133
	public function rename($remoteFileFrom, $remoteFileTo)
134
	{
135
		$conn = $this->getConnection();
136
		//print $conn->getSFTPLog();
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
137
		return $conn->rename($remoteFileFrom, $remoteFileTo);
138
	}
139
140
	/**
141
	 * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
142
	 * 
143
	 * @return Net_SFTP connection
144
	 */
145
	protected function getConnection()
146
	{
147
		return \SSH::into($this->connectionName)->getGateway()->getConnection();
148
	}
149
150
	/**
151
	 * Gets a Net_SFTP connection as Laravels SSH doesn't have all the functionality
152
	 * 
153
	 * @param  string $fileName 
154
	 * @return bool 	
155
	 */
156
	protected function isValidExtension($fileName)
157
	{
158
		return substr(strrchr($fileName, '.'), 1) === 'xml' || substr(strrchr($fileName, '.'), 1) === 'err';
159
	}
160
}