Issues (10)

Security Analysis    no request data  

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.

ProcessStatusHandler.php (2 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 Innmind\ProvisionerBundle;
4
5
use Innmind\ProvisionerBundle\Server\ServerInterface;
6
7
/**
8
 * Holds informations about a process througthout a symfony runtime
9
 */
10
class ProcessStatusHandler
11
{
12
    const COMPUTE_ITERATIONS = 3;
13
    const ITERATIONS_SLEEP = 2;
14
15
    protected $informations = [];
16
    protected $server;
17
    protected $usePrecision = true;
18
19
    /**
20
     * Set the server helper
21
     *
22
     * @param ServerInterface $server
23
     */
24 39
    public function setServer(ServerInterface $server)
25
    {
26 39
        $this->server = $server;
27 39
    }
28
29
    /**
30
     * Whether to run compute multiple times cpu usage
31
     * to get a better approximation or not
32
     *
33
     * @param bool $use
34
     */
35 39
    public function setUsePrecision($use)
36
    {
37 39
        $this->usePrecision = (bool) $use;
38 39
    }
39
40
    /**
41
     * Return the number of process running for the givent command
42
     *
43
     * @param string $command
44
     *
45
     * @return int
46
     */
47 27 View Code Duplication
    public function getProcessCount($command)
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...
48
    {
49 27
        $hash = $this->getKey($command);
50
51 27
        if (!isset($this->informations[$hash])) {
52 24
            $this->computeProcessInformations($command);
53 24
        }
54
55 27
        return $this->informations[$hash]['number'];
56
    }
57
58
    /**
59
     * Return the average CPU usage for the given command
60
     *
61
     * @param string $command
62
     *
63
     * @return float
64
     */
65 6 View Code Duplication
    public function getProcessUsage($command)
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...
66
    {
67 6
        $hash = $this->getKey($command);
68
69 6
        if (!isset($this->informations[$hash])) {
70 6
            $this->computeProcessInformations($command);
71 6
        }
72
73 6
        return $this->informations[$hash]['usage'];
74
    }
75
76
    /**
77
     * Compute the process usage/number for the given command
78
     *
79
     * @param string $command
80
     */
81 30
    protected function computeProcessInformations($command)
82
    {
83 30
        $averageProcessUsage = 0;
84 30
        $averageProcessNumber = 0;
85 30
        $iterations = $this->usePrecision ? self::COMPUTE_ITERATIONS : 1;
86
87 30
        for ($i = 0; $i < $iterations; $i++) {
88 30
            $averageProcessUsage += $this->server->getProcessUsage($command);
89 30
            $averageProcessNumber += $this->server->getProcessCount($command);
90
91 30
            if ($this->usePrecision === true) {
92
                sleep(self::ITERATIONS_SLEEP);
93
            }
94 30
        }
95
96 30
        $averageProcessUsage = $averageProcessUsage / $iterations;
97 30
        $averageProcessNumber = floor($averageProcessNumber / $iterations);
98
99 30
        $this->informations[$this->getKey($command)] = [
100 30
            'usage' => (float) $averageProcessUsage,
101
            'number' => (int) $averageProcessNumber
102 30
        ];
103 30
    }
104
105
    /**
106
     * Return a unique key for the given command
107
     *
108
     * @param string $command
109
     *
110
     * @return string
111
     */
112 30
    protected function getKey($command)
113
    {
114 30
        return md5($command);
115
    }
116
}
117