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/Command/AliasCommand.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
3
namespace Geekish\Crap\Command;
4
5
use Geekish\Crap\CrapException;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Symfony\Component\Console\Question\ConfirmationQuestion;
11
use Symfony\Component\Console\Question\Question;
12
13
/**
14
 * Class AliasCommand
15
 * @package Geekish\Crap\Command
16
 */
17
final class AliasCommand extends BaseCommand
18
{
19
    /**
20
     * @inheritDoc
21
     */
22 View Code Duplication
    protected function configure()
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...
23
    {
24
        $this->setName('alias');
25
        $this->setDescription('Defines an alias for a package to be used by crap.');
26
        $this->addArgument('alias', InputArgument::REQUIRED, 'Package alias');
27
        $this->addArgument('package', InputArgument::REQUIRED, 'Package');
28
        $this->addOption(
29
            'dry-run',
30
            null,
31
            InputOption::VALUE_NONE,
32
            'Run command without writing to your `crap.json`, useful for testing.'
33
        );
34
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $alias = $input->getArgument('alias');
42
        $package = $input->getArgument('package');
43
44
        if (!$this->helper->validateAlias($alias)) {
45
            throw CrapException::create(
46
                'The alias `%s` is invalid, it should be lowercase, and match: [a-z0-9_.-]+',
47
                $alias
48
            );
49
        }
50
51
        if (!$this->helper->validatePackage($package)) {
52
            throw CrapException::create(
53
                'The package `%s` is invalid, it should match: [a-z0-9_.-]+/[a-z0-9_.-]+',
54
                $input->getArgument('package')
55
            );
56
        }
57
58
        $override = false;
59
60
        if ($this->helper->hasAlias($alias)) {
61
            $current = $this->helper->getAlias($alias);
62
63
            if ($current == $package) {
64
                $output->writeln(sprintf(
65
                    '<comment>Alias `%s` to package `%s` already exists, silly.</comment>',
66
                    $alias,
67
                    $package
68
                ));
69
                return 0;
70
            }
71
72
            $helper = $this->getHelper('question');
73
74
            $output->writeln(sprintf(
75
                '<comment>Alias `%s` exists and is set to `%s`.</comment>',
76
                $alias,
77
                $current
78
            ));
79
80
            $ask = sprintf('Override alias `%s` with `%s`? (y/n) ', $alias, $package);
81
            $question = new ConfirmationQuestion($ask, false);
82
83
            if (!$helper->ask($input, $output, $question)) {
84
                return 0;
85
            }
86
87
            $override = true;
88
        }
89
90
        if ($input->getOption('dry-run') !== true) {
91
            $this->helper->setAlias($alias, $package);
92
        }
93
94
        $output->writeln(sprintf(
95
            '<success>Alias `%s` to package `%s` successfully %s.</success>',
96
            $alias,
97
            $package,
98
            $override ? 'updated' : 'added'
99
        ));
100
101
        return 0;
102
    }
103
104
    /**
105
     * @inheritDoc
106
     */
107
    protected function interact(InputInterface $input, OutputInterface $output)
108
    {
109
        $args = array_values($input->getArguments());
110
111
        $helper = $this->getHelper('question');
112
113
        if ($args[2] == null && $this->helper->validatePackage($args[1]) === true) {
114
            $package = $args[1];
115
116
            $output->writeln('<comment>You provided the package but no alias!</comment>');
117
118
            $message = sprintf('<question>What do you want to use an an alias for `%s`?</question>', $package);
119
            $question = new Question($message . PHP_EOL, false);
120
121
            $alias = $helper->ask($input, $output, $question);
122
123
            $input->setArgument('alias', $alias);
124
            $input->setArgument('package', $package);
125
        } elseif ($args[2] == null && $this->helper->validateAlias($args[1])) {
126
            $alias = $args[1];
127
128
            $output->writeln('<info>You provided the alias but no package!</info>');
129
130
            $message = sprintf('<question>What package do you want to alias `%s` to?</question>', $alias);
131
            $question = new Question($message . PHP_EOL, false);
132
133
            $package = $helper->ask($input, $output, $question);
134
135
            $input->setArgument('package', $package);
136
        } elseif ($this->helper->validateAlias($args[2]) && $this->helper->validatePackage($args[1])) {
137
            $output->writeln('<info>It looks like you swapped the package and alias.</info>');
138
139
            $message = sprintf(
140
                '<question>Did you mean to alias `%s` to package `%s`?</question> (y/n) ',
141
                $args[2],
142
                $args[1]
143
            );
144
145
            $question = new ConfirmationQuestion($message, false);
146
147
            if ($helper->ask($input, $output, $question)) {
148
                $input->setArgument('alias', $args[2]);
149
                $input->setArgument('package', $args[1]);
150
            }
151
        } elseif ($this->helper->validateAlias($args[1]) && $this->helper->hasAlias($args[2])) {
152
            $output->writeln('<info>You provided an existing alias instead of a package.</info>');
153
154
            $existing = $this->helper->getAlias($args[2]);
155
156
            $message = sprintf(
157
                '<question>Do you want to alias `%s` to `%s`?</question> (y/n) ',
158
                $args[1],
159
                $existing
160
            );
161
162
            $question = new ConfirmationQuestion($message, false);
163
164
            if ($helper->ask($input, $output, $question)) {
165
                $input->setArgument('package', $existing);
166
            }
167
        }
168
    }
169
}
170