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.

src/Queue/QueueProcessor.php (2 issues)

Severity

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 Glooby\TaskBundle\Queue;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Glooby\TaskBundle\Model\QueuedTaskInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Process\Process;
9
10
/**
11
 * @author Emil Kilhage
12
 */
13
class QueueProcessor
14
{
15
    /**
16
     * @var int
17
     */
18
    private $limit;
19
20
    /**
21
     * @var bool
22
     */
23
    private $debug;
24
25
    /**
26
     * @var Process[]
27
     */
28
    private $processes = [];
29
30
    /**
31
     * @var OutputInterface
32
     */
33
    protected $output;
34
35
    /**
36
     * @var ManagerRegistry
37
     */
38
    protected $doctrine;
39
40
    /**
41
     * @param ManagerRegistry $doctrine
42
     */
43
    public function setDoctrine($doctrine)
44
    {
45
        $this->doctrine = $doctrine;
46
    }
47
48
    /**
49
     * @param OutputInterface $output
50
     */
51
    public function setOutput(OutputInterface $output)
52
    {
53
        $this->output = $output;
54
    }
55
56
    /**
57
     * @param boolean $debug
58
     */
59
    public function setDebug($debug)
60
    {
61
        $this->debug = $debug;
62
    }
63
64
    /**
65
     * @param int $limit
66
     */
67
    public function setLimit($limit)
68
    {
69
        $this->limit = $limit;
70
    }
71
72
    /**
73
     * @throws \Exception
74
     */
75
    public function process()
76
    {
77
        $queueRepo = $this->doctrine->getManager()
78
            ->getRepository('GloobyTaskBundle:QueuedTask');
79
80
        $started = [];
81
        foreach ($queueRepo->findQueued($this->limit) as $queuedTask) {
82
            if (!$queueRepo->isRunning($queuedTask->getName()) && !in_array($queuedTask->getName(), $started)) {
83
                $started[] = $queuedTask->getName();
84
                $this->start($queuedTask);
85
            }
86
        }
87
88
        $this->wait();
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    private function getProcessParams()
95
    {
96
        $params = [];
97
98
        if (!$this->debug) {
99
            $params[] = '--env=prod';
100
        }
101
102
        return implode(' ', $params);
103
    }
104
105
    /**
106
     *
107
     */
108
    private function wait()
109
    {
110
        while (count($this->processes) > 0) {
111
            sleep(1);
112
113
            foreach ($this->processes as $i => $process) {
114
                if (!$process->isRunning()) {
115
                    unset($this->processes[$i]);
116
                    echo $process->getOutput();
117
                }
118
            }
119
        }
120
    }
121
122
    /**
123
     * @param QueuedTaskInterface $queuedTask
124
     */
125
    private function start(QueuedTaskInterface $queuedTask)
126
    {
127
        $command = $this->createCommand($queuedTask);
128
        $process = $this->createProcess($command);
129
130
        $this->processes[] = $process;
131
132
        if (null !== $this->output) {
133
            $this->output->writeln("$command");
134
        }
135
    }
136
137
    /**
138
     * @param string $command
139
     * @return Process
140
     */
141
    private function createProcess($command)
142
    {
143
        $that = $this;
0 ignored issues
show
$that 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...
144
        $nl = false;
0 ignored issues
show
$nl 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...
145
146
        $process = new Process($command);
147
        $process->setTimeout(0);
148
        $process->start();
149
150
        return $process;
151
    }
152
153
    /**
154
     * @param QueuedTaskInterface $queuedTask
155
     * @return string
156
     */
157
    private function createCommand(QueuedTaskInterface $queuedTask)
158
    {
159
        $command = sprintf(
160
            '%s -d memory_limit=%s bin/console task:run --id=%s %s',
161
            exec("readlink -f /proc/".posix_getpid()."/exe"),
162
            ini_get('memory_limit'),
163
            $queuedTask->getId(),
164
            $this->getProcessParams()
165
        );
166
167
        return $command;
168
    }
169
}
170