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/template/filesystem.php (8 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
3
	use arc\path as path;
4
5
	class ar_template_filesystem extends arBase {
6
		private $path;
7
		private $config;
8
9
		public function __construct($path, $config ) {
10
			$this->path   = path::collapse($path);
11
			$this->config = $config;
12
			$this->config['path'] = path::collapse($config['path']);
13
		}
14
15
		public function get($path, $name){
16
			$arpath = path::collapse($path);
17
18
			if ( strpos($arpath, $this->path, 0) !== 0) {
19
				return ar('error')->raiseError('invalide path for loading template',500);
20
			}
21
22
			$realpath = $this->config['path'] . substr($arpath,strlen($this->path));
23
			$realpath = realpath($realpath) .'/';
24
25
			$cachepath = sha1($path . $name);
26
			$tempOb    = ar::context()->getObject();
27
			$cacheroot = $tempOb->store->get_config('files').'temp/';
28
29
			if ( 
30
				! file_exists( $cacheroot . $cachepath )  ||
31
				( filemtime($cacheroot . $cachepath ) < filemtime ( $realpath  . $name ) )
32
			) {
33
				$compiled = $this->compile($path, $name);
34
				file_put_contents($cacheroot . $cachepath, $compiled);
35
			}
36
			include (  $cacheroot . $cachepath );
37
			return $arTemplateFunction;
0 ignored issues
show
The variable $arTemplateFunction does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
38
		}
39
40
		public function save($path, $name, $template, $local=null, $private=null) {
0 ignored issues
show
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $template is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $local is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $private is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
			return false;
42
		}
43
44 View Code Duplication
		public function load($path, $name) {
45
			$arpath = path::collapse($path);
46
47
			if ( strpos($arpath, $this->path, 0) !== 0) {
48
				return ar('error')->raiseError('invalide path for loading template',500);
49
			}
50
51
			$realpath = $this->config['path'] . substr($arpath,strlen($this->path));
52
			$realpath = realpath($realpath) .'/';
53
54
			return file_get_contents($realpath . $name);
55
		}
56
57
		public function ls($path) {
58
			$arpath = path::collapse($path);
59
60
			if ( strpos($arpath, $this->path, 0) !== 0) {
61
				return [];
62
			}
63
			$realpath = $this->config['path'] . substr($arpath,strlen($this->path));
64
			$realpath = realpath($realpath) .'/';
65
			$traverse = 'src/';
66
			if (!file_exists($realpath . 'library.json')) {
67
				$realparent = path::parent($realpath);
68
				$node = basename($realpath);
69
				if ($node === 'tests' && file_exists($realparent . 'library.json') ) {
70
					// special case
71
					// system/lib/libname/tests/ is a sibling of src instead of a child library
72
					$traverse = 'tests/';
73
					$arpath   = path::parent($path);
74
					$realpath = $realparent;
75
				} else {
76
					return [];
77
				}
78
			}
79
80
			$config = json_decode(file_get_contents($realpath . 'library.json'),true);
81
82
			if(!isset($config['exports']) ) {
83
				$config['exports'] = [];
84
			}
85
			if(!isset($config['local']) ) {
86
				$config['local'] = [];
87
			}
88
89
			$result = [];
90
91
			$traverseDir = function ($path, $type = 'pobject', $nls = 'any') use ($arpath, &$result, $config, &$traverseDir, $realpath) {
92
				$path = path::collapse($path);
93
				if (is_dir($path) ) {
94
					$index = scandir($path, SCANDIR_SORT_NONE);
95
					if($index !== false) {
96
						list($maintype, $subtype) = explode('.', $type,2);
97
						foreach($index as $filename) {
98
							if($filename[0] === "." ) {
99
								continue;
100
							}
101
							$filepath = $path . $filename;
102
							if ( is_dir($filepath) ) {
103
								if (strlen($filename) == 2) {
104
									$traverseDir(path::collapse($filename, $path), $type, $filename);
105
								} else {
106
									$traverseDir(path::collapse($filename, $path), $filename);
107
								}
108
							} else if ( is_file($filepath) ) {
109
								$tempname = sprintf("%s.%s.%s",$type,$filename,$nls);
110
								$confname = sprintf("%s::%s",$type,$filename);
111
								$private = true;
112
								if (isset( $config['exports'] ) ) {
113
									if ($config['exports'][0] === '*') {
114
										$private = false;
115
									} else {
116
										$private = ! (
117
											in_array($filename, $config['exports']) ||
118
											in_array($confname, $config['exports'])
119
										);
120
									}
121
								}
122
								$local = false;
123
								if (isset( $config['local'] ) ) {
124
									$local = in_array($confname, $config['local']);
125
								}
126
								$result[$filename][] = [
127
									'id'       => PHP_INT_MAX,
128
									'path'     => $arpath,
129
									'type'     => $maintype,
130
									'subtype'  => $subtype,
131
									'name'     => $tempname,
132
									'filename' => substr($filepath,strlen($realpath)),
133
									'language' => $nls,
134
									'private'  => $private,
135
									'local'    => $local,
136
								];
137
							}
138
						}
139
					}
140
				}
141
142
			};
143
			$traverseDir($realpath . $traverse );
144
			return $result;
145
		}
146
147
		public function rm($path, $name){
0 ignored issues
show
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
148
		}
149
150 View Code Duplication
		public function exists($path, $name) {
151
			$arpath = path::collapse($path);
152
153
			if ( strpos($arpath, $this->path, 0) !== 0) {
154
				return ar('error')->raiseError('invalide path for loading template',500);
155
			}
156
157
			$realpath = $this->config['path'] . substr($arpath,strlen($this->path));
158
			$realpath = realpath($realpath) .'/';
159
			return file_exists($realpath . $name);
160
		}
161
162
		public function compile($path, $name) {
163
			global $AR;
164
			$arpath = path::collapse($path);
165
166
			if ( strpos($arpath, $this->path, 0) !== 0) {
167
				return ar('error')->raiseError('invalide path for loading template',500);
168
			}
169
170
			$realpath = $this->config['path'] . substr($arpath,strlen($this->path));
171
			$realpath = realpath($realpath) .'/';
172
173
			$template = file_get_contents($realpath . $name);
174
175
			require_once(AriadneBasePath."/modules/mod_pinp.phtml");
176
177
			$pinp = new pinp($AR->PINP_Functions, "local->", "\$AR_this->_");
178
179
			// FIXME error checking
180
			$compiled = $pinp->compile(strtr($template,"\r",""));
181
			$compiled = sprintf($AR->PINPtemplate, $compiled);
182
			return $compiled;
183
184
		}
185
	}
186