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/groups/lib/discussion.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
 * Discussion function library
4
 */
5
6
/**
7
 * List all discussion topics
8
 */
9
function discussion_handle_all_page() {
10
11
	elgg_pop_breadcrumb();
12
	elgg_push_breadcrumb(elgg_echo('discussion'));
13
14
	$content = elgg_list_entities(array(
15
		'type' => 'object',
16
		'subtype' => 'groupforumtopic',
17
		'order_by' => 'e.last_action desc',
18
		'limit' => max(20, elgg_get_config('default_limit')),
19
		'full_view' => false,
20
		'no_results' => elgg_echo('discussion:none'),
21
		'preload_owners' => true,
22
		'preload_containers' => true,
23
	));
24
25
	$title = elgg_echo('discussion:latest');
26
27
	$params = array(
28
		'content' => $content,
29
		'title' => $title,
30
		'sidebar' => elgg_view('discussion/sidebar'),
31
		'filter' => '',
32
	);
33
	$body = elgg_view_layout('content', $params);
34
35
	echo elgg_view_page($title, $body);
36
}
37
38
/**
39
 * List discussion topics in a group
40
 *
41
 * @param int $guid Group entity GUID
42
 */
43
function discussion_handle_list_page($guid) {
44
	$lang = get_current_language();
45
	elgg_set_page_owner_guid($guid);
46
47
	elgg_group_gatekeeper();
48
49
	$group = get_entity($guid);
50
	if (!elgg_instanceof($group, 'group')) {
51
		forward('', '404');
52
	}
53
	elgg_push_breadcrumb(gc_explode_translation($group->name,$lang), $group->getURL());
54
	elgg_push_breadcrumb(elgg_echo('item:object:groupforumtopic'));
55
56
	elgg_register_title_button();
57
58
	$title = elgg_echo('item:object:groupforumtopic');
59
60
	$options = array(
61
		'type' => 'object',
62
		'subtype' => 'groupforumtopic',
63
		'limit' => max(20, elgg_get_config('default_limit')),
64
		'order_by' => 'e.last_action desc',
65
		'container_guid' => $guid,
66
		'full_view' => false,
67
		'no_results' => elgg_echo('discussion:none'),
68
		'preload_owners' => true,
69
	);
70
	$content = elgg_list_entities($options);
71
72
	$params = array(
73
		'content' => $content,
74
		'title' => $title,
75
		'sidebar' => elgg_view('discussion/sidebar'),
76
		'filter' => '',
77
	);
78
79
	$body = elgg_view_layout('content', $params);
80
81
	echo elgg_view_page($title, $body);
82
}
83
84
/**
85
 * Edit or add a discussion topic
86
 *
87
 * @param string $type 'add' or 'edit'
88
 * @param int    $guid GUID of group or topic
89
 */
90
function discussion_handle_edit_page($type, $guid) {
91
	elgg_gatekeeper();
92
	$lang = get_current_language();
93
94
95
	if ($type == 'add') {
96
		$group = get_entity($guid);
97
		if (!elgg_instanceof($group, 'group')) {
98
			register_error(elgg_echo('group:notfound'));
99
			forward();
100
		}
101
102
		// make sure user has permissions to add a topic to container
103
		if (!$group->canWriteToContainer(0, 'object', 'groupforumtopic')) {
104
			register_error(elgg_echo('groups:permissions:error'));
105
			forward($group->getURL());
106
		}
107
108
		$title = elgg_echo('groups:addtopic');
109
110
		elgg_push_breadcrumb(gc_explode_translation($group->name,$lang), "discussion/owner/$group->guid");
111
		elgg_push_breadcrumb($title);
112
113
		$body_vars = discussion_prepare_form_vars();
114
		$content = elgg_view_form('discussion/save', array(), $body_vars);
115
	} else {
116
		$topic = get_entity($guid);
117 View Code Duplication
		if (!elgg_instanceof($topic, 'object', 'groupforumtopic') || !$topic->canEdit()) {
118
			register_error(elgg_echo('discussion:topic:notfound'));
119
			forward();
120
		}
121
		$group = $topic->getContainerEntity();
122
		if (!elgg_instanceof($group, 'group')) {
123
			register_error(elgg_echo('group:notfound'));
124
			forward();
125
		}
126
127
		$title = elgg_echo('groups:edittopic');
128
129
		elgg_push_breadcrumb(gc_explode_translation($group->title,$lang), "discussion/owner/$group->guid");
130
		elgg_push_breadcrumb(gc_explode_translation($topic->title,$lang), $topic->getURL());
131
		elgg_push_breadcrumb($title);
132
133
		$body_vars = discussion_prepare_form_vars($topic);
0 ignored issues
show
$topic is of type object<ElggEntity>, but the function expects a object<ElggObject>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
134
		$content = elgg_view_form('discussion/save', array(), $body_vars);
135
	}
136
137
138
	$params = array(
139
		'content' => $content,
140
		'title' => $title,
141
		'sidebar' => elgg_view('discussion/sidebar/edit'),
142
		'filter' => '',
143
	);
144
	$body = elgg_view_layout('content', $params);
145
146
	echo elgg_view_page($title, $body);
147
}
148
149
/**
150
 * Edit discussion reply
151
 *
152
 * @param string $type 'edit'
153
 * @param int    $guid GUID of group or topic
154
 */
155
function discussion_handle_reply_edit_page($type, $guid) {
156
	elgg_gatekeeper();
157
158
	if ($type == 'edit') {
159
		$reply = get_entity($guid);
160
		if (!elgg_instanceof($reply, 'object', 'discussion_reply', 'ElggDiscussionReply') || !$reply->canEdit()) {
161
			register_error(elgg_echo('discussion:reply:error:notfound'));
162
			forward();
163
		}
164
		$topic = $reply->getContainerEntity();
165
		if (!elgg_instanceof($topic, 'object', 'groupforumtopic')) {
166
			register_error(elgg_echo('discussion:topic:notfound'));
167
			forward();
168
		}
169
		$group = $topic->getContainerEntity();
170
		if (!elgg_instanceof($group, 'group')) {
171
			register_error(elgg_echo('group:notfound'));
172
			forward();
173
		}
174
175
		$title = elgg_echo('discussion:reply:edit');
176
177
		elgg_push_breadcrumb($group->name, "discussion/owner/$group->guid");
178
		elgg_push_breadcrumb($topic->title, $topic->getURL());
179
		elgg_push_breadcrumb($title);
180
181
		$params = array(
182
			'guid' => $reply->guid,
183
			'hidden' => false,
184
		);
185
		$content = elgg_view('ajax/discussion/reply/edit', $params);
186
	}
187
188
	$params = array(
189
		'content' => $content,
0 ignored issues
show
The variable $content does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
190
		'title' => $title,
0 ignored issues
show
The variable $title does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
191
		'sidebar' => elgg_view('discussion/sidebar/edit'),
192
		'filter' => '',
193
	);
194
	$body = elgg_view_layout('content', $params);
195
196
	echo elgg_view_page($title, $body);
197
}
198
199
/**
200
 * View a discussion topic
201
 *
202
 * @param int $guid GUID of topic
203
 */
204
function discussion_handle_view_page($guid) {
205
	// We now have RSS on topics
206
	global $autofeed;
207
	$autofeed = true;
208
	$lang = get_current_language();
209
	elgg_entity_gatekeeper($guid, 'object', 'groupforumtopic');
210
211
	$topic = get_entity($guid);
212
//$topic->description =  gc_explode_translation($topic->description, $lang); //change content to translation description   
213
	$group = $topic->getContainerEntity();
214
	if (!elgg_instanceof($group, 'group')) {
215
		register_error(elgg_echo('group:notfound'));
216
		forward();
217
	}
218
219
	elgg_load_js('elgg.discussion');
220
221
	elgg_set_page_owner_guid($group->getGUID());
222
223
	elgg_group_gatekeeper();
224
225
	
226
		elgg_push_breadcrumb(gc_explode_translation($group->title,$lang), "discussion/owner/$group->guid");
227
228
	elgg_push_breadcrumb(gc_explode_translation($topic->title, $lang));
229
230
231
	$params = array(
232
		'topic' => $topic,
233
		'show_add_form' => false,
234
	);
235
236
237
	$content = elgg_view_entity($topic, array('full_view' => true, ));
238
	if ($topic->status == 'closed') {
239
		$content .= elgg_view('discussion/replies', $params);
240
		$content .= elgg_view('discussion/closed');
241
	} elseif ($group->canWriteToContainer(0, 'object', 'groupforumtopic') || elgg_is_admin_logged_in()) {
242
		$params['show_add_form'] = true;
243
		$content .= elgg_view('discussion/replies', $params);
244
	} else {
245
		$content .= elgg_view('discussion/replies', $params);
246
	}
247
248
   $title = gc_explode_translation($topic->title, $lang);
249
250
	$params = array(
251
		'content' => $content,
252
		'title' =>$title,
253
		'sidebar' => elgg_view('discussion/sidebar'),
254
		'filter' => '',
255
	);
256
	$body = elgg_view_layout('content', $params);
257
258
	echo elgg_view_page($topic->title, $body);
259
}
260
261
/**
262
 * Prepare discussion topic form variables
263
 *
264
 * @param ElggObject $topic Topic object if editing
265
 * @return array
266
 */
267 View Code Duplication
function discussion_prepare_form_vars($topic = NULL) {
268
	// input names => defaults
269
	$lang = get_current_language();
270
	$values = array(
271
		'title' => '',
272
		'title2' => '',
273
		'description' => '',
274
		'description2' => '',
275
		'status' => '',
276
		'access_id' => ACCESS_DEFAULT,
277
		'tags' => '',
278
		'container_guid' => elgg_get_page_owner_guid(),
279
		'guid' => null,
280
		'topic' => $topic,
281
	);
282
283
	if ($topic) {
284
		foreach (array_keys($values) as $field) {
285
			if (isset($topic->$field)) {
286
287
					$values[$field] = $topic->$field;
288
			}
289
		}
290
	}
291
292
	if (elgg_is_sticky_form('topic')) {
293
		$sticky_values = elgg_get_sticky_values('topic');
294
		foreach ($sticky_values as $key => $value) {
295
			$values[$key] = $value;
296
		}
297
	}
298
299
	elgg_clear_sticky_form('topic');
300
301
	return $values;
302
}
303