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/modules/mod_xml.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
	class pinp_xml {
3
		public static function _parser() {
4
			$context = pobject::getContext();
5
			$me      = $context['arCurrentObject'];
6
			$parser = new xml_parser($me);
7
			return $parser;
8
		}
9
10
		public static function _escape($text) {
11
			$search  = array('&','"',"'",'<','>');
12
			$replace = array('&amp;','&quot;','&apos;','&lt;','&gt;');
13
			return str_replace($search, $replace, $text);
14
		}
15
16
		public static function _unescape($text) {
17
			$search  = array('&quot;','&apos;','&lt;','&gt;','&amp;');
18
			$replace = array('"',"'",'<','>','&');
19
			return str_replace($search, $replace, $text);
20
		}
21
22
	};
23
24
	class xml_parser {
25
		protected $object;
26
		protected $tag_open_template;
27
		protected $tag_class_template;
28
		protected $tag_data_template;
29
		protected $ns = array();
30
		public $elements;
31
		public $MULTI_TAGS;
32
		public $error;
33
		public $rss_items;
34
35
36
		public function __construct($object) {
37
			$this->object = $object;
38
		}
39
40
		public function _set_element_handler($tag_open, $tag_close) {
41
			$this->tag_open_template = $tag_open;
42
			$this->tag_close_template = $tag_close;
0 ignored issues
show
The property tag_close_template 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...
43
		}
44
45
		public function _set_character_data_handler($tag_data) {
46
			$this->tag_data_template = $tag_data;
47
		}
48
49
		public function _parse($string) {
50
			$parser = xml_parser_create();
51
			xml_set_object($parser, $this);
52
			xml_set_element_handler($parser, "call_tag_open", "call_tag_close");
53
			xml_set_character_data_handler($parser, "call_tag_data");
54 View Code Duplication
			if (!xml_parse($parser, $string)) {
55
				$this->error = sprintf("XML error: %s at line %d",
56
					xml_error_string(xml_get_error_code($parser)),
57
						xml_get_current_line_number($parser));
58
			}
59
		}
60
61
		public function _get_array($string, $MULTI_TAGS = array()) {
62
			$parser = xml_parser_create();
63
			$this->elements = array();
64
			$this->MULTI_TAGS = array();
65
			foreach ($MULTI_TAGS as $tag) {
66
				$this->MULTI_TAGS[] = strtoupper($tag);
67
			}
68
			xml_set_object($parser, $this);
69
			xml_set_element_handler($parser, "startElement", "endElement");
70
			xml_set_character_data_handler($parser, "characterData");
71 View Code Duplication
			if (!xml_parse($parser, $string)) {
72
				$this->error = sprintf("XML error: %s at line %d",
73
					xml_error_string(xml_get_error_code($parser)),
74
						xml_get_current_line_number($parser));
75
			}
76
77
			return $this->elements;
78
		}
79
80
		public function _parse_url($url) {
81
			if (!preg_match('|^https?://|i', $url)) {
82
				$this->error = "Not a valid URL ($url)";
83
			} else {
84
				$parser = xml_parser_create();
85
				xml_set_object($parser, $this);
86
				xml_set_element_handler($parser, "call_tag_open", "call_tag_close");
87
				xml_set_character_data_handler($parser, "call_tag_data");
88
				$fp = fopen($url, "r");
89
				if (!$fp) {
90
					$this->error = "Could not open ($url)";
91
				} else {
92
					while (!$this->error && !feof($fp)) {
93
						$string = fread($fp, 4096);
94 View Code Duplication
						if (!xml_parse($parser, $string)) {
95
							$this->error = sprintf("XML error: %s at line %d",
96
								xml_error_string(xml_get_error_code($parser)),
97
									xml_get_current_line_number($parser));
98
						}
99
					}
100
					fclose($fp);
101
				}
102
			}
103
		}
104
105
		public function _parse_curl($url) {
106
			if (!preg_match('|^https?://|i', $url)) {
107
				$this->error = "Not a valid URL ($url)";
108
			} else {
109
				$parser = xml_parser_create();
110
				xml_set_object($parser, $this);
111
				xml_set_element_handler($parser, "call_tag_open", "call_tag_close");
112
				xml_set_character_data_handler($parser, "call_tag_data");
113
114
				$ch = curl_init($url);
115
116
				curl_setopt($ch, CURLOPT_HEADER, 0);
117
				curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
118
119
				$string = curl_exec($ch);
120
				curl_close($ch);
121 View Code Duplication
				if (!xml_parse($parser, $string)) {
122
					$this->error = sprintf("XML error: %s at line %d",
123
					xml_error_string(xml_get_error_code($parser)),
124
					xml_get_current_line_number($parser));
125
				}
126
127
			}
128
		}
129
130
		public function call_tag_open($parser, $tag, $attributes) {
0 ignored issues
show
The parameter $parser 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...
131
			global $ARBeenHere;
132
			$ARBeenHere = array();
133
			if ($this->tag_open_template) {
134
				$this->object->call($this->tag_open_template, array("tag" => $tag, "attributes" => $attributes));
135
			}
136
		}
137
138
		public function call_tag_close($parser, $tag) {
0 ignored issues
show
The parameter $parser 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...
139
			global $ARBeenHere;
140
			$ARBeenHere = array();
141
			if ($this->tag_close_template) {
142
				$this->object->call($this->tag_close_template, array("tag" => $tag));
143
			}
144
		}
145
146
		public function call_tag_data($parser, $data) {
0 ignored issues
show
The parameter $parser 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...
147
			global $ARBeenHere;
148
			$ARBeenHere = array();
149
			if ($this->tag_data_template) {
150
				$this->object->call($this->tag_data_template, array("tag_data" => $data));
151
			}
152
		}
153
154
155
		public function startElement($parser, $name, $attribs) {
0 ignored issues
show
The parameter $parser 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...
156
		//global $MULTI_TAGS;
157
			$newElement = array();
158
			$element = &$this->elements;
159
160
			if (is_array($this->ns)) {
161
				foreach ($this->ns as $n) {
162
					$element = &$element[$n];
163
				}
164
			}
165
166
			$this->ns[] = $name;
167
			$newElement[':attribs'] = $attribs;
168
			if (!in_array($name, $this->MULTI_TAGS)) {
169
				$element[$name] = $newElement;
170
			} else {
171
				$element[$name][] = $newElement;
172
				$this->ns[] = count($element[$name])-1;
173
			}
174
		}
175
176
		public function endElement($parser, $name) {
0 ignored issues
show
The parameter $parser 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...
177
		//global $MULTI_TAGS;
178
			$element = &$this->elements;
179
			foreach ($this->ns as $n) {
180
				$parentElement = $element;
181
				$element = &$element[$n];
182
			}
183
			switch ($name) {
184
				case 'item':
185
					$this->rss_items[] = $element;
186
					unset($parentElement[$name]);
187
				break;
188
			}
189
			$parent = $this->ns[count($this->ns)-2];
190
			if (in_array($parent, $this->MULTI_TAGS) && $parent === $name) {
191
				array_pop($this->ns);
192
			}
193
			array_pop($this->ns);
194
		}
195
196
		public function characterData($parser, $data) {
0 ignored issues
show
The parameter $parser 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...
197
			$element = &$this->elements;
198
			$name = "";
199
			foreach ($this->ns as $n) {
200
				$name .= ":$n";
201
				$element = &$element[$n];
202
			}
203
			switch ($n) {
0 ignored issues
show
The variable $n seems to be defined by a foreach iteration on line 199. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
204
				// do not put anything else above this line
205
				// or else '0' values will trigger it.
206
				case 0:
207
				default:
208
					if (!$element) {
209
						$element = array();
210
					}
211
					$element[':data'] .= $data;
212
				break;
213
			}
214
		}
215
	}
216