Issues (26)

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/Application.php (3 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
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Console;
11
12
use Railt\Console\Language\GraphQLLanguage;
13
use Railt\Console\Language\LanguageInterface;
14
use Railt\Console\Language\PHPLanguage;
15
use Symfony\Component\Console\Application as Symfony;
16
use Symfony\Component\Console\Command\Command;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Railt\Console\Command.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/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 before OtherDir/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:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use Symfony\Component\Console\Input\ArgvInput;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\ConsoleOutput;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
/**
23
 * Class Application
24
 */
25
class Application extends Symfony
26
{
27
    /**
28
     * @var string
29
     */
30
    public const APP_NAME = 'Railt';
31
32
    /**
33
     * @var string
34
     */
35
    public const APP_VERSION = '1.2';
36
37
    /**
38
     * @var ExceptionRenderer
39
     */
40
    private $renderer;
41
42
    /**
43
     * @var Highlighter
44
     */
45
    private $highlighter;
46
47
    /**
48
     * Application constructor.
49
     * @throws \InvalidArgumentException
50
     * @throws \Railt\Lexer\Exception\BadLexemeException
51
     */
52
    public function __construct()
53
    {
54
        parent::__construct(self::APP_NAME, self::APP_VERSION);
55
56
        $this->highlighter = $this->bootHighlight();
57
        $this->renderer    = new ExceptionRenderer($this->highlighter);
58
    }
59
60
    /**
61
     * @param string ...$paths
62
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
63
     */
64
    public function tryReadManifest(string ...$paths): void
65
    {
66
        foreach ($paths as $path) {
67
            if (\is_file($path) && \is_readable($path)) {
68
                $this->readManifest($path);
69
            }
70
        }
71
    }
72
73
    /**
74
     * @param string $path
75
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
76
     */
77
    public function readManifest(string $path): void
78
    {
79
        $manifest = \json_decode(\file_get_contents($path), true);
80
81
        try {
82
            foreach ($manifest['commands'] ?? [] as $command) {
83
                $this->add(new $command());
84
            }
85
        } catch (\Throwable $e) {
86
            $this->throw($e);
87
        }
88
    }
89
90
    /**
91
     * @return Highlighter
92
     * @throws \InvalidArgumentException
93
     * @throws \Railt\Lexer\Exception\BadLexemeException
94
     */
95
    private function bootHighlight(): Highlighter
96
    {
97
        $hl = new Highlighter();
98
99
        $hl->add(new PHPLanguage());
100
        $hl->add(new GraphQLLanguage());
101
102
        return $hl;
103
    }
104
105
    /**
106
     * @param LanguageInterface $language
107
     * @return Application
108
     */
109
    public function addLanguage(LanguageInterface $language): self
110
    {
111
        $this->highlighter->add($language);
112
113
        return $this;
114
    }
115
116
    /**
117
     * @param InputInterface|null $input
118
     * @param OutputInterface|null $output
119
     * @throws \Throwable
120
     */
121
    public function gracefulRun(InputInterface $input = null, OutputInterface $output = null): void
122
    {
123
        [$input, $output] = $this->bootPipes($input, $output);
124
125
        try {
126
            $this->setCatchExceptions(false);
127
            $code = parent::run($input, $output);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (run() instead of gracefulRun()). Are you sure this is correct? If so, you might want to change this to $this->run().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
128
        } catch (\Throwable $e) {
129
            $code = $this->exitCode($e);
130
            $this->throw($e);
131
        } finally {
132
            exit($code);
0 ignored issues
show
The variable $code does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
133
        }
134
    }
135
136
    /**
137
     * @param InputInterface|null $input
138
     * @param OutputInterface|null $output
139
     * @return array
140
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
141
     * @throws \Symfony\Component\Console\Exception\RuntimeException
142
     */
143
    private function bootPipes(InputInterface $input = null, OutputInterface $output = null): array
144
    {
145
        $input  = $input ?? new ArgvInput();
146
        $output = $output ?? new ConsoleOutput();
147
148
        return [$input, $output];
149
    }
150
151
    /**
152
     * @param \Throwable $e
153
     * @return int
154
     */
155
    private function exitCode(\Throwable $e): int
156
    {
157
        return $e->getCode() ?: 1;
158
    }
159
160
    /**
161
     * @param Command $command
162
     * @return Command
163
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
164
     */
165
    public function add(Command $command): Command
166
    {
167
        try {
168
            parent::add($command);
169
        } catch (\Throwable $e) {
170
            $this->throw($e);
171
        }
172
173
        return $command;
174
    }
175
176
    /**
177
     * @param \Throwable $e
178
     * @param ConsoleOutput|null $output
179
     * @return void
180
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
181
     */
182
    public function throw(\Throwable $e, ConsoleOutput $output = null): void
183
    {
184
        try {
185
            $result = $this->renderer->render($e);
186
        } catch (\Throwable $error) {
187
            $result = (string)new $error($error->getMessage(), $e->getCode(), $e);
188
        }
189
190
        ($output ?? new ConsoleOutput())->write($result);
191
192
        exit($this->exitCode($e));
193
    }
194
}
195