Issues (65)

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/Phossa2/Middleware/Queue.php (2 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
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Middleware
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Middleware;
16
17
use Psr\Http\Message\RequestInterface;
18
use Psr\Http\Message\ResponseInterface;
19
use Phossa2\Shared\Base\ObjectAbstract;
20
use Phossa2\Middleware\Message\Message;
21
use Phossa2\Middleware\Exception\LogicException;
22
use Phossa2\Middleware\Interfaces\QueueInterface;
23
use Phossa2\Middleware\Interfaces\DelegateInterface;
24
use Phossa2\Middleware\Interfaces\ConditionInterface;
25
use Phossa2\Middleware\Interfaces\MiddlewareInterface;
26
27
/**
28
 * Queue
29
 *
30
 * Middleware queue
31
 *
32
 * @package Phossa2\Middleware
33
 * @author  Hong Zhang <[email protected]>
34
 * @version 2.0.1
35
 * @since   2.0.0 added
36
 * @since   2.0.1 added $terminate
37
 */
38
class Queue extends ObjectAbstract implements QueueInterface
39
{
40
    /**
41
     * @var    \SplQueue
42
     * @access protected
43
     */
44
    protected $queue;
45
46
    /**
47
     * @var    bool
48
     * @access protected
49
     */
50
    protected $terminate = false;
51
52
    /**
53
     * Constructor
54
     *
55
     * @param  array $middlewares
56
     * @access public
57
     */
58
    public function __construct(
59
        array $middlewares = []
60
    ) {
61
        // create the queue
62
        $this->queue = new \SplQueue();
63
64
        // fill the queue with middlewares
65
        $this->fillTheQueue($middlewares);
66
    }
67
68
    /**
69
     * Compatible with middlewares of the signature
70
     *
71
     * ```php
72
     * fn($request, $response, callable $next)
73
     * ```
74
     *
75
     * @param  RequestInterface $request
76
     * @param  ResponseInterface $response
77
     * @param  DelegateInterface $next
78
     * @return ResponseInterface
79
     * @access public
80
     */
81
    public function __invoke(
82
        RequestInterface $request,
83
        ResponseInterface $response,
84
        DelegateInterface $next = null
85
    )/*# : ResponseInterface */ {
86
        return $this->process($request, $response, $next);
87
    }
88
89
    /**
90
     * {@inheritDoc}
91
     */
92
    public function push($middleware, $condition = null)
93
    {
94
        $this->queue->push([$middleware, $condition]);
95
        $this->queue->rewind();
96
        return $this;
97
    }
98
99
    /**
100
     * {@inheritDoc}
101
     */
102
    public function process(
103
        RequestInterface $request,
104
        ResponseInterface $response,
105
        DelegateInterface $next = null
106
    )/*# : ResponseInterface */ {
107
        // process the queue
108
        $response = $this->next($request, $response);
109
110
        // $next is parent queue
111
        return ($next && !$this->terminate) ?
112
            $next->next($request, $response) :
113
            $response;
114
    }
115
116
    /**
117
     * {@inheritDoc}
118
     */
119
    public function next(
120
        RequestInterface $request,
121
        ResponseInterface $response
122
    )/*# : ResponseInterface */ {
123
        if ($this->queue->valid()) {
124
            list($middleware, $condition) = $this->queue->current();
125
            $this->queue->next();
126
127
            if (null === $condition ||
128
                $this->evalCondition($condition, $request, $response)
129
            ) { // run this mw
130
                return $this->runMiddleware($middleware, $request, $response);
131
            } else { // skip this mw
132
                return $this->next($request, $response);
133
            }
134
        }
135
        $this->queue->rewind();
136
        return $response;
137
    }
138
139
    /**
140
     * Fill the queue with middlewares
141
     *
142
     * @param  array $middlewares
143
     * @access protected
144
     */
145
    protected function fillTheQueue(array $middlewares)
146
    {
147
        foreach ($middlewares as $mw) {
148
            // with conditions specified
149
            if (is_array($mw)) {
150
                $this->push($mw[0], $mw[1]);
151
152
            // no condition
153
            } else {
154
                $this->push($mw);
155
            }
156
        }
157
    }
158
159
    /**
160
     * Process/run this middleware
161
     *
162
     * @param  MiddlewareInterface|callable $middleware
163
     * @param  RequestInterface $request
164
     * @param  ResponseInterface $response
165
     * @return ResponseInterface
166
     * @throws LogicException if invalid middleware type
167
     * @access protected
168
     */
169 View Code Duplication
    protected function runMiddleware(
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...
170
        $middleware,
171
        RequestInterface $request,
172
        ResponseInterface $response
173
    )/*# : ResponseInterface */ {
174
        // instance of MiddlewareInterface
175
        if (is_object($middleware) && $middleware instanceof MiddlewareInterface) {
176
            return $middleware->process($request, $response, $this);
177
178
        // old style callable
179
        } elseif (is_callable($middleware)) {
180
            return $middleware($request, $response, $this);
181
182
        // unknown middleware type
183
        } else {
184
            throw new LogicException(
185
                Message::get(Message::MIDDLEWARE_INVALID, $middleware),
186
                Message::MIDDLEWARE_INVALID
187
            );
188
        }
189
    }
190
191
    /**
192
     * Evaluate the condition
193
     *
194
     * support both a callable returns bool value or an object instance of
195
     * ConditionInterface.
196
     *
197
     * @param  ConditionInterface|callable $condition
198
     * @param  RequestInterface $request
199
     * @param  ResponseInterface $response
200
     * @return bool
201
     * @throws LogicException if condition is invalid
202
     * @access protected
203
     */
204 View Code Duplication
    protected function evalCondition(
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...
205
        $condition,
206
        RequestInterface $request,
207
        ResponseInterface $response
208
    )/*# : bool */ {
209
        // instanceof ConditionInterface
210
        if (is_object($condition) && $condition instanceof ConditionInterface) {
211
            return $condition->evaluate($request, $response);
212
213
        // old style callable
214
        } elseif (is_callable($condition)) {
215
            return $condition($request, $response);
216
217
        // unknown type
218
        } else {
219
            throw new LogicException(
220
                Message::get(Message::CONDITION_INVALID, $condition),
221
                Message::CONDITION_INVALID
222
            );
223
        }
224
    }
225
}
226