Issues (621)

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.

class/DoSync.php (6 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
namespace XoopsModules\Smallworld;
4
5
/**
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * SmallWorld
17
 *
18
 * @copyright    The XOOPS Project (https://xoops.org)
19
 * @copyright    2011 Culex
20
 * @license      GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/)
21
 * @package      SmallWorld
22
 * @since        1.0
23
 * @author       Michael Albertsen (http://culex.dk) <[email protected]>
24
 */
25
26
/*
27
 *  Does a sync to remove orphans from smallworld db
28
 *
29
 */
30
31
/**
32
 * Class DoSync
33
 */
34
class DoSync
35
{
36
    /**
37
     * check for orphans (xoops_users <-> smallworld_users) and remove from smallworld
38
     */
39
    public function checkOrphans()
40
    {
41
        $sql    = 'SELECT userid FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . ' WHERE userid NOT IN ( SELECT uid FROM ' . $GLOBALS['xoopsDB']->prefix('users') . ')';
42
        $result = $GLOBALS['xoopsDB']->queryF($sql);
43
        if ($result) {
44
            while (false !== ($r = $GLOBALS['xoopsDB']->fetchArray($result))) {
45
                $this->deleteAccount($r['userid']);
46
            }
47
        }
48
    }
49
50
    /**
51
     * deleteAccount function
52
     * - Delete user account and associate rows across tables
53
     *
54
     * @param int $userid
55
     * @return bool true on success, false on failure
56
     */
57
    public function deleteAccount($userid)
58
    {
59
        $user     = new \XoopsUser($userid);
0 ignored issues
show
$user 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...
60
        //$username = $user->uname();
61
        $sql01    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_admin') . " WHERE userid = '" . $userid . "'";
62
        $sql02    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_comments') . " WHERE uid_fk = '" . $userid . "'";
63
        $sql03    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_followers') . " WHERE me = '" . $userid . "' OR you = '" . $userid . "'";
64
        $sql04    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_friends') . " WHERE me = '" . $userid . "' OR you = '" . $userid . "'";
65
        $sql05    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_images') . " WHERE userid = '" . $userid . "'";
66
        $sql06    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . " WHERE uid_fk = '" . $userid . "'";
67
        $sql07    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . " WHERE userid = '" . $userid . "'";
68
        $sql08    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_vote') . " WHERE user_id = '" . $userid . "'";
69
        $sql09    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_complaints') . " WHERE owner = '" . $userid . "' OR byuser_id = '" . $userid . "'";
70
        $sql10    = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_settings') . " WHERE userid = '" . $userid . "'";
71
72
        $result01 = $GLOBALS['xoopsDB']->queryF($sql01);
73
        $result02 = $GLOBALS['xoopsDB']->queryF($sql02);
74
        $result03 = $GLOBALS['xoopsDB']->queryF($sql03);
75
        $result04 = $GLOBALS['xoopsDB']->queryF($sql04);
76
        $result05 = $GLOBALS['xoopsDB']->queryF($sql05);
77
        $result06 = $GLOBALS['xoopsDB']->queryF($sql06);
78
        $result07 = $GLOBALS['xoopsDB']->queryF($sql07);
79
        $result08 = $GLOBALS['xoopsDB']->queryF($sql08);
80
        $result09 = $GLOBALS['xoopsDB']->queryF($sql09);
81
        $result10 = $GLOBALS['xoopsDB']->queryF($sql10);
82
        // Remove picture dir
83
        $dirname = XOOPS_ROOT_PATH . '/uploads/albums_smallworld' . '/' . $userid . '/';
84
        $result11 = $this->smallworld_remDir($userid, $dirname, $empty = false);
85
86
        return $result01 && $result02 && $result03 && $result04 && $result05 && $result06 && $result07 && $result08 && $result09 && $result10 && $result11;
87
    }
88
89
    /**
90
     * smallworld_remDir function
91
     * - Remove user image dir in uploads.
92
     * @param int         $userid
93
     * @param string|bool $directory
94
     * @param bool|int    $empty
95
     * @return bool
0 ignored issues
show
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
96
     */
97 View Code Duplication
    public function smallworld_remDir($userid, $directory, $empty = false)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        if ('' != $userid) {
100
            if ('/' === mb_substr($directory, -1)) {
101
                $directory = mb_substr($directory, 0, -1);
102
            }
103
104
            if (!file_exists($directory) || !is_dir($directory)) {
105
                return false;
106
            } elseif (!is_readable($directory)) {
107
                return false;
108
            }
109
            $directoryHandle = opendir($directory);
110
            while (false !== ($contents = readdir($directoryHandle))) {
111
                if ('.' !== $contents && '..' !== $contents) {
112
                    $path = $directory . '/' . $contents;
113
                    if (is_dir($path)) {
114
                        $this->smallworld_remDir($userid, $path);
115
                    } else {
116
                        unlink($path);
117
                    }
118
                }
119
            }
120
            closedir($directoryHandle);
121
            if (false === $empty) {
122
                if (!rmdir($directory)) {
123
                    return false;
124
                }
125
            }
126
127
            return true;
128
        }
129
    }
130
131
    /**
132
     * SmallworldDeleteDirectory function
133
     * - Delete images from users on delete
134
     * @param int $userid
135
     * @return true
0 ignored issues
show
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
136
     */
137
    public function SmallworldDeleteDirectory($userid)
138
    {
139
        $dirname = XOOPS_ROOT_PATH . '/uploads/albums_smallworld' . '/' . $userid . '/';
140
        if (is_dir($dirname)) {
141
            $dir_handle = opendir($dirname);
142
        }
143
        if (!$dir_handle) {
0 ignored issues
show
The variable $dir_handle 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...
144
            return false;
145
        }
146
        while ($file = readdir($dir_handle)) {
147 View Code Duplication
            if ('.' != $file && '..' != $file) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148
                if (!is_dir($dirname . '/' . $file)) {
149
                    unlink($dirname . '/' . $file);
150
                } else {
151
                    $this->SmallworldDeleteDirectory($dirname . '/' . $file);
152
                }
153
            }
154
        }
155
        closedir($dir_handle);
156
        rmdir($dirname);
157
158
        return true;
159
    }
160
}
161