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/Filter/BaseFilter.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
/**
4
 * This file is part of Stream package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Serafim\Stream\Filter;
13
14
abstract class BaseFilter implements FilterInterface
15
{
16
    /**
17
     * @var array<callable>
18
     */
19
    protected array $filters = [];
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
20
21
    /**
22
     * @param string $class
23
     * @param string $file
24
     * @return bool
25
     */
26
    public function __invoke(string $class, string $file): bool
27 1
    {
28
        return $this->match($class, $file);
29 1
    }
30
31
    /**
32
     * @param callable $filter
33
     * @return $this
34
     */
35
    public function not(callable $filter): self
36 1
    {
37
        return $this->where(function (string $class, string $file) use ($filter): bool {
38
            return ! $filter($class, $file);
39 1
        });
40 1
    }
41
42
    /**
43
     * @param callable $filter
44
     * @return $this
45
     */
46
    public function where(callable $filter): self
47 14
    {
48
        $this->filters[] = $filter;
49 14
50
        return $this;
51 14
    }
52
53
    /**
54
     * @param \Closure $then
55
     * @return BaseFilter|$this
56
     */
57
    public function every(\Closure $then): self
58 1
    {
59
        return $this->where(function (string $class, string $file) use ($then): bool {
60
            $then($conjunction = new Conjunction());
61 1
62
            return $conjunction->match($class, $file);
63 1
        });
64 1
    }
65
66
    /**
67
     * @param \Closure $then
68
     * @return $this
69
     */
70
    public function any(\Closure $then): self
71 1
    {
72
        return $this->where(function (string $class, string $file) use ($then): bool {
73
            $then($disjunction = new Disjunction());
74 1
75
            return $disjunction->match($class, $file);
76 1
        });
77 1
    }
78
79
    /**
80
     * @param string $fqn
81
     * @return $this
82
     */
83
    public function fqn(string $fqn): self
84 1
    {
85
        return $this->where(function (string $class) use ($fqn): bool {
86
            return \trim($class, '\\') === \trim($fqn, '\\');
87 1
        });
88 1
    }
89
90
    /**
91
     * @param string $name
92
     * @return $this
93
     */
94
    public function className(string $name): self
95 2
    {
96
        $name = \trim($name, '\\');
97 2
98
        return $this->where(function (string $fqn) use ($name): bool {
99
            return \substr($fqn, -\strlen($name)) === $name;
100 2
        });
101 2
    }
102
103
    /**
104
     * @param string $prefix
105
     * @return $this
106
     */
107
    public function namespace(string $prefix): self
108 1
    {
109
        $prefix = \trim($prefix, '\\');
110 1
111
        return $this->where(function (string $class) use ($prefix): bool {
112
            return \strpos(\trim($class, '\\'), $prefix) === 0;
113 1
        });
114 1
    }
115
116
    /**
117
     * @param string $name
118
     * @return $this
119
     */
120
    public function fileName(string $name): self
121 1
    {
122
        return $this->where(function (string $_, string $file) use ($name): bool {
123
            $file = \str_replace('\\', '/', $file);
124 1
125
            return \pathinfo($file, \PATHINFO_FILENAME) === $name;
126 1
        });
127 1
    }
128
129
    /**
130
     * @param string $regex
131
     * @return $this
132
     */
133
    public function pathNameMatches(string $regex): self
134 1
    {
135
        $regex = $this->regex($regex, false);
136 1
137
        return $this->where(function (string $_, string $file) use ($regex): bool {
138
            return \preg_match($regex, $file) !== 0;
139 1
        });
140 1
    }
141
142
    /**
143
     * @param string $regex
144
     * @return $this
145
     */
146
    public function fileNameMatches(string $regex): self
147 1
    {
148
        $regex = $this->regex($regex);
149 1
150
        return $this->where(function (string $_, string $file) use ($regex): bool {
151
            return \preg_match($regex, \pathinfo($file, \PATHINFO_FILENAME)) !== 0;
152 1
        });
153 1
    }
154
155
    /**
156
     * @param string $regex
157
     * @return $this
158
     */
159
    public function classNameMatches(string $regex): self
160 1
    {
161
        $regex = $this->regex($regex, true);
162 1
163
        return $this->where(function (string $fqn) use ($regex): bool {
164
            $class = \basename(\str_replace('\\', '/', $fqn));
165 1
166
            return \preg_match($regex, $class) !== 0;
167 1
        });
168 1
    }
169
170
    /**
171
     * @param string $regex
172
     * @return $this
173
     */
174
    public function fqnMatches(string $regex): self
175 1
    {
176
        $regex = $this->regex($regex);
177 1
178
        return $this->where(function (string $fqn) use ($regex): bool {
179
            return \preg_match($regex, $fqn) !== 0;
180 1
        });
181 1
    }
182
183
    /**
184
     * @param string $regex
185
     * @param bool $strict
186
     * @return string
187
     */
188
    private function regex(string $regex, bool $strict = false): string
189 4
    {
190
        $regex = $strict ? '^' . $regex . '$' : $regex;
191 4
192
        return \sprintf('/%s/isuS', \addcslashes($regex, '/'));
193 4
    }
194
}
195