Issues (62)

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/WildcardPermission.php (1 issue)

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 Spatie\Permission;
4
5
use Illuminate\Support\Collection;
6
use Spatie\Permission\Exceptions\WildcardPermissionNotProperlyFormatted;
7
8
class WildcardPermission
9
{
10
    /** @var string */
11
    const WILDCARD_TOKEN = '*';
12
13
    /** @var string */
14
    const PART_DELIMITER = '.';
15
16
    /** @var string */
17
    const SUBPART_DELIMITER = ',';
18
19
    /** @var string */
20
    protected $permission;
21
22
    /** @var Collection */
23
    protected $parts;
24
25
    /**
26
     * @param string $permission
27
     */
28
    public function __construct(string $permission)
29
    {
30
        $this->permission = $permission;
31
        $this->parts = collect();
32
33
        $this->setParts();
34
    }
35
36
    /**
37
     * @param string|WildcardPermission $permission
38
     *
39
     * @return bool
40
     */
41
    public function implies($permission): bool
42
    {
43
        if (is_string($permission)) {
44
            $permission = new self($permission);
45
        }
46
47
        $otherParts = $permission->getParts();
48
49
        $i = 0;
50
        foreach ($otherParts as $otherPart) {
51
            if ($this->getParts()->count() - 1 < $i) {
52
                return true;
53
            }
54
55
            if (! $this->parts->get($i)->contains(self::WILDCARD_TOKEN)
56
                && ! $this->containsAll($this->parts->get($i), $otherPart)) {
57
                return false;
58
            }
59
60
            $i++;
61
        }
62
63
        for ($i; $i < $this->parts->count(); $i++) {
64
            if (! $this->parts->get($i)->contains(self::WILDCARD_TOKEN)) {
65
                return false;
66
            }
67
        }
68
69
        return true;
70
    }
71
72
    /**
73
     * @param Collection $part
74
     * @param Collection $otherPart
75
     *
76
     * @return bool
77
     */
78
    protected function containsAll(Collection $part, Collection $otherPart): bool
79
    {
80
        foreach ($otherPart->toArray() as $item) {
81
            if (! $part->contains($item)) {
82
                return false;
83
            }
84
        }
85
86
        return true;
87
    }
88
89
    /**
90
     * @return Collection
91
     */
92
    public function getParts(): Collection
93
    {
94
        return $this->parts;
95
    }
96
97
    /**
98
     * Sets the different parts and subparts from permission string.
99
     *
100
     * @return void
101
     */
102
    protected function setParts(): void
103
    {
104
        if (empty($this->permission) || $this->permission == null) {
105
            throw WildcardPermissionNotProperlyFormatted::create($this->permission);
106
        }
107
108
        $parts = collect(explode(self::PART_DELIMITER, $this->permission));
109
110
        $parts->each(function ($item, $key) {
0 ignored issues
show
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
            $subParts = collect(explode(self::SUBPART_DELIMITER, $item));
112
113
            if ($subParts->isEmpty() || $subParts->contains('')) {
114
                throw WildcardPermissionNotProperlyFormatted::create($this->permission);
115
            }
116
117
            $this->parts->add($subParts);
118
        });
119
120
        if ($this->parts->isEmpty()) {
121
            throw WildcardPermissionNotProperlyFormatted::create($this->permission);
122
        }
123
    }
124
}
125