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.

engine/classes/Elgg/Config.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
namespace Elgg;
3
4
5
/**
6
 * WARNING: API IN FLUX. DO NOT USE DIRECTLY.
7
 *
8
 * @access private
9
 *
10
 * @package    Elgg.Core
11
 * @subpackage Config
12
 * @since      1.10.0
13
 */
14
class Config {
15
	/**
16
	 * Global Elgg configuration
17
	 * 
18
	 * @var \stdClass
19
	 */
20
	private $CONFIG;
21
22
	/**
23
	 * Constructor
24
	 */
25 2
	public function __construct() {
26 2
		global $CONFIG;
27 2
		$this->CONFIG = $CONFIG;
28 2
	}
29
30
	/**
31
	 * Get the URL for the current (or specified) site
32
	 *
33
	 * @param int $site_guid The GUID of the site whose URL we want to grab
34
	 * @return string
35
	 */
36 30
	function getSiteUrl($site_guid = 0) {
37 30
		if ($site_guid == 0) {
38
			
39 30
			return $this->CONFIG->wwwroot;
40
		}
41
	
42
		$site = get_entity($site_guid);
43
	
44
		if (!$site instanceof \ElggSite) {
45
			return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by Elgg\Config::getSiteUrl of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
46
		}
47
		/* @var \ElggSite $site */
48
	
49
		return $site->url;
50
	}
51
	
52
	/**
53
	 * Get the plugin path for this installation
54
	 *
55
	 * @return string
56
	 */
57
	function getPluginsPath() {
58
		
59
		return $this->CONFIG->pluginspath;
60
	}
61
	
62
	/**
63
	 * Get the data directory path for this installation
64
	 *
65
	 * @return string
66
	 */
67
	function getDataPath() {
68
		
69
		return $this->CONFIG->dataroot;
70
	}
71
	
72
	/**
73
	 * Get the root directory path for this installation
74
	 *
75
	 * @return string
76
	 */
77
	function getRootPath() {
78
		
79
		return $this->CONFIG->path;
80
	}
81
	
82
	/**
83
	 * Get an Elgg configuration value
84
	 *
85
	 * @param string $name      Name of the configuration value
86
	 * @param int    $site_guid null for installation setting, 0 for default site
87
	 *
88
	 * @return mixed Configuration value or null if it does not exist
89
	 */
90 1
	function get($name, $site_guid = 0) {
91
		
92
	
93 1
		$name = trim($name);
94
	
95
		// do not return $CONFIG value if asking for non-current site
96 1
		if (($site_guid === 0 || $site_guid === null || $site_guid == $this->CONFIG->site_guid) && isset($this->CONFIG->$name)) {
97 1
			return $this->CONFIG->$name;
98
		}
99
	
100
		if ($site_guid === null) {
101
			// installation wide setting
102
			$value = _elgg_services()->datalist->get($name);
103
		} else {
104
			if ($site_guid == 0) {
105
				$site_guid = (int) $this->CONFIG->site_guid;
106
			}
107
	
108
			// hit DB only if we're not sure if value isn't already loaded
109
			if (!isset($this->CONFIG->site_config_loaded) || $site_guid != $this->CONFIG->site_guid) {
110
				// site specific setting
111
				$value = _elgg_services()->configTable->get($name, $site_guid);
112
			} else {
113
				$value = null;
114
			}
115
		}
116
	
117
		// @todo document why we don't cache false
118
		if ($value === false) {
119
			return null;
120
		}
121
	
122 View Code Duplication
		if ($site_guid == $this->CONFIG->site_guid || $site_guid === null) {
123
			$this->CONFIG->$name = $value;
124
		}
125
	
126
		return $value;
127
	}
128
	
129
	/**
130
	 * Set an Elgg configuration value
131
	 *
132
	 * @warning This does not persist the configuration setting. Use elgg_save_config()
133
	 *
134
	 * @param string $name  Name of the configuration value
135
	 * @param mixed  $value Value
136
	 *
137
	 * @return void
138
	 */
139
	function set($name, $value) {
140
		
141
	
142
		$name = trim($name);
143
	
144
		$this->CONFIG->$name = $value;
145
	}
146
	
147
	/**
148
	 * Save a configuration setting
149
	 *
150
	 * @param string $name      Configuration name (cannot be greater than 255 characters)
151
	 * @param mixed  $value     Configuration value. Should be string for installation setting
152
	 * @param int    $site_guid null for installation setting, 0 for default site
153
	 *
154
	 * @return bool
155
	 */
156
	function save($name, $value, $site_guid = 0) {
157
		
158
	
159
		$name = trim($name);
160
	
161
		if (strlen($name) > 255) {
162
			_elgg_services()->logger->error("The name length for configuration variables cannot be greater than 255");
163
			return false;
164
		}
165
	
166
		if ($site_guid === null) {
167
			if (is_array($value) || is_object($value)) {
168
				return false;
169
			}
170
			$result = _elgg_services()->datalist->set($name, $value);
171
		} else {
172
			if ($site_guid == 0) {
173
				$site_guid = (int) $this->CONFIG->site_guid;
174
			}
175
			$result = _elgg_services()->configTable->set($name, $value, $site_guid);
176
		}
177
	
178 View Code Duplication
		if ($site_guid === null || $site_guid == $this->CONFIG->site_guid) {
179
			_elgg_services()->config->set($name, $value);
180
		}
181
	
182
		return $result;
183
	}
184
}