Issues (3099)

Security Analysis    not enabled

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.

UtilitiesBundle/Command/CipherCommand.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 Kunstmaan\UtilitiesBundle\Command;
4
5
use Kunstmaan\UtilitiesBundle\Helper\Cipher\CipherInterface;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Question\ChoiceQuestion;
10
use Symfony\Component\Console\Question\Question;
11
use Symfony\Component\Filesystem\Filesystem;
12
13
/**
14
 * @final since 5.1
15
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
16
 */
17
class CipherCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
18
{
19
    /**
20
     * @var CipherInterface
21
     */
22
    private $cipher;
23
24
    private static $methods = [
25
        0 => 'Encrypt text',
26
        1 => 'Decrypt text',
27
        2 => 'Encrypt file',
28
        3 => 'Decrypt file',
29
    ];
30
31
    /**
32
     * @param CipherInterface|null $cipher
33
     */
34
    public function __construct(/* CipherInterface */ $cipher = null)
35
    {
36
        parent::__construct();
37
38
        if (!$cipher instanceof CipherInterface) {
39
            @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);
40
41
            $this->setName(null === $cipher ? 'kuma:cipher' : $cipher);
42
43
            return;
44
        }
45
46
        $this->cipher = $cipher;
47
    }
48
49
    protected function configure()
50
    {
51
        $this->setName('kuma:cipher')->setDescription('Cipher utilities commands.');
52
    }
53
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        if (null === $this->cipher) {
57
            $this->cipher = $this->getContainer()->get('kunstmaan_utilities.cipher');
58
        }
59
        $helper = $this->getHelper('question');
60
61
        $question = new ChoiceQuestion(
62
            'Please select the method you want to use',
63
            self::$methods,
64
            0
65
        );
66
67
        $question->setErrorMessage('Method %s is invalid.');
68
        $method = $helper->ask($input, $output, $question);
69
        $method = array_search($method, self::$methods, true);
70
        switch ($method) {
71
            case 0:
72
            case 1:
73
                $question = new Question('Please enter the text: ');
74
                $question->setValidator(function ($value) {
75
                    if (trim($value) === '') {
76
                        throw new \Exception('The text cannot be empty');
77
                    }
78
79
                    return $value;
80
                });
81
                $question->setMaxAttempts(3);
82
                $text = $helper->ask($input, $output, $question);
83
                $text = $method === 0 ? $this->cipher->encrypt($text) : $this->cipher->decrypt($text);
84
                $output->writeln(sprintf('Result: %s', $text));
85
86
                break;
87
            case 2:
88
            case 3:
89
            $fs = new Filesystem();
90
91
            $question = new Question('Please enter the input file path: ');
92
                $question->setValidator(function ($value) use ($fs) {
93
                    if (trim($value) === '') {
94
                        throw new \Exception('The input file path cannot be empty');
95
                    }
96
97
                    if (false === $fs->exists($value)) {
98
                        throw new \Exception('The input file must exists');
99
                    }
100
101
                    if (is_dir($value)) {
102
                        throw new \Exception('The input file cannot be a dir');
103
                    }
104
105
                    return $value;
106
                });
107
                $question->setMaxAttempts(3);
108
                $inputFilePath = $helper->ask($input, $output, $question);
109
110
                $question = new Question('Please enter the output file path: ');
111
                $question->setValidator(function ($value) {
112
                    if (trim($value) === '') {
113
                        throw new \Exception('The output file path cannot be empty');
114
                    }
115
116
                    if (is_dir($value)) {
117
                        throw new \Exception('The output file path cannot be a dir');
118
                    }
119
120
                    return $value;
121
                });
122
                $question->setMaxAttempts(3);
123
                $outputFilePath = $helper->ask($input, $output, $question);
124
125
                if ($method === 2) {
126
                    $this->cipher->encryptFile($inputFilePath, $outputFilePath);
127
                } else {
128
                    if (false === $fs->exists($outputFilePath)) {
129
                        $fs->touch($outputFilePath);
130
                    }
131
                    $this->cipher->decryptFile($inputFilePath, $outputFilePath);
132
                }
133
134
                $output->writeln(sprintf('Check "%s" to see result', $outputFilePath));
135
136
                break;
137
        }
138
139
        return 0;
140
    }
141
}
142