Issues (4714)

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.

src/Intraface/ModuleHandler.php (10 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
 * Module
4
 *
5
 * @package Intraface
6
 * @author  Lars Olesen <[email protected]>
7
 * @author  Sune Jensen <[email protected]>
8
 * @since   0.1.0
9
 * @version @package-version@
10
 */
11
class Intraface_ModuleHandler
12
{
13
    private $user;
14
    private $internet;
0 ignored issues
show
The property $internet is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
    private $modules = array();
16
    private $primary_module_name;
17
    private $primary_module_object;
18
    private $shared = array();
19
20 94
    public function __construct($intranet = '', $user = '')
21
    {
22 94
        $this->user = $user;
23 94
        $this->intranet = $intranet;
0 ignored issues
show
The property intranet 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...
24 94
    }
25
26
    /**
27
     * Returns the primary module
28
     *
29
     * Used for instance in Page to give the correct submenu.
30
     *
31
     * @return module object or false
32
     */
33 1
    function getPrimaryModule()
34
    {
35 1
        if (!empty($this->modules[$this->primary_module_name]) and is_object($this->modules[$this->primary_module_name])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
36 1
            return($this->modules[$this->primary_module_name]);
37
        } else {
38 1
            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 Intraface_ModuleHandler::getPrimaryModule of type Module.

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...
39
        }
40
    }
41
42 28
    function setPrimaryModule($module_name)
43
    {
44 28
        if (!empty($this->primary_module_object) and is_object($this->primary_module_object)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
45
            throw new Exception('Primary module has been set');
46
        } else {
47 28
            $module = $this->useModule($module_name);
48
49 27
            if (is_object($module)) {
50 27
                $this->primary_module_name = $module_name;
51
52
                // Finds dependent modules
53
                // @todo Maybe this should be moved to useModule()
54 27
                $dependent_modules = $module->getDependentModules();
55
56 27
                foreach ($dependent_modules as $dependent) {
57
                    $no_use = $this->useModule($dependent);
0 ignored issues
show
$no_use is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58 27
                }
59
60 27
                return $module;
61
            } else {
62
                // @todo Den fejlmeddelse er egentlig irrelevant, da useModul ikke enten returnere et objekt eller throw new Exception.
63
                throw new Exception('Du har ikke adgang til modulet');
64
            }
65
        }
66
    }
67
68
    /**
69
     * useModule()
70
     *
71
     * @todo Need to handle access
72
     *
73
     * @param  string  $module_name
74
     * @param  boolean $ignore_user_access
75
     *
76
     * @return object  $module
77
     */
78 90
    public function useModule($module_name, $ignore_user_access = false)
79
    {
80 90
        if (!self::isValidModuleName($module_name)) {
81 1
            throw new Exception($module_name . ' is not a valid module name');
82
        }
83
84 89
        if (!empty($this->modules[$module_name]) and is_object($this->modules[$module_name])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
85 25
            return $this->modules[$module_name];
86
        }
87
88 89
        $this->modules[$module_name] = $module_name;
89
90
        // @todo check whether a module has any limitations in access here? - we have not asked for shared
91
92
        // access control here
93 89
        $access = false;
94
95 89
        if (!is_object($this->user)) {
96 9
            if (!is_object($this->intranet)) {
97 2
                throw new Exception('Cannot use a module when no intranet is available');
98
            }
99
            // Det er et weblogin.
100 7
            if ($this->intranet->hasModuleAccess($module_name)) {
101 6
                $access = true;
102 6
            }
103 87
        } elseif ($ignore_user_access) {
104
            if (!is_object($this->intranet)) {
105
                throw new Exception('Cannot use a module when no intranet is available');
106
            }
107
            // Skal kun kontrollere om intranettet har adgang, for at benytte modullet
108
            if ($this->intranet->hasModuleAccess($module_name)) {
109
                $access = true;
110
            }
111
        } else {
112
            // Almindelig login
113 80
            if ($this->user->hasModuleAccess($module_name)) {
114 79
                $access = true;
115 79
            }
116
        }
117
118 87
        if ($access !== true) {
119 2
            throw new Exception('You need access to a required module to see this page, maybe it is ' . $module_name);
120
        }
121
122 85
        $main_class_name = "Main" . ucfirst($module_name);
123 85
        $main_class_path = PATH_INCLUDE_MODULE . $module_name . "/" . $main_class_name . ".php";
124
125 85
        if (file_exists($main_class_path)) {
126 85
            require_once($main_class_path);
127 85
            $object = new $main_class_name;
128 85
            $object->load($this);
129 85
            $this->modules[$module_name] = $object;
130 85
            return $object;
131
        } else {
132
            // @TODO this should not fail as hard - but what should happen then?
133
            throw new Exception('ModuleHandler: ' . $main_class_path . ' does not exist');
134
        }
135
    }
136
137
    /**
138
     * Gives access to a shared module
139
     *
140
     * @param string $shared_name Name on module to load
141
     *
142
     * @return object or false
143
     */
144 63
    public function useShared($shared_name)
145
    {
146 63
        if (!self::isValidModuleName($shared_name)) {
147
            throw new Exception($shared_name. ' is not a valid shared module name');
148
        }
149
150
        // Tjekker om shared allerede er loaded
151 63
        if (!empty($this->shared[$shared_name]) and is_object($this->shared[$shared_name])) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
152 36
            return $this->shared[$shared_name];
153
        }
154
155 63
        $main_shared_name = 'Shared' . ucfirst($shared_name);
156 63
        $main_shared_path = PATH_INCLUDE_SHARED . $shared_name . '/' . $main_shared_name . '.php';
157
158 63
        if (file_exists($main_shared_path)) {
159 63
            require_once $main_shared_path;
160 63
            $object = new $main_shared_name;
161 63
            $object->load();
162 63
            $this->shared[$shared_name] = $object;
163 63
            return $object;
164
        } else {
165
            throw new Exception($shared_name . ' cannot be found on ' . $main_shared_path . ' with PATH_INCLUDE_SHARED: ' . PATH_INCLUDE_SHARED);
166
        }
167
    }
168
169
    /**
170
     * getModule()
171
     *
172
     * @param string $module_name
0 ignored issues
show
There is no parameter named $module_name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
173
     *
174
     * @return object
175
     */
176 2
    function getModule($name)
177
    {
178 2
        if (is_object($this->modules[$name])) {
179 2
            return($this->modules[$name]);
180
        } else {
181
            throw new Exception('getModule() module ' . $name . ' not loaded');
182
        }
183
    }
184
185
    /**
186
     * getModules()
187
     *
188
     * @param string $order_by
189
     *
190
     * @return array
191
     */
192 2
    public static function getModules($db, $order_by = 'frontpage_index')
193
    {
194 2
        $modules = array();
195
196 2
        if ($order_by != '') {
197 2
            $order_by = "ORDER BY ".$db->quoteIdentifier($order_by, 'text');
198 2
        }
199
200 2
        $i = 0;
201 2
        $result = $db->query("SELECT id, menu_label, name, show_menu FROM module WHERE active = 1 ".$order_by);
202 2
        if (PEAR::isError($result)) {
203
            throw new Exception($result->getUserInfo());
204
        }
205 2
        while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
206 2
            $modules[$i]['id'] = $row['id'];
207 2
            $modules[$i]['name'] = $row['name'];
208 2
            $modules[$i]['menu_label'] = $row['menu_label'];
209 2
            $modules[$i]['show_menu'] = $row['show_menu'];
210
211 2
            $j = 0;
212 2
            $result_sub = $db->query("SELECT id, description FROM module_sub_access WHERE active = 1 AND module_id = ".$db->quote($row["id"], 'integer')." ORDER BY description");
213 2
            if (PEAR::isError($result_sub)) {
214
                throw new Exception($result_sub->getUserInfo());
215
            }
216
217 2
            while ($row_sub = $result_sub->fetchRow(MDB2_FETCHMODE_ASSOC)) {
218 2
                $modules[$i]['sub_access'][$j]['id'] = $row_sub['id'];
219 2
                $modules[$i]['sub_access'][$j]['description'] = $row_sub['description'];
220 2
                $j++;
221 2
            }
222
223 2
            $i++;
224 2
        }
225 2
        return $modules;
226
    }
227
228
    /**
229
     * Function to check whether the module has been registered
230
     * Made temporarily for /main/index.php
231
     */
232
    public static function exists($db, $module_id)
233
    {
234
        if (is_numeric($module_id)) {
235
            throw new Exception("Not yet implemented!");
236
        } else {
237
            $result = $db->query('SELECT id FROM module WHERE name = '.$db->quote($module_id, 'text'));
238
            if (PEAR::isError($result)) {
239
                throw new Exception('Error in query: '.$result->getUserInfo());
240
            }
241
242
            if ($result->numRows() > 0) {
243
                return true;
244
            } else {
245
                return false;
246
            }
247
        }
248
        return false;
0 ignored issues
show
return false; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
249
    }
250
251 92
    private static function isValidModuleName($name)
252
    {
253 92
        return preg_match("/^[a-z0-9]+$/", $name);
254
    }
255
}
256