Issues (286)

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.

app/Ship/core/Abstracts/Exceptions/Exception.php (1 issue)

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 Apiato\Core\Abstracts\Exceptions;
4
5
use App\Ship\Exceptions\Codes\ErrorCodeManager;
6
use Exception as BaseException;
7
use Illuminate\Support\Facades\Config;
8
use Illuminate\Support\MessageBag;
9
use Log;
10
use Symfony\Component\HttpFoundation\Response;
11
use Symfony\Component\HttpKernel\Exception\HttpException as SymfonyHttpException;
12
13
/**
14
 * Class Exception.
15
 *
16
 * @author  Mahmoud Zalt <[email protected]>
17
 */
18
abstract class Exception extends SymfonyHttpException
19
{
20
21
    /**
22
     * MessageBag errors.
23
     *
24
     * @var \Illuminate\Support\MessageBag
25
     */
26
    protected $errors;
27
28
    /**
29
     * Default status code.
30
     *
31
     * @var int
32
     */
33
    CONST DEFAULT_STATUS_CODE = Response::HTTP_INTERNAL_SERVER_ERROR;
34
35
    /**
36
     * @var string
37
     */
38
    protected $environment;
39
40
    /**
41
     * @var mixed
42
     */
43
    private $customData = null;
44
45
    /**
46
     * Exception constructor.
47
     *
48
     * @param null            $message
49
     * @param null            $errors
50
     * @param null            $statusCode
51
     * @param int             $code
52
     * @param \Exception|null $previous
53
     * @param array           $headers
54
     */
55
    public function __construct(
56
        $message = null,
57
        $errors = null,
58
        $statusCode = null,
59
        $code = 0,
60
        BaseException $previous = null,
61
        $headers = []
62
    ) {
63
64
        // detect and set the running environment
65
        $this->environment = Config::get('app.env');
66
67
        $message = $this->prepareMessage($message);
68
        $error = $this->prepareError($errors);
69
        $statusCode = $this->prepareStatusCode($statusCode);
70
71
        $this->logTheError($statusCode, $message, $code);
72
73
        parent::__construct($statusCode, $message, $previous, $headers, $code);
74
75
        $this->customData = $this->addCustomData();
76
77
        $this->code = $this->evaluateErrorCode();
78
    }
79
80
    /**
81
     * Help developers debug the error without showing these details to the end user.
82
     * Usage: `throw (new MyCustomException())->debug($e)`.
83
     *
84
     * @param $error
85
     * @param $force
86
     *
87
     * @return $this
88
     */
89
    public function debug($error, $force = false)
90
    {
91
        if ($error instanceof BaseException) {
92
            $error = $error->getMessage();
93
        }
94
95
        if ($this->environment != 'testing' || $force === true) {
96
            Log::error('[DEBUG] ' . $error);
97
        }
98
99
        return $this;
100
    }
101
102
    /**
103
     * Get the errors message bag.
104
     *
105
     * @return \Illuminate\Support\MessageBag
106
     */
107
    public function getErrors()
108
    {
109
        return $this->errors;
110
    }
111
112
    /**
113
     * Determine if message bag has any errors.
114
     *
115
     * @return bool
116
     */
117
    public function hasErrors()
118
    {
119
        return !$this->errors->isEmpty();
120
    }
121
122
    /**
123
     * @param $statusCode
124
     * @param $message
125
     * @param $code
126
     */
127
    private function logTheError($statusCode, $message, $code)
128
    {
129
        // if not testing environment, log the error message
130
        if ($this->environment != 'testing') {
131
            Log::error('[ERROR] ' .
132
                'Status Code: ' . $statusCode . ' | ' .
133
                'Message: ' . $message . ' | ' .
134
                'Errors: ' . $this->errors . ' | ' .
135
                'Code: ' . $code
136
            );
137
        }
138
    }
139
140
    /**
141
     * @param null $errors
142
     *
143
     * @return  \Illuminate\Support\MessageBag|null
144
     */
145
    private function prepareError($errors = null)
146
    {
147
        return is_null($errors) ? new MessageBag() : $this->prepareArrayError($errors);
148
    }
149
150
    /**
151
     * @param array $errors
152
     *
153
     * @return  array|\Illuminate\Support\MessageBag
154
     */
155
    private function prepareArrayError(array $errors = [])
156
    {
157
        return is_array($errors) ? new MessageBag($errors) : $errors;
158
    }
159
160
    /**
161
     * @param null $message
162
     *
163
     * @return  null
164
     */
165
    private function prepareMessage($message = null)
166
    {
167
        return is_null($message) && property_exists($this, 'message') ? $this->message : $message;
168
    }
169
170
    /**
171
     * @param $statusCode
172
     *
173
     * @return  int
174
     */
175
    private function prepareStatusCode($statusCode = null)
176
    {
177
        return is_null($statusCode) ? $this->findStatusCode() : $statusCode;
178
    }
179
180
    /**
181
     * @return  int
182
     */
183
    private function findStatusCode()
184
    {
185
        return property_exists($this, 'httpStatusCode') ? $this->httpStatusCode : Self::DEFAULT_STATUS_CODE;
0 ignored issues
show
The property httpStatusCode does not seem to exist. Did you mean statusCode?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
186
    }
187
188
    /**
189
     * @return mixed
190
     */
191
    public function getCustomData()
192
    {
193
        return $this->customData;
194
    }
195
196
    /**
197
     * @return void
198
     */
199
    protected function addCustomData()
200
    {
201
        $this->customData = null;
202
    }
203
204
    /**
205
     * Append customData to the exception and return the Exception!
206
     *
207
     * @param $customData
208
     *
209
     * @return $this
210
     */
211
    public function overrideCustomData($customData)
212
    {
213
        $this->customData = $customData;
214
        return $this;
215
    }
216
217
    /**
218
     * Default value
219
     *
220
     * @return int
221
     */
222
    public function useErrorCode()
223
    {
224
        return $this->code;
225
    }
226
227
    /**
228
     * Overrides the code with the application error code (if set)
229
     *
230
     * @return int
231
     */
232
    private function evaluateErrorCode()
233
    {
234
        $code = $this->useErrorCode();
235
236
        if (is_array($code)) {
237
            $code = ErrorCodeManager::getCode($code);
238
        }
239
240
        return $code;
241
    }
242
}
243