Issues (2473)

Branch: master

Security Analysis    no vulnerabilities found

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.

mod/garbagecollector/start.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
 * Elgg garbage collector.
4
 *
5
 * @package ElggGarbageCollector
6
 */
7
8
elgg_register_event_handler('init', 'system', 'garbagecollector_init');
9
10
function garbagecollector_init() {
11
	$period = elgg_get_plugin_setting('period', 'garbagecollector');
12
	switch ($period) {
13
		case 'weekly':
14
		case 'monthly':
15
		case 'yearly':
16
			break;
17
		default:
18
			$period = 'monthly';
19
	}
20
21
	// Register cron hook
22
	elgg_register_plugin_hook_handler('cron', $period, 'garbagecollector_cron');
23
	
24
	elgg_register_plugin_hook_handler('gc', 'system', 'garbagecollector_orphaned_metastrings');
25
	elgg_register_plugin_hook_handler('gc', 'system', 'garbagecollector_entities');
26
}
27
28
/**
29
 * Cron job
30
 */
31
function garbagecollector_cron($hook, $entity_type, $returnvalue, $params) {
32
33
	echo elgg_echo('garbagecollector') . "\n";
34
35
	// Now, because we are nice, trigger a plugin hook to let other plugins do some GC
36
	$rv = true;
37
	$period = elgg_get_plugin_setting('period','garbagecollector');
38
	elgg_trigger_plugin_hook('gc', 'system', array('period' => $period));
39
40
	// Now we optimize all tables
41
//	$tables = get_db_tables();
42
//	foreach ($tables as $table) {
43
//		echo elgg_echo('garbagecollector:optimize', array($table));
44
//
45
//		if (optimize_table($table) !== false) {
46
//			echo elgg_echo('garbagecollector:ok');
47
//		} else {
48
//			echo elgg_echo('garbagecollector:error');
49
//		}
50
//
51
//		echo "\n";
52
//	}
53
54
	echo elgg_echo('garbagecollector:done');
55
}
56
57
/**
58
 * Get array of table names
59
 *
60
 * @return array
61
 */
62
function garbagecollector_get_tables() {
63
	static $tables;
64
65
	if (isset($tables)) {
66
		return $tables;
67
	}
68
69
	$table_prefix = elgg_get_config('dbprefix');
70
	$result = get_data("SHOW TABLES LIKE '$table_prefix%'");
71
72
	$tables = array();
73 View Code Duplication
	if (is_array($result) && !empty($result)) {
74
		foreach ($result as $row) {
75
			$row = (array) $row;
76
			if (is_array($row) && !empty($row)) {
77
				foreach ($row as $element) {
78
					$tables[] = $element;
79
				}
80
			}
81
		}
82
	}
83
84
	return $tables;
85
}
86
87
/**
88
 * Optimize a table
89
 *
90
 * @param string $table Database table name
91
 * @return bool
92
 */
93
function garbagecollector_optimize_table($table) {
94
	$table = sanitise_string($table);
95
	return update_data("OPTIMIZE TABLE $table");
96
}
97
98
/**
99
 * Garbage collect stub and fragments from any broken delete/create calls
100
 *
101
 * @return void
102
 */
103
function garbagecollector_entities() {
104
	$dbprefix = elgg_get_config('dbprefix');
105
106
	$tables = array(
107
		'site' => 'sites_entity',
108
		'object' => 'objects_entity',
109
		'group' => 'groups_entity',
110
		'user' => 'users_entity',
111
	);
112
113
	foreach ($tables as $type => $table) {
114
		delete_data("DELETE FROM {$dbprefix}{$table}
115
		WHERE guid NOT IN (SELECT guid FROM {$dbprefix}entities)");
116
		delete_data("DELETE FROM {$dbprefix}entities
117
		WHERE type = '$type' AND guid NOT IN (SELECT guid FROM {$dbprefix}{$table})");
118
	}
119
}
120
121
/**
122
 * Delete any orphaned entries in metastrings.
123
 *
124
 * @return void
125
 */
126
function garbagecollector_orphaned_metastrings() {
127
	$dbprefix = elgg_get_config('dbprefix');
128
	
129
	// Garbage collect metastrings
130
	echo elgg_echo('garbagecollector:gc:metastrings');
131
132
	// If memcache is enabled then we need to flush it of deleted values
133
	if (is_memcache_available()) {
134
		$select_query = "
135
		SELECT * FROM {$dbprefix}metastrings WHERE
136
		(
137
			(id NOT IN (SELECT name_id FROM {$dbprefix}metadata)) AND
138
			(id NOT IN (SELECT value_id FROM {$dbprefix}metadata)) AND
139
			(id NOT IN (SELECT name_id FROM {$dbprefix}annotations)) AND
140
			(id NOT IN (SELECT value_id FROM {$dbprefix}annotations))
141
		)";
142
143
		$dead = get_data($select_query);
144
		if ($dead) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $dead of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
145
			static $metastrings_memcache;
146
			
147
			if (!$metastrings_memcache) {
148
				$metastrings_memcache = new \ElggMemcache('metastrings_memcache');
149
			}
150
151
			foreach ($dead as $d) {
152
				$metastrings_memcache->delete($d->string);
153
			}
154
		}
155
	}
156
157
	$query = "
158
		DELETE FROM {$dbprefix}metastrings WHERE
159
		(
160
			(id NOT IN (SELECT name_id FROM {$dbprefix}metadata)) AND
161
			(id NOT IN (SELECT value_id FROM {$dbprefix}metadata)) AND
162
			(id NOT IN (SELECT name_id FROM {$dbprefix}annotations)) AND
163
			(id NOT IN (SELECT value_id FROM {$dbprefix}annotations))
164
		)";
165
166
	$result = delete_data($query);
167
	
168
	if ($result !== false) {
169
		echo elgg_echo('garbagecollector:ok');
170
	} else {
171
		echo elgg_echo('garbagecollector:error');
172
	}
173
}
174