Issues (243)

Security Analysis    2 potential vulnerabilities

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 (2)
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/web/Asset.php (4 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 /** MicroAsset */
2
3
namespace Micro\Web;
4
5
use Micro\Auth\Injector;
6
use Micro\Base\Autoload;
7
use Micro\Base\Exception;
8
use Micro\Base\KernelInjector;
9
use Micro\File\FileHelper;
10
use Micro\Mvc\Views\IView;
11
12
/**
13
 * Asset class file.
14
 *
15
 * @author Oleg Lunegov <[email protected]>
16
 * @link https://github.com/linpax/microphp-framework
17
 * @copyright Copyright (c) 2013 Oleg Lunegov
18
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
19
 * @package Micro
20
 * @subpackage Web
21
 * @version 1.0
22
 * @since 1.0
23
 */
24
class Asset
25
{
26
    /** @var string $sourcePath Full-path to source asset dir */
27
    public $sourcePath;
28
29
    /** @var bool $isHead Is a publish into head block */
30
    public $isHead = true;
31
    /** @var array $js JavaScript files links */
32
    public $js = [];
33
    /** @var array $css CSS files links */
34
    public $css = [];
35
    /** @var array $required Required assets */
36
    public $required = [];
37
    /** @var array $excludes Excludes extensions */
38
    public $excludes = [];
39
40
    /** @var IView $view View for install current asset */
41
    protected $view;
42
    /** @var string $hash Unique directory to publish into assets dir */
43
    protected $hash;
44
    /** @var string $publishPath Publish path */
45
    protected $publishPath;
46
    /** @var array $published Published required extends */
47
    private $published = [];
48
49
50
    /**
51
     * Constructor asset
52
     *
53
     * @access public
54
     *
55
     * @param IView $view
56
     *
57
     * @result void
58
     * @throws \Micro\Base\Exception
59
     */
60
    public function __construct(IView $view)
61
    {
62
        $this->view = $view;
63
64
        if (!$this->sourcePath) {
65
            $this->sourcePath = dirname(Autoload::getClassPath(get_class($this)));
66
        }
67
68
        $this->hash = md5($this->sourcePath);
69
70
        $this->publishPath = '/' . (($dir = (new Injector)->param('assetsDirName')) ? $dir : 'assets') . '/' . $this->hash;
71
72
        $web = (new KernelInjector)->build()->getWebDir();
73
74
        if (!file_exists($this->sourcePath)) {
75
            throw new Exception('Asset dir not exists: '.$this->sourcePath);
76
        }
77
78
        if (!is_dir($web.$this->publishPath) && (!mkdir($web.$this->publishPath, 0777) && !is_dir($web.$this->publishPath))) {
79
            throw new Exception('Could not access to publish dir: '.$this->publishPath);
80
        }
81
82
        FileHelper::recurseCopyIfEdited($this->sourcePath, $web.$this->publishPath, $this->excludes);
83
    }
84
85
    /**
86
     * Send asset into view
87
     *
88
     * @access public
89
     * @return void
90
     */
91
    public function publish()
92
    {
93
        foreach ($this->required AS $require) {
94
            if (!in_array($require, $this->published, true) && class_exists($require)) {
95
                $this->published[] = $require;
96
97
                /** @var Asset $require */
98
                $require = new $require($this->view);
99
                $require->publish();
100
            }
101
        }
102
103 View Code Duplication
        if ($this->js) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->js of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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...
104
            if (is_string($this->js)) {
105
                $this->js = [$this->js];
106
            }
107
108
            if (0 !== count($this->js)) {
109
                /** @noinspection ForeachSourceInspection */
110
                foreach ($this->js AS $script) {
111
                    $this->view->registerScriptFile($this->publishPath.$script, $this->isHead);
112
                }
113
            }
114
        }
115
116 View Code Duplication
        if ($this->css) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->css of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
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...
117
            if (is_string($this->css)) {
118
                $this->css = [$this->css];
119
            }
120
121
            if (0 !== count($this->css)) {
122
                /** @noinspection ForeachSourceInspection */
123
                foreach ($this->css AS $style) {
124
                    $this->view->registerCssFile($this->publishPath.$style, $this->isHead);
125
                }
126
            }
127
        }
128
    }
129
}
130