Issues (23)

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/Middleware/Whoops.php (8 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 Psr7Middlewares\Middleware;
4
5
use Psr7Middlewares\Utils;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
use Whoops\Run;
9
use Whoops\Handler\PrettyPageHandler;
10
use Whoops\Handler\PlainTextHandler;
11
use Whoops\Handler\JsonResponseHandler;
12
use Whoops\Handler\XmlResponseHandler;
13
14
/**
15
 * Middleware to use whoops as error handler.
16
 */
17
class Whoops
18
{
19
    use Utils\StreamTrait;
20
21
    /**
22
     * @var Run|null The provided instance of Whoops
23
     */
24
    private $whoops;
25
26
    /**
27
     * @var bool Whether catch errors or not
28
     */
29
    private $catchErrors = true;
30
31
    /**
32
     * Set the whoops instance.
33
     *
34
     * @param Run|null $whoops
35
     */
36
    public function __construct(Run $whoops = null)
37
    {
38
        $this->whoops = $whoops;
39
    }
40
41
    /**
42
     * Whether catch errors or not.
43
     *
44
     * @param bool $catchErrors
45
     *
46
     * @return self
47
     */
48
    public function catchErrors($catchErrors = true)
49
    {
50
        $this->catchErrors = (bool) $catchErrors;
51
52
        return $this;
53
    }
54
55
    /**
56
     * Execute the middleware.
57
     *
58
     * @param ServerRequestInterface $request
59
     * @param ResponseInterface      $response
60
     * @param callable               $next
61
     *
62
     * @return ResponseInterface
63
     */
64
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
65
    {
66
        ob_start();
67
        $level = ob_get_level();
68
69
        $method = Run::EXCEPTION_HANDLER;
70
        $whoops = $this->getWhoopsInstance($request);
71
72
        $whoops->allowQuit(false);
73
        $whoops->writeToOutput(false);
74
        $whoops->sendHttpCode(false);
75
76
        //Catch errors means register whoops globally
77
        if ($this->catchErrors) {
78
            $whoops->register();
79
        }
80
81
        try {
82
            $response = $next($request, $response);
83
        } catch (\Throwable $exception) {
0 ignored issues
show
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
84
            $body = self::createStream($response->getBody());
85
            $body->write($whoops->$method($exception));
86
            $response = $response->withStatus(500)->withBody($body);
87
        } catch (\Exception $exception) {
88
            $body = self::createStream($response->getBody());
89
            $body->write($whoops->$method($exception));
90
            $response = $response->withStatus(500)->withBody($body);
91
        } finally {
92
            Utils\Helpers::getOutput($level);
93
        }
94
95
        if ($this->catchErrors) {
96
            $whoops->unregister();
97
        }
98
99
        return $response;
100
    }
101
102
    /**
103
     * Returns the whoops instance or create one.
104
     *
105
     * @param ServerRequestInterface $request
106
     *
107
     * @return Run
108
     */
109
    private function getWhoopsInstance(ServerRequestInterface $request)
110
    {
111
        if ($this->whoops) {
112
            return $this->whoops;
113
        }
114
115
        $whoops = new Run();
116
117
        if (php_sapi_name() === 'cli') {
118
            $whoops->pushHandler(new PlainTextHandler());
0 ignored issues
show
new \Whoops\Handler\PlainTextHandler() is of type object<Whoops\Handler\PlainTextHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
119
120
            return $whoops;
121
        }
122
123
        $format = FormatNegotiator::getFormat($request);
124
125
        switch ($format) {
126
            case 'json':
127
                $whoops->pushHandler(new JsonResponseHandler());
0 ignored issues
show
new \Whoops\Handler\JsonResponseHandler() is of type object<Whoops\Handler\JsonResponseHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
128
                break;
129
130
            case 'html':
131
                $whoops->pushHandler(new PrettyPageHandler());
0 ignored issues
show
new \Whoops\Handler\PrettyPageHandler() is of type object<Whoops\Handler\PrettyPageHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
132
                break;
133
134
            case 'xml':
135
                $whoops->pushHandler(new XmlResponseHandler());
0 ignored issues
show
new \Whoops\Handler\XmlResponseHandler() is of type object<Whoops\Handler\XmlResponseHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
136
                break;
137
138
            case 'txt':
139
            case 'css':
140
            case 'js':
141
                $whoops->pushHandler(new PlainTextHandler());
0 ignored issues
show
new \Whoops\Handler\PlainTextHandler() is of type object<Whoops\Handler\PlainTextHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
142
                break;
143
144
            default:
145
                if (empty($format)) {
146
                    $whoops->pushHandler(new PrettyPageHandler());
0 ignored issues
show
new \Whoops\Handler\PrettyPageHandler() is of type object<Whoops\Handler\PrettyPageHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
147
                } else {
148
                    $whoops->pushHandler(new PlainTextHandler());
0 ignored issues
show
new \Whoops\Handler\PlainTextHandler() is of type object<Whoops\Handler\PlainTextHandler>, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
149
                }
150
151
                break;
152
        }
153
154
        return $whoops;
155
    }
156
}
157