Issues (1)

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/RestException.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 Josh\Exceptions;
4
5
use Exception;
6
use Illuminate\Http\Request;
7
use Anetwork\Respond\Facades\Respond;
8
use Illuminate\Database\Eloquent\ModelNotFoundException;
9
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
10
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
12
trait RestException
13
{
14
    /**
15
     * Datas of response
16
     *
17
     * @var array
18
     */
19
    protected $datas = [];
20
21
    /**
22
     * In development mode return trace of exception
23
     *
24
     * @var array
25
     */
26
    protected $trace = [];
27
28
    /**
29
     * Creates a new JSON response based on exception type.
30
     *
31
     * @author Alireza Josheghani <[email protected]>
32
     * @since  11 Nov 2016
33
     * @param  Exception $exception
34
     * @return \Anetwork\Respond\Facades\Respond
35
     */
36
    protected function getJsonResponseForException(Exception $exception)
37
    {
38
        $message = $exception->getMessage();
39
40
        $this->getTrace($exception);
41
42
        if ($exception instanceof ModelNotFoundException) {
43
            return $this->modelNotFound($message);
44
        } elseif ($exception instanceof NotFoundHttpException) {
45
            return $this->httpNotFound();
46
        } elseif ($exception instanceof BadRequestHttpException) {
47
            return $this->badRequest($message);
48
        }
49
50
        return $this->errorException($message);
51
    }
52
53
    /**
54
     * Returns json response for generic bad request.
55
     *
56
     * @author Alireza Josheghani <[email protected]>
57
     * @since  11 Nov 2016
58
     * @param  string $message
59
     * @return \Anetwork\Respond\Facades\Respond
60
     */
61
    protected function badRequest($message)
62
    {
63
        $this->datas['message'] = $message;
64
65
        return Respond::setStatusCode(400)
66
            ->setStatusText('bad request !')
67
            ->respondWithResult($this->datas);
68
    }
69
70
    /**
71
     * Returns json response ErrorException
72
     *
73
     * @author Alireza Josheghani <[email protected]>
74
     * @since  11 Nov 2016
75
     * @param  string $message
76
     * @return \Anetwork\Respond\Facades\Respond
77
     */
78
    protected function errorException($message)
79
    {
80
        $this->datas['message'] = $message;
81
82
        return Respond::setStatusCode(400)
83
            ->setStatusText('ErrorException !')
84
            ->respondWithMessage($this->datas);
85
    }
86
87
    /**
88
     * Returns json response for Eloquent model not found exception.
89
     *
90
     * @author Alireza Josheghani <[email protected]>
91
     * @since  11 Nov 2016
92
     * @param  string $message
93
     * @return \Anetwork\Respond\Facades\Respond
94
     */
95
    protected function modelNotFound($message)
96
    {
97
        $this->datas['message'] = $message;
98
99
        return Respond::setStatusCode(404)
100
            ->setStatusText('model notfound !')
101
            ->respondWithResult($this->datas);
102
    }
103
104
    /**
105
     * Returns json response for Eloquent model not found exception.
106
     *
107
     * @author Alireza Josheghani <[email protected]>
108
     * @since  11 Nov 2016
109
     * @return \Anetwork\Respond\Facades\Respond
110
     */
111
    protected function httpNotFound()
112
    {
113
        $this->datas['message'] = 'Sorry, the page you are looking for could not be found.';
114
115
        return Respond::setStatusCode(404)
116
            ->setStatusText('NotFoundHttpException')
117
            ->respondWithResult($this->datas);
118
    }
119
120
    /**
121
     * Get Trace in development mode
122
     *
123
     * @author Alireza Josheghani <[email protected]>
124
     * @since  11 Nov 2016
125
     * @param  Exception $exception
126
     * @return void
127
     */
128
    private function getTrace(Exception $exception)
129
    {
130
131
        if (config('app.debug')) {
132
133
            $traces = $exception->getTrace();
134
135
            if (!empty($traces)) {
136
                foreach ($traces as $trace) {
137
                    unset($trace['args']);
138
                    $this->trace[] = $trace;
139
                }
140
141
                $this->datas['trace'] = $this->trace;
142
            }
143
        }
144
    }
145
146
    /**
147
     * Render json exception
148
     *
149
     * @author Alireza Josheghani <[email protected]>
150
     * @since  11 Nov 2016
151
     * @param  Request   $request
152
     * @param  Exception $exception
153
     * @return \Anetwork\Respond\Facades\Respond
154
     */
155
    public function renderRestException(Request $request, Exception $exception)
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
156
    {
157
        return $this->getJsonResponseForException($exception);
158
    }
159
160
}
161