Issues (20)

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/InitCommand.php (5 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 Acacha\Llum\Console;
4
5
use Acacha\Llum\Compiler\RCFileCompiler;
6
use Acacha\Llum\Filesystem\Filesystem;
7
use Acacha\Llum\Github\GithubAPI;
8
use Acacha\Llum\LlumRCFile;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Question\ConfirmationQuestion;
12
use Symfony\Component\Console\Question\Question;
13
14
/**
15
 * Class InitCommand
16
 * @package Acacha\Llum\Console
17
 */
18
class InitCommand extends LlumCommand
19
{
20
21
    /**
22
     * Github api service class.
23
     *
24
     * @var GithubAPI
25
     */
26
    protected $api;
27
28
    /**
29
     * Filesystem.
30
     *
31
     * @var Filesystem
32
     */
33
    protected $filesystem;
34
35
    /**
36
     * Compiler for llumrc file.
37
     *
38
     * @var RCFileCompiler
39
     */
40
    protected $compiler;
41
42
    /**
43
     * Command name.
44
     *
45
     * @var string
46
     */
47
    protected $commandName = 'init';
48
49
    /**
50
     * Command description.
51
     *
52
     * @var string
53
     */
54
    protected $commandDescription = 'Create ~/.llumrc file with llum configuration data';
55
56
    /**
57
     * Method to execute.
58
     *
59
     * @var string
60
     */
61
    protected $method = 'init';
62
63
    /**
64
     * Github username
65
     *
66
     * @var
67
     */
68
    protected $github_username;
69
70
    /**
71
     * Github token.
72
     *
73
     * @var string
74
     */
75
    protected $github_token = "";
76
77
    /**
78
     * Get path to stub.
79
     *
80
     * @return string
81
     */
82
    protected function getStubPath() {
83
        return __DIR__ . '/stubs/llumrc.stub';
84
    }
85
86
87
    /**
88
     * InitCommand constructor.
89
     *
90
     * @param Filesystem $filesystem
91
     * @param RCFileCompiler $compiler
92
     * @param GithubAPI $api
93
     */
94
    public function __construct(Filesystem $filesystem, RCFileCompiler $compiler, GithubAPI $api)
95
    {
96
        parent::__construct();
97
        $this->filesystem = $filesystem;
98
        $this->compiler = $compiler;
99
        $this->api = $api;
100
    }
101
102
    /**
103
     * init command.
104
     */
105
    public function init(InputInterface $input, OutputInterface $output)
106
    {
107
        try {
108
            $this->executeWizard($input,$output);
109
            $this->filesystem->overwrite(
110
                (new LlumRCFile())->path(),
111
                $this->compiler->compile(
112
                    $this->filesystem->get($this->getStubPath()),
113
                    $this->data));
0 ignored issues
show
The property data does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
114
        } catch (\Exception $e) {
115
            print_r($e->xdebug_message);
0 ignored issues
show
The property xdebug_message does not seem to exist. Did you mean message?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
116
        }
117
    }
118
119
    /**
120
     * Executes wizard.
121
     *
122
     * @param InputInterface $input
123
     * @param OutputInterface $output
124
     */
125
    protected function executeWizard(InputInterface $input, OutputInterface $output){
126
127
        $this->askGithubUsername($input,$output);
128
        $this->askGithubToken($input,$output);
129
130
        $this->data = [
131
            "GITHUB_USERNAME" => $this->github_username,
132
            "GITHUB_TOKEN" => $this->github_token,
133
            "GITHUB_TOKEN_NAME" => $this->api->tokenName(),
134
        ];
135
    }
136
137
    /**
138
     * @param InputInterface $input
139
     * @param OutputInterface $output
140
     */
141
    public function askGithubUsername(InputInterface $input, OutputInterface $output)
142
    {
143
        $defaultusername = $this->defaultUsername();
144
        $question = new Question('<info>Please enter your github username (' . $defaultusername . ') ? </info>', $defaultusername);
145
        $this->github_username = $this->getHelper('question')->ask($input, $output, $question);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Console\Helper\HelperInterface as the method ask() does only exist in the following implementations of said interface: Symfony\Component\Console\Helper\QuestionHelper, Symfony\Component\Consol...r\SymfonyQuestionHelper.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
146
    }
147
148
    /**
149
     * @return string
150
     */
151
    protected function defaultUsername()
152
    {
153
        return get_current_user();
154
    }
155
156
    /**
157
     * @param InputInterface $input
158
     * @param OutputInterface $output
159
     */
160
    public function askGithubToken(InputInterface $input, OutputInterface $output)
161
    {
162
        $question = new ConfirmationQuestion('<info>Do you want to use our assistant to obtain token via Github API (Y/n)? </info>', true);
163
        if ($this->getHelper('question')->ask($input, $output, $question)) {
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Console\Helper\HelperInterface as the method ask() does only exist in the following implementations of said interface: Symfony\Component\Console\Helper\QuestionHelper, Symfony\Component\Consol...r\SymfonyQuestionHelper.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
164
            $this->github_token =$this->api->getPersonalToken(
165
                $this->github_username,
166
                $this->askGithubPassword($input,$output));
167
        }
168
    }
169
170
    /**
171
     * @param InputInterface $input
172
     * @param OutputInterface $output
173
     * @return mixed
174
     */
175
    protected function askGithubPassword(InputInterface $input, OutputInterface $output) {
176
        $question = new Question('<info>Github password? </info>');
177
        $question->setHidden(true);
178
        $question->setHiddenFallback(false);
179
180
        return $this->getHelper('question')->ask($input, $output, $question);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Console\Helper\HelperInterface as the method ask() does only exist in the following implementations of said interface: Symfony\Component\Console\Helper\QuestionHelper, Symfony\Component\Consol...r\SymfonyQuestionHelper.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
181
    }
182
}