Issues (2)

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/ScriptHandler.php (2 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 EM\CssCompiler;
4
5
use Composer\Script\Event;
6
use EM\CssCompiler\Processor\Processor;
7
8
/**
9
 * @see   ScriptHandlerTest
10
 *
11
 * @since 0.1
12
 */
13
class ScriptHandler
14
{
15
    const CONFIG_MAIN_KEY          = 'css-compiler';
16
    const OPTION_KEY_INPUT         = 'input';
17
    const OPTION_KEY_OUTPUT        = 'output';
18
    const OPTION_KEY_FORMATTER     = 'format';
19
    const DEFAULT_OPTION_FORMATTER = 'compact';
20
    protected static $mandatoryOptions = [
21
        self::OPTION_KEY_INPUT  => 'array',
22
        self::OPTION_KEY_OUTPUT => 'string'
23
    ];
24
25
    /**
26
     * @api
27
     *
28
     * @param Event $event
29
     *
30
     * @throws \InvalidArgumentException
31
     */
32 1
    public static function generateCSS(Event $event)
33
    {
34 1
        $extra = $event->getComposer()->getPackage()->getExtra();
35 1
        static::validateConfiguration($extra);
36
37 1
        $processor = new Processor($event->getIO());
38
39 1
        foreach ($extra[static::CONFIG_MAIN_KEY] as $options) {
40 1
            foreach ($options[static::OPTION_KEY_INPUT] as $inputSource) {
41 1
                $processor->attachFiles(
42 1
                    static::resolvePath($inputSource, getcwd()),
43 1
                    static::resolvePath($options[static::OPTION_KEY_OUTPUT], getcwd())
44
                );
45
            }
46
47 1
            $formatter = array_key_exists(static::OPTION_KEY_FORMATTER, $options) ? $options[static::OPTION_KEY_FORMATTER] : static::DEFAULT_OPTION_FORMATTER;
48 1
            $processor->processFiles($formatter);
49
        }
50 1
        $processor->saveOutput();
51 1
    }
52
53
    /**
54
     * @param string $path
55
     * @param string $prefix
56
     *
57
     * @return string
58
     */
59 1
    protected static function resolvePath($path, $prefix)
60
    {
61 1
        return '/' === substr($path, 0, 1) ? $path : "{$prefix}/{$path}";
62
    }
63
64
    /**
65
     * @param array $config
66
     *
67
     * @throws \InvalidArgumentException
68
     */
69 6
    protected static function validateConfiguration(array $config)
70
    {
71 6
        if (!array_key_exists(static::CONFIG_MAIN_KEY, $config)) {
72 1
            throw new \InvalidArgumentException('compiler should needs to be configured through the extra.css-compiler setting');
73
        }
74
75 5
        if (!is_array($config[static::CONFIG_MAIN_KEY])) {
76 2
            throw new \InvalidArgumentException('the extra.' . static::CONFIG_MAIN_KEY . ' setting must be an array of objects');
77
        }
78
79 3
        foreach ($config[static::CONFIG_MAIN_KEY] as $index => $options) {
80 3
            if (!is_array($options)) {
81 1
                throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[$index] should be an array");
82
            }
83
84 2
            static::validateMandatoryOptions($options, $index);
85
        }
86 2
    }
87
88
    /**
89
     * @param array $options
90
     * @param int   $index
91
     *
92
     * @throws \InvalidArgumentException
93
     */
94 7
    protected static function validateMandatoryOptions(array $options, $index)
95
    {
96 7
        foreach (static::$mandatoryOptions as $optionIndex => $type) {
97 7 View Code Duplication
            if (!array_key_exists($optionIndex, $options)) {
0 ignored issues
show
This code seems to be duplicated across 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...
98 1
                throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[$index].{$optionIndex} is required!");
99
            }
100
101 6
            $callable = "is_{$type}";
102 6 View Code Duplication
            if (!$callable($options[$optionIndex])) {
0 ignored issues
show
This code seems to be duplicated across 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...
103 6
                throw new \InvalidArgumentException('extra.' . static::CONFIG_MAIN_KEY . "[$index].{$optionIndex} should be {$type}!");
104
            }
105
        }
106 3
    }
107
}
108