This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 Sovereign\Plugins\onMessage; |
||
4 | |||
5 | use Discord\Discord; |
||
6 | use Discord\Parts\Channel\Message; |
||
7 | use Discord\Parts\Guild\Role; |
||
8 | use Discord\Parts\User\Member; |
||
9 | use Monolog\Logger; |
||
10 | use Sovereign\Lib\Config; |
||
0 ignored issues
–
show
|
|||
11 | use Sovereign\Lib\cURL; |
||
12 | use Sovereign\Lib\Db; |
||
13 | use Sovereign\Lib\Permissions; |
||
14 | use Sovereign\Lib\ServerConfig; |
||
15 | use Sovereign\Lib\Settings; |
||
16 | use Sovereign\Lib\Users; |
||
17 | |||
18 | class auth extends \Threaded implements \Collectable |
||
19 | { |
||
20 | /** |
||
21 | * @var Message |
||
22 | */ |
||
23 | private $message; |
||
24 | /** |
||
25 | * @var Discord |
||
26 | */ |
||
27 | private $discord; |
||
28 | /** |
||
29 | * @var Logger |
||
30 | */ |
||
31 | private $log; |
||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $channelConfig; |
||
36 | /** |
||
37 | * @var Config |
||
38 | */ |
||
39 | private $config; |
||
40 | /** |
||
41 | * @var Db |
||
42 | */ |
||
43 | private $db; |
||
44 | /** |
||
45 | * @var cURL |
||
46 | */ |
||
47 | private $curl; |
||
48 | /** |
||
49 | * @var Settings |
||
50 | */ |
||
51 | private $settings; |
||
52 | /** |
||
53 | * @var Permissions |
||
54 | */ |
||
55 | private $permissions; |
||
56 | /** |
||
57 | * @var ServerConfig |
||
58 | */ |
||
59 | private $serverConfig; |
||
60 | /** |
||
61 | * @var Users |
||
62 | */ |
||
63 | private $users; |
||
64 | /** |
||
65 | * @var array |
||
66 | */ |
||
67 | private $extras; |
||
68 | |||
69 | View Code Duplication | public function __construct($message, $discord, $channelConfig, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras) |
|
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. ![]() |
|||
70 | { |
||
71 | $this->message = $message; |
||
72 | $this->discord = $discord; |
||
73 | $this->channelConfig = $channelConfig; |
||
74 | $this->log = $log; |
||
75 | $this->config = $config; |
||
76 | $this->db = $db; |
||
77 | $this->curl = $curl; |
||
78 | $this->settings = $settings; |
||
79 | $this->permissions = $permissions; |
||
80 | $this->serverConfig = $serverConfig; |
||
81 | $this->users = $users; |
||
82 | $this->extras = $extras; |
||
83 | } |
||
84 | |||
85 | public function run() |
||
86 | { |
||
87 | $explode = explode(" ", $this->message->content); |
||
88 | $authString = isset($explode[1]) ? $explode[1] : ""; |
||
89 | |||
90 | if ($this->message->getChannelAttribute()->is_private) { |
||
91 | return $this->message->reply("**Error** You are trying to send your auth token in private. This won't work because i need the guild information, which i can only get if you post it in a public channel on the server you want to get authed on."); |
||
92 | } |
||
93 | |||
94 | $authData = $this->db->queryRow("SELECT * FROM authRegs WHERE authString = :authString AND active = 1", array(":authString" => $authString)); |
||
95 | |||
96 | if ($authData) { |
||
0 ignored issues
–
show
The expression
$authData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
97 | $groups = json_decode($authData["groups"], true); |
||
98 | $characterID = $authData["characterID"]; |
||
99 | /** @var Role $roles */ |
||
100 | $roles = $this->message->getFullChannelAttribute()->getGuildAttribute()->getRolesAttribute(); |
||
101 | /** @var Member $member */ |
||
102 | $member = $this->message->getFullChannelAttribute()->getGuildAttribute()->getMembersAttribute()->get("id", $this->message->author->id); |
||
103 | $username = $this->message->author->username; |
||
104 | $discordID = $this->message->author->id; |
||
105 | |||
106 | // @todo Force ingame name |
||
107 | $characterName = json_decode($this->curl->get("https://evedata.xyz/api/character/shortinformation/{$characterID}/"))->characterName; |
||
0 ignored issues
–
show
$characterName 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 ![]() |
|||
108 | // Doesn't work yet, but it should be something like $member->nick($characterName); |
||
109 | //$member->user->setAttribute("username", $characterName); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
75% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
110 | |||
111 | /** @var Role $role */ |
||
112 | foreach ($roles as $role) { |
||
113 | $roleName = $role->name; |
||
114 | if (in_array($roleName, $groups)) { |
||
115 | $member->addRole($role); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | // Save the member object, so all the roles are set |
||
120 | $member->save(); |
||
121 | |||
122 | $this->db->execute("UPDATE authRegs SET discordID = :discordID, active = 0 WHERE authString = :authString", array(":discordID" => $discordID, ":authString" => $authString)); |
||
123 | $this->log->addInfo("{$username} authenticated in {$this->message->getChannelAttribute()->name} on {$this->message->getChannelAttribute()->getGuildAttribute()->name}"); |
||
124 | $this->message->reply("You have now been added to the following groups: " . implode(", ", $groups)); |
||
125 | } else { |
||
126 | $this->message->reply("**Error** You are trying to authenticate with an already used (or not existing) auth token.."); |
||
127 | } |
||
128 | |||
129 | // Mark this as garbage |
||
130 | $this->isGarbage(); |
||
131 | } |
||
132 | } |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/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 beforeOtherDir/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: