Issues (2)

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/Console/DebugCommand.php (1 issue)

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
/* (c) Anton Medvedev <[email protected]>
3
/* (c) Oskar van Velden <[email protected]>
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Deployer\Console;
10
11
use Deployer\Deployer;
12
use Deployer\Task\GroupTask;
13
use Deployer\Task\TaskCollection;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface as Input;
17
use Symfony\Component\Console\Output\OutputInterface as Output;
18
19
class DebugCommand extends Command
20
{
21
    /** @var Output */
22
    protected $output;
23
24
    /**
25
     * @var TaskCollection
26
     */
27
    private $tasks;
28
29
    /**
30
     * @var Deployer
31
     */
32
    private $deployer;
33
34
    /**
35
     * @var array
36
     */
37
    private $tree;
38
39
    /**
40
     * Depth of nesting (for rendering purposes)
41
     * @var int
42
     */
43
    private $depth = 0;
44
45
    /**
46
     * @var array
47
     */
48
    private $openGroupDepths = [];
49
50
    /**
51
     * @param Deployer $deployer
52
     */
53 17
    public function __construct(Deployer $deployer)
54
    {
55 17
        parent::__construct('debug:task');
56 17
        $this->setDescription('Display the task-tree for a given task');
57 17
        $this->deployer = $deployer;
58 17
        $this->tree = [];
59 17
    }
60
61
    /**
62
     * Configures the command
63
     */
64 17
    protected function configure()
65
    {
66 17
        $this->addArgument(
67 17
            'task',
68 17
            InputArgument::REQUIRED,
69 17
            'Task to display the tree for'
70
        );
71 17
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected function execute(Input $input, Output $output)
77
    {
78
        $this->output = $output;
79
80
        $rootTaskName = $input->getArgument('task');
81
82
        $this->buildTree($rootTaskName);
83
        $this->outputTree($rootTaskName);
84
    }
85
86
    /**
87
     * Build the tree based on the given taskName
88
     * @param $taskName
89
     *
90
     * @return void
91
     */
92
    private function buildTree($taskName)
93
    {
94
        $this->tasks = Deployer::get()->tasks;
0 ignored issues
show
Documentation Bug introduced by Oskar van Velden
It seems like \Deployer\Deployer::get()->tasks can also be of type array<integer,object<Deployer\Task\Task>>. However, the property $tasks is declared as type object<Deployer\Task\TaskCollection>. 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...
95
        $this->createTreeFromTaskName($taskName, '', true);
96
    }
97
98
    /**
99
     * Create a tree from the given taskname
100
     *
101
     * @param string $taskName
102
     * @param string $postfix
103
     * @param bool $isLast
104
     *
105
     * @return void
106
     */
107
    private function createTreeFromTaskName($taskName, $postfix = '', $isLast = false)
108
    {
109
        $task = $this->tasks->get($taskName);
110
111
        if ($task->getBefore()) {
112
            $beforePostfix = sprintf(' [before:%s]', $task->getName());
113
114
            foreach ($task->getBefore() as $beforeTask) {
115
                $this->createTreeFromTaskName($beforeTask, $beforePostfix);
116
            }
117
        }
118
119
        if ($task instanceof GroupTask) {
120
            $isLast = $isLast && empty($task->getAfter());
121
122
            $this->addTaskToTree($task->getName() . $postfix, $isLast);
123
124
            if (!$isLast) {
125
                $this->openGroupDepths[] = $this->depth;
126
            }
127
128
            $this->depth++;
129
130
            $taskGroup = $task->getGroup();
131
            foreach ($taskGroup as $subtask) {
132
                $isLastSubtask = $subtask === end($taskGroup);
133
                $this->createTreeFromTaskName($subtask, '', $isLastSubtask);
134
            }
135
136
            if (!$isLast) {
137
                array_pop($this->openGroupDepths);
138
            }
139
140
            $this->depth--;
141
        } else {
142
            $this->addTaskToTree($task->getName() . $postfix, $isLast);
143
        }
144
145
        if ($task->getAfter()) {
146
            $afterPostfix = sprintf(' [after:%s]', $task->getName());
147
148
            foreach ($task->getAfter() as $afterTask) {
149
                $this->createTreeFromTaskName($afterTask, $afterPostfix);
150
            }
151
        }
152
    }
153
154
    /**
155
     * Add the (formatted) taskName to the rendertree, with some additional information
156
     *
157
     * @param string $taskName formatted with prefixes if needed
158
     * @param bool $isLast indication for what symbol to use for rendering
159
     */
160
    private function addTaskToTree($taskName, $isLast = false)
161
    {
162
        $this->tree[] = [
163
            'taskName' => $taskName,
164
            'depth' => $this->depth,
165
            'isLast' => $isLast,
166
            'openDepths' => $this->openGroupDepths
167
        ];
168
    }
169
170
    /**
171
     * Render the tree, after everything is build
172
     *
173
     * @param $taskName
174
     */
175
    private function outputTree($taskName)
176
    {
177
        $this->output->writeln("The task-tree for <fg=cyan>$taskName</fg=cyan>:");
178
179
        /**
180
         * @var $REPEAT_COUNT number of spaces for each depth increase
181
         */
182
        $REPEAT_COUNT = 4;
183
184
        foreach ($this->tree as $treeItem) {
185
            $depth = $treeItem['depth'];
186
187
            $startSymbol = $treeItem['isLast'] || $treeItem === end($this->tree) ? '└' : '├';
188
189
            $prefix = '';
190
191
            for ($i = 0; $i < $depth; $i++) {
192
                if (in_array($i, $treeItem['openDepths'])) {
193
                    $prefix .= '│' . str_repeat(' ', $REPEAT_COUNT - 1);
194
                } else {
195
                    $prefix .= str_repeat(' ', $REPEAT_COUNT);
196
                }
197
            }
198
199
            $prefix .=  $startSymbol . '──';
200
201
            $this->output->writeln(sprintf('%s %s', $prefix, $treeItem['taskName']));
202
        }
203
    }
204
}
205