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/nls.php (3 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
ar_pinp::allow( 'ar_nls' );
4
ar_pinp::allow( 'ar_nlsDictionary', array("load", "setLanguage", "getLanguage") );
5
6
class ar_nls extends arBase {
7
8
	public static function dict($defaultLanguage, $currentLanguage = null, $defaultVarName = "ARnls", $baseDir = null ) {
9
		if ( !$baseDir ) {
10
			global $store; // FIXME: remove dependency on $store, use arbasedir in some way.
11
			$baseDir = $store->get_config("code")."nls/";
12
		}
13
		return new ar_nlsDictionary($baseDir, $defaultLanguage, $currentLanguage, $defaultVarName );
14
	}
15
16
}
17
18
class ar_nlsDictionary extends arBase implements ArrayAccess, Iterator {
19
20
	private $currentList = null;
21
	private $defaultList = null;
22
	private $baseDir = null;
23
	private $languages = array();
24
	private $loaded = array();
25
	public $currentLanguage = null;
26
	public $defaultLanguage = null;
27
28
	public function __construct( $baseDir, $defaultLanguage, $currentLanguage = null, $defaultVarName = "ARnls" ) {
29
30
		$this->baseDir = $baseDir;
31
		$this->defaultVarName = $defaultVarName;
0 ignored issues
show
The property defaultVarName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
33
		if( !isset($currentLanguage) ) {
34
			$currentLanguage = $defaultLanguage;
35
		}
36
37
		$this->languages[$defaultLanguage] = array();
38
		$this->languages[$currentLanguage] = array();
39
40
		$this->defaultList = &$this->languages[$defaultLanguage];
41
		$this->currentList = &$this->languages[$currentLanguage];
42
43
		$this->currentLanguage = $currentLanguage;
44
		$this->defaultLanguage = $defaultLanguage;
45
46
		$this->load();
47
	}
48
49
	public function setLanguage( $language ) {
50
		if( !isset($language) || $language == "" ) {
51
			$language = $this->defaultLanguage;
52
		}
53
		if( !isset( $this->languages[$language] ) ) {
54
			$this->languages[$language] = array();
55
		}
56
		$this->currentList = &$this->languages[$language];
57
		$this->currentLanguage = $language;
58
		$this->load();
59
60
		foreach( $this->loaded as $section => $nlslist ) {
61
			if( !isset($nlslist[$language]) ) {
62
				$this->load($section);
63
			}
64
		}
65
		return $this;
66
	}
67
68
	public function getLanguage( $language = null ) {
69
		return isset($language) ? $this->languages[$language] : $this->currentList;
70
	}
71
72
	public function load( $section = "", $nls = null, $varName = null ) {
73
		if( !isset($nls) ) {
74
			$nls = $this->currentLanguage;
75
		}
76
		if( !isset($varName) ) {
77
			$varName = $this->defaultVarName;
78
		}
79
80
		$nls = preg_replace('|[^a-z]*|i','',$nls);
81
		$re = '|[^a-z-_.:0-9/]*|i';				// only allow 'normal' characters
82
		$section = str_replace('//', '/', 			// protects against urls in the form of //google.com
83
				str_replace('..', '', 			// protects against ../../../../../etc/passwd
84
				preg_replace($re, '', $section))); // add .js if not set, remove .. and other dirty characters
85
86
		if (strpos($section, 'current:')!==false) {
87
				$context = pobject::getContext();
88
				$arLibraryPath = $context['arLibraryPath'];
89
				$sectionCacheName = str_replace( 'current:', $arLibraryPath.':', $section);
90
		} else {
91
				$sectionCacheName = $section;
92
		}
93
94
		if( !$section ) {
95
			if( !$this->loaded[$sectionCacheName][$nls] && ($fullFile = $this->baseDir.$nls) && file_exists($fullFile) ) {
96
				include($fullFile);
97
				$this->loaded[$sectionCacheName][$nls] = true;
98
				$this->languages[$nls] = array_merge((array)$this->languages[$nls], (array)$$varName);
99
			}
100
		} elseif( !$this->loaded[$sectionCacheName][$nls] ) {
101
			$this->loaded[$sectionCacheName][$nls] = true;
102
			$fullFile = $this->baseDir.$section.".".$nls;
103
			if( file_exists($fullFile) ) {
104
				include($fullFile);
105
				$this->languages[$nls] = array_merge((array)$this->languages[$nls], (array)$$varName);
106
			} else {
107
				// FIXME: UGLY hack stolen from pobject::loadtext()
108
				global $ARCurrent;
109
				$context = pobject::getContext();
110
				$me = $context["arCurrentObject"];
111
				if ( !$me || !is_object($me) ) {
112
					//FIXME: this should not happen, but ldObjectNotFound() sometimes triggers this
113
					// the problem is that there is no arCurrentObject pushed on the stack
114
					// generally we can just return and nothing serious will happen
115
					debug('No current object found on the context stack, skipping loadtext', 'all');
116
					return $this;
117
				}
118
				$arResult = $ARCurrent->arResult;
119
				$me->pushContext(array());
120
					$oldnls = $me->reqnls;
121
					$me->reqnls = $nls;
122
					$oldAllnls = $ARCurrent->allnls;
123
					$ARCurrent->allnls = true;
124
					$me->CheckConfig($section, array("nls" => $nls));
125
					$ARCurrent->allnls = $oldAllnls;
126
					$me->reqnls = $oldnls;
127
				$me->popContext();
128
129
				$nlsarray = array();
130
				if( is_array($ARCurrent->arResult) ) {
131
					$nlsarray = $ARCurrent->arResult;
132
				} elseif( is_array($me->{$varName}) ) {
133
					$nlsarray = $me->{$varName};
134
				} elseif( is_array($ARCurrent->{$varName}) ) {
135
					$nlsarray = $ARCurrent->{$varName};
136
				}
137
				$ARCurrent->arResult = $arResult;
138
				$this->languages[$nls] = array_merge((array)$this->languages[$nls], (array)$nlsarray);
139
			}
140
		}
141
		return $this;
142
	}
143
144
	/* ArrayAccess */
145
146 1
	public function offsetSet( $offset, $value ) {
147 1
		if ($offset == "") {
148
			$this->currentList[] = $value;
149
		} else {
150 1
			$this->currentList[$offset] = $value;
151
		}
152 1
	}
153
154
	public function offsetExists( $offset ) {
155
		return ( $this->getEntry( $offset ) !== null );
156
	}
157
158
	public function offsetUnset( $offset ) {
159
		unset($this->currentList[$offset]);
160
	}
161
162 7
	private function getEntry( $offset ) {
163 7 View Code Duplication
		if( isset( $this->currentList[$offset] ) ) {
164 7
			return $this->currentList[$offset];
165
		} elseif( strpos($offset, ":") !== false ) { // $ARnls["ariadne:foo"] => try and autoload "ariadne.$currentLanguage"
166
			list($section, $rest) = explode(":", $offset, 2);
0 ignored issues
show
The assignment to $rest is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
167
			$this->load($section, $this->currentLanguage);
168
			if( isset( $this->currentList[$offset] ) ) {
169
				return $this->currentList[$offset];
170
			}
171
		}
172 View Code Duplication
		if( isset( $this->defaultList[$offset] ) ) {
173
			return $this->defaultList[$offset];
174
		} elseif( strpos($offset, ":") !== false ) { // $ARnls["ariadne:foo"] => try and autoload "ariadne.$defaultLanguage"
175
			list($section, $rest) = explode(":", $offset, 2);
0 ignored issues
show
The assignment to $rest is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
176
			$this->load($section, $this->defaultLanguage);
177
			if( isset( $this->defaultList[$offset] ) ) {
178
				return $this->defaultList[$offset];
179
			}
180
		}
181
		return null;
182
	}
183
184
185 7
	public function offsetGet( $offset ) {
186 7
		$value = $this->getEntry( $offset );
187 7
		return ( isset( $value ) ? $value : "{".$offset."}" );
188
	}
189
190
	/* Iterator */
191
	public function current() {
192
		return current($this->currentList);
193
	}
194
195
	public function key() {
196
		return key($this->currentList);
197
	}
198
199
	public function next() {
200
		return next($this->currentList);
201
	}
202
203
	public function rewind() {
204
		return reset($this->currentList);
205
	}
206
207
	public function valid() {
208
		$value = key($this->currentList);
209
		return isset($value);
210
	}
211
212
}
213