Issues (1751)

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.

lib/ar/http/files.php (2 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
	ar_pinp::allow( 'ar_http_files');
3
	ar_pinp::allow( 'ar_http_filesRegistry');
4
5
	class ar_http_files extends arBase {
6
7
		protected static $store = null;
8
9
		protected static function getStore( $store = null ) {
10
			if ( !$store ) {
11
				$store = self::$store;
12
			}
13
			if ( !$store ) {
14
				self::$store =  ar('loader/session')->get();
15
				if ( !self::$store ) {
16
					self::$store = ar('loader/session')->start();
17
				}
18
				$store = self::$store;
19
			}
20
			return $store;
21
		}
22
23
		public static function ls() {
0 ignored issues
show
ls uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
24
			return $_FILES;
25
		}
26
27
		public static function getFile( $filename ) {
0 ignored issues
show
getFile uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
28
			// return opened file if exists, null otherwise
29
			$filename = (string) $filename;
30
			$file = null;
31
			$info = $_FILES[$filename];
32
			if ( $info && is_uploaded_file( $info['tmp_name'] ) ) {
33
				$fp = fopen( $info['tmp_name'], 'r+b' );
34
				$file = new ar_content_filesFile( $fp );
35
			}
36
			return $file;
37
		}
38
39
		public static function registry( $store = null ) {
40
			$store = self::getStore( $store );
41
			return new ar_http_filesRegistry( $store );
42
		}
43
44
	}
45
46
	class ar_http_filesRegistry extends arBase {
47
48
		protected $store = null;
49
50
		public function __construct( $store ) {
51
			$this->store = $store;
52
		}
53
54
		public function ls() {
55
			return $this->store->getvar('registeredFiles');
56
		}
57
58
		public function getFile( $filename, $nls = 'none' ) {
59
			$filename = (string) $filename;
60
			$nls = (string) $nls;
61
			$registeredFiles = $this->ls();
62
			$info = $registeredFiles[$filename][$nls];
63
			if ($info && $info['temp']) {
64
				// check before removing
65
				$tempfile = preg_replace( "|[\\\/]|", "", $info['temp'] );
66
				$tempOb = ar::context()->getObject();
67
				$tempfile = $tempOb->store->get_config('files').'temp/'.$tempfile;
68
				$resource = fopen( $tempfile, 'r+b' );
69
				return new ar_content_filesFile( $resource );
70
			} else {
71
				return null;
72
			}
73
		}
74
75
		public function getInfo( $filename, $nls = 'none' ) {
76
			$filename = (string) $filename;
77
			$nls = (string) $nls;
78
			$registeredFiles = $this->ls();
79
			$info = $registeredFiles[$filename][$nls];
80
			if ( $info ) {
81
				return $info;
82
			} else {
83
				return ar('error')->raiseError( 'No info for file '.$filename.' found', 502 );
84
			}
85
		}
86
87
		public function putFile( $filename, $nls = 'none', $originalName = null ) {
88
			$filename = (string) $filename;
89
			$nls = (string) $nls;
90
			if ( !isset($originalName) ) {
91
				$originalName = $filename;
92
			}
93
			$originalName = (string) $originalName;
94
			$registeredFiles = (array) $this->store->getvar('registeredFiles');
95
			$error = '';
96
			$fileInfo = ldRegisterFile( $originalName, $error );
97
			if (!$error) {
98
				$cleanInfo = array(
99
					'name' => $fileInfo[ $originalName ],
100
					'temp' => $fileInfo[ $originalName.'_temp' ],
101
					'size' => $fileInfo[ $originalName.'_size' ],
102
					'type' => $fileInfo[ $originalName.'_type' ]
103
				);
104
				$registeredFiles[ $filename ][ $nls ] = $cleanInfo;
105
				$this->store->putvar('registeredFiles', $registeredFiles );
106
				$result = $cleanInfo;
107
			} else {
108
				$result = ar('error')->raiseError( $error, 501 );
109
			}
110
			return $result;
111
		}
112
113
		public function remove( $filename, $nls = 'none') {
114
			$filename = (string) $filename;
115
			$nls = (string) $nls;
116
			$registeredFiles = $this->ls();
117
			$info = $registeredFiles[$filename][$nls];
118
			unset($registeredFiles[$filename][$nls]);
119
			if (!$registeredFiles[$filename]) {
120
				unset($registeredFiles[$filename]);
121
			}
122
			$this->store->putvar('registeredFiles', $registeredFiles );
123
			if ($info && $info[$filename.'_temp']) {
124
				// check before removing
125
				$tempfile = preg_replace( "|[\\\/]|", "", $info[$filename.'_temp'] );
126
				$tempOb = ar::context()->getObject();
127
				$tempfile = $tempOb->store->get_config('files').'temp/'.$tempfile;
128
				if ($tempfile && file_exists($tempfile) ) {
129
					unlink($tempfile);
130
				}
131
			}
132
		}
133
134
	}
135