Issues (35)

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/RulerZ.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
declare(strict_types=1);
4
5
namespace RulerZ;
6
7
use RulerZ\Compiler\Compiler;
8
use RulerZ\Compiler\CompilationTarget;
9
use RulerZ\Context\ExecutionContext;
10
use RulerZ\Exception\TargetUnsupportedException;
11
use RulerZ\Spec\Specification;
12
13
class RulerZ
14
{
15
    /**
16
     * @var Compiler
17
     */
18
    private $compiler;
19
20
    /**
21
     * @var array<CompilationTarget>
22
     */
23
    private $compilationTargets = [];
24
25
    /**
26
     * @param array $compilationTargets A list of compilation targets, each one handles a specific target type (an array, a DoctrineQueryBuilder, ...)
27
     */
28
    public function __construct(Compiler $compiler, array $compilationTargets = [])
29
    {
30
        $this->compiler = $compiler;
31
32
        foreach ($compilationTargets as $targetCompiler) {
33
            $this->registerCompilationTarget($targetCompiler);
34
        }
35
    }
36
37
    /**
38
     * Registers a new target compiler.
39
     *
40
     * @param CompilationTarget $compilationTarget The target compiler to register.
41
     */
42
    public function registerCompilationTarget(CompilationTarget $compilationTarget): void
43
    {
44
        $this->compilationTargets[] = $compilationTarget;
45
    }
46
47
    /**
48
     * Apply the filters on the target using the given rule and parameters.
49
     * The target compiler to use is determined at runtime using the registered ones.
50
     *
51
     * @param mixed  $target           The target to filter.
52
     * @param string $rule             The rule to apply.
53
     * @param array  $parameters       The parameters used in the rule.
54
     * @param array  $executionContext The execution context.
55
     *
56
     * @return mixed
57
     *
58
     * @throws TargetUnsupportedException
59
     */
60 View Code Duplication
    public function applyFilter($target, string $rule, array $parameters = [], array $executionContext = [])
0 ignored issues
show
This method seems to be duplicated in 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...
61
    {
62
        $targetCompiler = $this->findTargetCompiler($target, CompilationTarget::MODE_APPLY_FILTER);
63
        $compilationContext = $targetCompiler->createCompilationContext($target);
64
        $executor = $this->compiler->compile($rule, $targetCompiler, $compilationContext);
65
66
        return $executor->applyFilter($target, $parameters, $targetCompiler->getOperators()->getOperators(), new ExecutionContext($executionContext));
67
    }
68
69
    /**
70
     * Filters a target using the given rule and parameters.
71
     * The target compiler to use is determined at runtime using the registered ones.
72
     *
73
     * @param mixed  $target           The target to filter.
74
     * @param string $rule             The rule to apply.
75
     * @param array  $parameters       The parameters used in the rule.
76
     * @param array  $executionContext The execution context.
77
     *
78
     * @return \Traversable The filtered target.
79
     *
80
     * @throws TargetUnsupportedException
81
     */
82 View Code Duplication
    public function filter($target, string $rule, array $parameters = [], array $executionContext = [])
0 ignored issues
show
This method seems to be duplicated in 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...
83
    {
84
        $targetCompiler = $this->findTargetCompiler($target, CompilationTarget::MODE_FILTER);
85
        $compilationContext = $targetCompiler->createCompilationContext($target);
86
        $executor = $this->compiler->compile($rule, $targetCompiler, $compilationContext);
87
88
        return $executor->filter($target, $parameters, $targetCompiler->getOperators()->getOperators(), new ExecutionContext($executionContext));
89
    }
90
91
    /**
92
     * Filters a target using the given specification.
93
     * The targetCompiler to use is determined at runtime using the registered ones.
94
     *
95
     * @param mixed         $target           The target to filter.
96
     * @param Specification $spec             The specification to apply.
97
     * @param array         $executionContext The execution context.
98
     *
99
     * @return mixed The filtered target.
100
     *
101
     * @throws TargetUnsupportedException
102
     */
103
    public function filterSpec($target, Specification $spec, array $executionContext = [])
104
    {
105
        return $this->filter($target, $spec->getRule(), $spec->getParameters(), $executionContext);
106
    }
107
108
    /**
109
     * Apply the filters on a target using the given specification.
110
     * The targetCompiler to use is determined at runtime using the registered ones.
111
     *
112
     * @param mixed         $target           The target to filter.
113
     * @param Specification $spec             The specification to apply.
114
     * @param array         $executionContext The execution context.
115
     *
116
     * @return mixed
117
     *
118
     * @throws TargetUnsupportedException
119
     */
120
    public function applyFilterSpec($target, Specification $spec, array $executionContext = [])
121
    {
122
        return $this->applyFilter($target, $spec->getRule(), $spec->getParameters(), $executionContext);
123
    }
124
125
    /**
126
     * Tells if a target satisfies the given rule and parameters.
127
     * The target compiler to use is determined at runtime using the registered ones.
128
     *
129
     * @param mixed  $target           The target.
130
     * @param string $rule             The rule to test.
131
     * @param array  $parameters       The parameters used in the rule.
132
     * @param array  $executionContext The execution context.
133
     *
134
     * @throws TargetUnsupportedException
135
     */
136 View Code Duplication
    public function satisfies($target, string $rule, array $parameters = [], array $executionContext = []): bool
0 ignored issues
show
This method seems to be duplicated in 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...
137
    {
138
        $targetCompiler = $this->findTargetCompiler($target, CompilationTarget::MODE_SATISFIES);
139
        $compilationContext = $targetCompiler->createCompilationContext($target);
140
        $executor = $this->compiler->compile($rule, $targetCompiler, $compilationContext);
141
142
        return $executor->satisfies($target, $parameters, $targetCompiler->getOperators()->getOperators(), new ExecutionContext($executionContext));
143
    }
144
145
    /**
146
     * Tells if a target satisfies the given specification.
147
     * The target compiler to use is determined at runtime using the registered ones.
148
     *
149
     * @param mixed         $target           The target.
150
     * @param Specification $spec             The specification to use.
151
     * @param array         $executionContext The execution context.
152
     *
153
     * @throws TargetUnsupportedException
154
     */
155
    public function satisfiesSpec($target, Specification $spec, array $executionContext = []): bool
156
    {
157
        return $this->satisfies($target, $spec->getRule(), $spec->getParameters(), $executionContext);
158
    }
159
160
    /**
161
     * Finds a target compiler supporting the given target.
162
     *
163
     * @param mixed  $target The target to filter.
164
     * @param string $mode   The execution mode (MODE_FILTER or MODE_SATISFIES).
165
     *
166
     * @throws TargetUnsupportedException
167
     */
168
    private function findTargetCompiler($target, $mode): CompilationTarget
169
    {
170
        /** @var CompilationTarget $targetCompiler */
171
        foreach ($this->compilationTargets as $targetCompiler) {
172
            if ($targetCompiler->supports($target, $mode)) {
173
                return $targetCompiler;
174
            }
175
        }
176
177
        throw new TargetUnsupportedException('The given target is not supported.');
178
    }
179
}
180