Issues (32)

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/Checks/SupervisorProgramsAreRunning.php (4 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 BeyondCode\SelfDiagnosis\Checks;
4
5
use BeyondCode\SelfDiagnosis\SystemFunctions;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Collection;
8
9
class SupervisorProgramsAreRunning implements Check
10
{
11
    /** @var Collection */
12
    protected $notRunningPrograms;
13
14
    /** @var string|null */
15
    protected $message;
16
17
    /** @var SystemFunctions */
18
    protected $systemFunctions;
19
20
    /** @var string */
21
    protected const REGEX_SUPERVISORCTL_STATUS = '/^(\S+)\s+RUNNING\s+pid\s+(\d+),\s+uptime\s+(\d+):(\d+):(\d+)$/';
22
23
    /**
24
     * SupervisorProgramsAreRunning constructor.
25
     *
26
     * @param SystemFunctions $systemFunctions
27
     */
28 32
    public function __construct(SystemFunctions $systemFunctions)
29
    {
30 32
        $this->systemFunctions = $systemFunctions;
31 32
    }
32
33
    /**
34
     * The name of the check.
35
     *
36
     * @param array $config
37
     * @return string
38
     */
39
    public function name(array $config): string
40
    {
41
        return trans('self-diagnosis::checks.supervisor_programs_are_running.name');
42
    }
43
44
    /**
45
     * Perform the actual verification of this check.
46
     *
47
     * @param array $config
48
     * @return bool
49
     */
50 32
    public function check(array $config): bool
51
    {
52 32
        $this->notRunningPrograms = new Collection(Arr::get($config, 'programs', []));
53 32
        if ($this->notRunningPrograms->isEmpty()) {
54 4
            return true;
55
        }
56
57 28
        if (!$this->systemFunctions->isFunctionAvailable('shell_exec')) {
58 4
            $this->message = trans('self-diagnosis::checks.supervisor_programs_are_running.message.shell_exec_not_available');
0 ignored issues
show
Documentation Bug introduced by
It seems like trans('self-diagnosis::c...ll_exec_not_available') can also be of type object<Illuminate\Contra...Translation\Translator> or array. However, the property $message is declared as type string|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
59 4
            return false;
60
        }
61
62 24
        if ($this->systemFunctions->isWindowsOperatingSystem()) {
63 4
            $this->message = trans('self-diagnosis::checks.supervisor_programs_are_running.message.cannot_run_on_windows');
0 ignored issues
show
Documentation Bug introduced by
It seems like trans('self-diagnosis::c...cannot_run_on_windows') can also be of type object<Illuminate\Contra...Translation\Translator> or array. However, the property $message is declared as type string|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
64 4
            return false;
65
        }
66
67 20
        $programs = $this->systemFunctions->callShellExec('supervisorctl status');
68 20
        if ($programs === null || $programs === '') {
69 4
            $this->message = trans('self-diagnosis::checks.supervisor_programs_are_running.message.supervisor_command_not_available');
0 ignored issues
show
Documentation Bug introduced by
It seems like trans('self-diagnosis::c...command_not_available') can also be of type object<Illuminate\Contra...Translation\Translator> or array. However, the property $message is declared as type string|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
70 4
            return false;
71
        }
72
73 16
        $restartedWithin = Arr::get($config, 'restarted_within', 0);
74 16
        $programs = explode("\n" , $programs);
75 16
        foreach ($programs as $program) {
76
            /*
77
             * Capture groups of regex:
78
             * (program name) (process id) (uptime hours) (minutes) (seconds)
79
             */
80 16
            $isMatch = preg_match(self::REGEX_SUPERVISORCTL_STATUS, trim($program), $matches);
81 16
            if ($isMatch) {
82 16
                if ($restartedWithin > 0) {
83 8
                    $totalSeconds = $matches[3] * 3600 + $matches[4] * 60 + $matches[5];
84 8
                    if ($totalSeconds > $restartedWithin) {
85 4
                        continue;
86
                    }
87
                }
88
89 6
                $this->notRunningPrograms = $this->notRunningPrograms->reject(function ($item) use ($matches) {
90 12
                    return $item === $matches[1];
91 12
                });
92
            }
93
        }
94
95 16
        return $this->notRunningPrograms->isEmpty();
96
    }
97
98
    /**
99
     * The error message to display in case the check does not pass.
100
     *
101
     * @param array $config
102
     * @return string
103
     */
104 20
    public function message(array $config): string
105
    {
106 20
        if ($this->message) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->message of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
107 12
            return $this->message;
108
        }
109
110 8
        return trans('self-diagnosis::checks.supervisor_programs_are_running.message.not_running_programs', [
111 8
            'programs' => $this->notRunningPrograms->implode(PHP_EOL),
112
        ]);
113
    }
114
}
115