Issues (7)

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/LicenseCheckCommand.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
declare(strict_types=1);
4
5
namespace BestIt\LicenseCheck\Command;
6
7
use BestIt\LicenseCheck\Checker;
8
use BestIt\LicenseCheck\Command\Exception\CommandException;
9
use BestIt\LicenseCheck\Configuration\ConfigurationLoader;
10
use BestIt\LicenseCheck\Configuration\Exception\ConfigurationNotFoundException;
11
use BestIt\LicenseCheck\Configuration\Exception\ConfigurationParseException;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use function defined;
18
19
/**
20
 * Command to check package licenses.
21
 *
22
 * @author best it AG <[email protected]>
23
 * @package BestIt\LicenseCheck\Command
24
 */
25
class LicenseCheckCommand extends Command
26
{
27
    /**
28
     * Constant for the directory cli argument.
29
     *
30
     * @var string ARGUMENT_DIRECTORY
31
     */
32
    private const ARGUMENT_DIRECTORY = 'directory';
33
34
    /**
35
     * Constant for the configuration cli option.
36
     *
37
     * @var string OPTION_CONFIGURATION
38
     */
39
    private const OPTION_CONFIGURATION = 'configuration';
40
41
    /**
42
     * Constant for the ignore-errors cli option.
43
     *
44
     * @var string OPTION_IGNORE_ERRORS
45
     */
46
    private const OPTION_IGNORE_ERRORS = 'ignore-errors';
47
48
    /**
49
     * Dependency to the checker class which do the license validation.
50
     *
51
     * @var Checker $checker
52
     */
53
    private Checker $checker;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
54
55
    /**
56
     * Dependency to the loader to get the configuration object.
57
     *
58
     * @var ConfigurationLoader $configurationLoader
59
     */
60
    private ConfigurationLoader $configurationLoader;
61
62
    /**
63
     * Create license check command instance.
64
     *
65
     * @param Checker $checker Dependency to the checker class which do the license validation.
66
     * @param ConfigurationLoader $configurationLoader Dependency to the loader to get the configuration object.
67
     */
68
    public function __construct(Checker $checker, ConfigurationLoader $configurationLoader)
69
    {
70
        $this->checker = $checker;
71
        $this->configurationLoader = $configurationLoader;
72
73
        parent::__construct('license-check');
74
    }
75
76
    /**
77
     * Add needed arguments and options to the command.
78
     *
79
     * @return void
80
     */
81
    protected function configure(): void
82
    {
83
        $this
84
            ->setDescription('Tool to check licenses of used packages.')
85
            ->addArgument(
86
                self::ARGUMENT_DIRECTORY,
87
                InputArgument::OPTIONAL,
88
                __DIR__,
89
            )
90
            ->addOption(
91
                self::OPTION_CONFIGURATION,
92
                'c',
93
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
94
                'List of configuration files.',
95
            )
96
            ->addOption(
97
                self::OPTION_IGNORE_ERRORS,
98
                null,
99
                InputOption::VALUE_NONE,
100
                'Don\'t return an error code.',
101
            );
102
    }
103
104
    /**
105
     * Execution method for the cli command.
106
     *
107
     * @param InputInterface $input
108
     * @param OutputInterface $output
109
     *
110
     * @throws ConfigurationNotFoundException Exception if configuration is not found.
111
     * @throws ConfigurationParseException Exception if configuration cannot be parsed.
112
     * @throws CommandException Thrown if directory is not readable
113
     *
114
     * @return int
115
     */
116
    protected function execute(InputInterface $input, OutputInterface $output): int
117
    {
118
        if (!is_string($workingDirectory = $input->getArgument(self::ARGUMENT_DIRECTORY))) {
119
            $workingDirectory = getcwd();
120
        }
121
122
        if (!is_string($workingDirectory)) {
123
            throw new CommandException('Cannot read working directory.');
124
        }
125
126
        $configFiles = $input->getOption(self::OPTION_CONFIGURATION);
127
128
        assert(is_array($configFiles));
129
        if (count($configFiles) === 0) {
130
            $configFiles[] = $workingDirectory . '/license-check.yml';
131
        }
132
133
        $configuration = $this->configurationLoader->load($configFiles);
134
135
        $resultSet = $this->checker->validate($configuration, $workingDirectory);
136
137
        $resultCode = defined('static::SUCCESS') ? static::SUCCESS : 0;
138
139
        if ($resultSet->isPassed()) {
140
            $output->writeln('<info>License check passed!</info>');
141
        } else {
142
            if (!$input->getOption(self::OPTION_IGNORE_ERRORS)) {
143
                $resultCode = defined('static::FAILURE') ? static::FAILURE : 1;
144
            }
145
146
            foreach ($resultSet->getViolations() as $violation) {
147
                $output->writeln(
148
                    sprintf(
149
                        '<comment>%s</comment>',
150
                        $violation,
151
                    ),
152
                );
153
            }
154
155
            $output->writeln('<error>License check failed!</error>');
156
        }
157
158
        return $resultCode;
159
    }
160
}
161