Issues (7)

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/BladeX.php (3 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 Spatie\BladeX;
4
5
use Illuminate\Support\Str;
6
use Spatie\BladeX\ComponentDirectory\NamespacedDirectory;
7
use Spatie\BladeX\ComponentDirectory\RegularDirectory;
8
use Spatie\BladeX\Exceptions\CouldNotRegisterComponent;
9
use Symfony\Component\Finder\SplFileInfo;
10
11
class BladeX
12
{
13
    /** @var array */
14
    public $registeredComponents = [];
15
16
    /** @var string */
17
    protected $prefix = '';
18
19
    /**
20
     * @param string|string[] $view
21
     * @param string $tag
22
     *
23
     * @return null|\Spatie\BladeX\Component
24
     */
25
    public function component($view, string $tag = ''): ?Component
26
    {
27
        if (is_iterable($view)) {
28
            $this->registerViews($view);
0 ignored issues
show
It seems like $view defined by parameter $view on line 25 can also be of type string; however, Spatie\BladeX\BladeX::registerViews() does only seem to accept object<Spatie\BladeX\ite...>|array<integer,string>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
29
30
            return null;
31
        }
32
33
        if ($view instanceof Component) {
34
            $this->registeredComponents[] = $view;
35
36
            return $view;
37
        }
38
39
        if (! is_string($view)) {
40
            throw CouldNotRegisterComponent::invalidArgument();
41
        }
42
43
        if (Str::endsWith($view, '*')) {
44
            $this->registerComponents($view);
45
46
            return null;
47
        }
48
49
        if (! view()->exists($view)) {
50
            throw CouldNotRegisterComponent::viewNotFound($view, $tag);
51
        }
52
53
        $component = new Component($view, $tag);
54
55
        $this->registeredComponents[] = $component;
56
57
        return $component;
58
    }
59
60
    /**
61
     * @param string|string[] $viewDirectory
62
     *
63
     * @return \Spatie\BladeX\ComponentCollection|\Spatie\BladeX\Component[]
64
     */
65
    public function components($viewDirectory): ComponentCollection
66
    {
67
        if (is_iterable($viewDirectory)) {
68
            $components = new ComponentCollection();
69
70
            foreach ($viewDirectory as $singleViewDirectory) {
0 ignored issues
show
The expression $viewDirectory of type string|array<integer,string> is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
71
                if (Str::endsWith($singleViewDirectory, '*')) {
72
                    $components = $components->merge($this->registerComponents($singleViewDirectory));
73
                } else {
74
                    $components->push($this->component($singleViewDirectory));
75
                }
76
            }
77
78
            return $components;
79
        }
80
81
        return $this->registerComponents($viewDirectory);
0 ignored issues
show
It seems like $viewDirectory defined by parameter $viewDirectory on line 65 can also be of type array<integer,string>; however, Spatie\BladeX\BladeX::registerComponents() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
82
    }
83
84
    /**
85
     * @return \Spatie\BladeX\Component[]
86
     */
87
    public function registeredComponents(): array
88
    {
89
        return collect($this->registeredComponents)->reverse()->unique(function (Component $component) {
90
            return $component->getTag();
91
        })->reverse()->values()->all();
92
    }
93
94
    public function prefix(string $prefix = ''): self
95
    {
96
        $this->prefix = $prefix;
97
98
        return $this;
99
    }
100
101
    public function getPrefix(): string
102
    {
103
        return empty($this->prefix) ? '' : Str::finish($this->prefix, '-');
104
    }
105
106
    /**
107
     * @internal
108
     *
109
     * @param string $viewDirectory
110
     *
111
     * @return \Spatie\BladeX\ComponentCollection|\Spatie\BladeX\Component[]
112
     */
113
    public function registerComponents(string $viewDirectory)
114
    {
115
        if (! Str::endsWith($viewDirectory, '*')) {
116
            throw CouldNotRegisterComponent::viewDirectoryWithoutWildcard($viewDirectory);
117
        }
118
119
        $includeSubdirectories = Str::endsWith($viewDirectory, '**.*');
120
121
        $componentDirectory = Str::contains($viewDirectory, '::')
122
            ? new NamespacedDirectory($viewDirectory, $includeSubdirectories)
123
            : new RegularDirectory($viewDirectory, $includeSubdirectories);
124
125
        return $this->registerViews(
126
            ComponentCollection::make($componentDirectory->getFiles())
127
128
                ->filter(function (SplFileInfo $file) {
129
                    return Str::endsWith($file->getFilename(), '.blade.php');
130
                })
131
                ->map(function (SplFileInfo $file) use ($componentDirectory) {
132
                    return $componentDirectory->getViewName($file);
133
                })
134
        );
135
    }
136
137
    /**
138
     * @param iterable|string[] $views
139
     *
140
     * @return \Spatie\BladeX\ComponentCollection|\Spatie\BladeX\Component[]
141
     */
142
    protected function registerViews(iterable $views): ComponentCollection
143
    {
144
        return ComponentCollection::make($views)->map(function (string $viewName) {
145
            return $this->component($viewName);
146
        });
147
    }
148
}
149