Issues (273)

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.

src/Command/LogCommand.php (1 issue)

Labels
Severity

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 BZIon\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
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\ChoiceQuestion;
11
use Symfony\Component\Console\Question\Question;
12
use Symfony\Component\Yaml\Yaml;
13
14
class LogCommand extends ContainerAwareCommand
15
{
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('bzion:log')
20
            ->setDescription('Add a change to the changelog.yml file')
21
            ->addArgument(
22
                'type',
23
                InputArgument::OPTIONAL,
24
                'The type of the change (feature, bug or note)'
25
            )
26
            ->addArgument(
27
                'description',
28
                InputArgument::OPTIONAL,
29
                'A short description of the change'
30
            )
31
            ->addOption(
32
                'date',
33
                'd',
34
                InputOption::VALUE_OPTIONAL,
35
                'The date when the change occured',
36
                'today'
37
            )
38
            ->addOption(
39
                'changelog',
40
                'c',
41
                InputOption::VALUE_OPTIONAL,
42
                'The path to the changelog file',
43
                dirname(dirname(__DIR__)) . '/app/changelog.yml'
44
            );
45
    }
46
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        $type = $input->getArgument('type');
50
        $date = \TimeDate::from($input->getOption('date'))->format("j F Y");
51
        $description = $input->getArgument('description');
52
53
        $helper = $this->getHelper('question');
54
55
        if (!$type) {
56
            $question = new ChoiceQuestion(
57
                '<question>Please enter the type of the change</question>: ',
58
                array('Bug', 'Feature', 'Note')
59
            );
60
            $type = $helper->ask($input, $output, $question);
61
        }
62
63
        if (!$description) {
64
            $question = new Question('<question>Please enter a short description of the change</question>: ');
65
            $description = $helper->ask($input, $output, $question);
66
        }
67
68
        $category = $this->getTypeName($type);
69
70
        // Parse the current changelog and append the new change to it
71
        $changelog = Yaml::parse(file_get_contents($input->getOption('changelog')));
72
        $this->addMissingArrays($changelog, $date, $category);
73
        $changelog[$date][$category][] = $description;
74
75
        $this->sort($changelog);
76
77
        $yaml = Yaml::dump($changelog, 3);
78
79
        // Prevent yaml from unnecessarily quoting strings
80
        $yaml = preg_replace('/^\'([[:print:]]+)\':$/m', '$1:', $yaml);
81
        $yaml = preg_replace('/^( {8}- )\'(.*)\'$/m', '$1$2', $yaml);
82
        $yaml = str_replace("''", "'", $yaml);
83
84
        if ($output->isDebug()) {
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Symfony\Component\Console\Output\OutputInterface as the method isDebug() does only exist in the following implementations of said interface: BZIon\Command\NullOutput, Symfony\Component\Console\Output\BufferedOutput, Symfony\Component\Console\Output\ConsoleOutput, Symfony\Component\Console\Output\NullOutput, Symfony\Component\Console\Output\Output, Symfony\Component\Console\Output\StreamOutput, Symfony\Component\Consol...ts\Fixtures\DummyOutput, Symfony\Component\Console\Tests\Output\TestOutput.

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...
85
            $output->writeln($yaml);
86
        }
87
88
        file_put_contents($input->getOption('changelog'), $yaml);
89
90
        $output->writeln('<info>The changelog has been updated successfully</info>');
91
    }
92
93
    /**
94
     * Get a type name to put into the YAML file from whatever the user gave us
95
     *
96
     * @param  string            $type The user's input
97
     * @throws \RuntimeException
98
     * @return string
99
     */
100
    private function getTypeName($type)
101
    {
102
        switch (strtolower($type)) {
103
            case 'b':
104
            case 'bug':
105
            case 'bugs':
106
                return 'Bugfixes';
107
            case 'f':
108
            case 'feature':
109
            case 'features':
110
                return 'Features';
111
            case 'n':
112
            case 'note':
113
            case 'notes':
114
                return 'Notes';
115
            default:
116
                throw new \RuntimeException("I don't understand what '$type' means");
117
        }
118
    }
119
120
    /**
121
     * If the changelog.yml file doesn't contain the date and the type of the
122
     * change, add them to it
123
     *
124
     * @param array  $changelog The parsed YAML file
125
     * @param string $date
126
     * @param string $category
127
     */
128
    private function addMissingArrays(&$changelog, $date, $category)
129
    {
130
        if (!is_array($changelog)) {
131
            $changelog = array();
132
        }
133
134
        if (!isset($changelog[$date])) {
135
            $changelog[$date] = array();
136
        }
137
138
        if (!isset($changelog[$date][$category])) {
139
            $changelog[$date][$category] = array();
140
        }
141
    }
142
143
    /**
144
     * Sort the parsed changelog array before saving it
145
     *
146
     * @param array $changelog The parsed changelog
147
     */
148
    public static function sort(&$changelog)
149
    {
150
        uksort($changelog, function ($first, $second) {
151
            $a = \TimeDate::from($first);
152
            $b = \TimeDate::from($second);
153
154
            if ($a == $b) {
155
                return 0;
156
            }
157
158
            return ($a > $b) ? -1 : 1;
159
        });
160
    }
161
}
162