Issues (92)

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.

app/Helpers/User.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
namespace App\Helpers;
4
5
use App\Facades\Session;
0 ignored issues
show
This use statement conflicts with another class in this namespace, App\Helpers\Session.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use App\Models\ChocolateyId;
7
use App\Models\User as UserModel;
8
use App\Singleton;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Facades\Config;
11
12
/**
13
 * Class User.
14
 */
15
final class User extends Singleton
16
{
17
    /**
18
     * Update User Data without overwriting Session.
19
     *
20
     * @param array $parameters
21
     *
22
     * @return UserModel
23
     */
24
    public function updateSession(array $parameters)
25
    {
26
        return $this->setSession($this->updateUser($this->getUser(), $parameters));
0 ignored issues
show
It seems like $this->getUser() can be null; however, updateUser() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
27
    }
28
29
    /**
30
     * Set User Data on Session.
31
     *
32
     * @param UserModel $user
33
     *
34
     * @return UserModel
35
     */
36
    public function setSession(UserModel $user)
37
    {
38
        return Session::set(Config::get('chocolatey.security.session'), $user);
39
    }
40
41
    /**
42
     * Update User Data by User Model.
43
     *
44
     * @param UserModel $user
45
     * @param array     $parameters
46
     *
47
     * @return UserModel
48
     */
49
    public function updateUser($user, array $parameters)
50
    {
51
        $user->update($parameters);
52
53
        return $user;
54
    }
55
56
    /**
57
     * Get User Data from Session
58
     * If User Session doesn't exists, return null.
59
     *
60
     * @return UserModel|null
61
     */
62
    public function getUser()
63
    {
64
        return Session::get(Config::get('chocolatey.security.session')) ?? null;
65
    }
66
67
    /**
68
     * Retrieve Non Banned Users (If all Users are Banned, return the Banned user Also).
69
     *
70
     * @param Request      $request
71
     * @param ChocolateyId $chocolateyId
72
     *
73
     * @return UserModel
74
     */
75
    private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId)
0 ignored issues
show
The parameter $chocolateyId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
        $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get();
78
79
        foreach ($temporaryUsers as $forUser) {
80
            if (!$forUser->isBanned) {
81
                return $forUser;
82
            }
83
        }
84
85
        return $temporaryUsers->get(0);
86
    }
87
88
    /**
89
     * Get Users.
90
     *
91
     * @param Request      $request
92
     * @param ChocolateyId $chocolateyId
93
     *
94
     * @return UserModel
95
     */
96
    private function retrieveUser(Request $request, ChocolateyId $chocolateyId)
97
    {
98
        if ($chocolateyId->last_logged_id != 0) {
99
            $temporaryUser = UserModel::find($chocolateyId->last_logged_id);
100
101
            if ($temporaryUser->isBanned) {
102
                return $this->checkForBanAlternative($request, $chocolateyId);
103
            }
104
105
            return $temporaryUser;
106
        }
107
108
        $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first();
109
110
        if ($temporaryUser->isBanned) {
111
            return $this->checkForBanAlternative($request, $chocolateyId);
112
        }
113
114
        return $temporaryUser;
115
    }
116
117
    /**
118
     * Set Session From Login Credentials.
119
     *
120
     * @param Request $request
121
     *
122
     * @return UserModel
123
     */
124
    public function loginUser(Request $request)
125
    {
126
        $chocolateyId = ChocolateyId::find($request->json()->get('email'));
127
128
        if ($chocolateyId == null) {
129
            return;
130
        }
131
132
        $user = $this->retrieveUser($request, $chocolateyId);
133
134
        $chocolateyId->last_logged_id = $user->uniqueId;
135
136
        return $chocolateyId->password == hash(Config::get('chocolatey.security.hash'), $request->json()->get('password'))
137
            ? $this->setSession($user) : null;
138
    }
139
140
    /**
141
     * Return if USer Session Exists.
142
     *
143
     * @return bool
144
     */
145
    public function hasSession()
146
    {
147
        return (bool) Session::get(Config::get('chocolatey.security.session'));
148
    }
149
150
    /**
151
     * Erase User Session.
152
     */
153
    public function eraseSession()
154
    {
155
        Session::erase(Config::get('chocolatey.security.session'));
156
    }
157
}
158