This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 App\Exceptions; |
||
4 | |||
5 | use Exception; |
||
6 | use Illuminate\Auth\AuthenticationException; |
||
7 | use Illuminate\Database\Eloquent\ModelNotFoundException; |
||
8 | use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; |
||
9 | use Illuminate\Http\Exceptions\HttpResponseException; |
||
10 | use Illuminate\Session\TokenMismatchException; |
||
11 | use Illuminate\Validation\ValidationException; |
||
12 | |||
13 | class Handler extends ExceptionHandler |
||
14 | { |
||
15 | /** |
||
16 | * A list of the exception types that should not be reported. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $dontReport = [ |
||
21 | \Illuminate\Auth\AuthenticationException::class, |
||
22 | \Illuminate\Auth\Access\AuthorizationException::class, |
||
23 | \Symfony\Component\HttpKernel\Exception\HttpException::class, |
||
24 | \Illuminate\Database\Eloquent\ModelNotFoundException::class, |
||
25 | \Illuminate\Session\TokenMismatchException::class, |
||
26 | \Illuminate\Validation\ValidationException::class, |
||
27 | \Illuminate\Database\Eloquent\ModelNotFoundException::class, |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * Report or log an exception. |
||
32 | * |
||
33 | * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
||
34 | * |
||
35 | * @param \Exception $exception |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | 12 | public function report(Exception $exception) |
|
40 | { |
||
41 | 12 | parent::report($exception); |
|
42 | 12 | } |
|
43 | |||
44 | /** |
||
45 | * Render an exception into an HTTP response. |
||
46 | * |
||
47 | * @param \Illuminate\Http\Request $request |
||
48 | * |
||
49 | * @return \Illuminate\Http\Response |
||
50 | */ |
||
51 | public function render($request, Exception $e) |
||
52 | { |
||
53 | // the below code is for Whoops support. Since Whoops can open some security holes we want to only have it |
||
54 | // enabled in the debug environment. We also don't want Whoops to handle 404 and Validation related exceptions. |
||
55 | if (config('app.debug') && ! ($e instanceof ValidationException) && ! ($e instanceof HttpResponseException)) { |
||
56 | return $this->renderExceptionWithWhoops($e); |
||
57 | } |
||
58 | |||
59 | // this line allows you to redirect to a route or even back to the current page |
||
60 | // if there is a CSRF Token Mismatch |
||
61 | if ($e instanceof TokenMismatchException) { |
||
62 | return redirect()->route('homepage'); |
||
0 ignored issues
–
show
|
|||
63 | } |
||
64 | |||
65 | // let's add some support if a Model is not found |
||
66 | // for example, if you were to run a query for User #10000 and that user didn't exist we can return a 404 error |
||
67 | if ($e instanceof ModelNotFoundException) { |
||
68 | return response()->view('errors.404', [], 404); |
||
69 | } |
||
70 | |||
71 | // Let's return a default error page instead of the ugly Laravel error page when we have fatal exceptions |
||
72 | if ($e instanceof \Symfony\Component\Debug\Exception\FatalErrorException) { |
||
73 | return response()->view('errors.500', [], 500); |
||
74 | } |
||
75 | |||
76 | // finally we are back to the original default error handling provided by Laravel |
||
77 | if ($this->isHttpException($e)) { |
||
78 | switch ($e->getStatusCode()) { |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Exception as the method getStatusCode() does only exist in the following sub-classes of Exception : Illuminate\Foundation\Ht...aintenanceModeException , Symfony\Component\HttpKe...cessDeniedHttpException , Symfony\Component\HttpKe...BadRequestHttpException , Symfony\Component\HttpKe...n\ConflictHttpException , Symfony\Component\HttpKe...ption\GoneHttpException , Symfony\Component\HttpKe...Exception\HttpException , Symfony\Component\HttpKe...thRequiredHttpException , Symfony\Component\HttpKe...NotAllowedHttpException , Symfony\Component\HttpKe...AcceptableHttpException , Symfony\Component\HttpKe...n\NotFoundHttpException , Symfony\Component\HttpKe...tionFailedHttpException , Symfony\Component\HttpKe...onRequiredHttpException , Symfony\Component\HttpKe...navailableHttpException , Symfony\Component\HttpKe...nyRequestsHttpException , Symfony\Component\HttpKe...authorizedHttpException , Symfony\Component\HttpKe...ableEntityHttpException , Symfony\Component\HttpKe...dMediaTypeHttpException . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
79 | // not found |
||
80 | case 404: |
||
81 | return response()->view('errors.404', [], 404); |
||
82 | break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
83 | // internal error |
||
84 | case 500: |
||
85 | return response()->view('errors.500', [], 500); |
||
86 | break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
87 | |||
88 | default: |
||
89 | return $this->renderHttpException($e); |
||
0 ignored issues
–
show
$e of type object<Exception> is not a sub-type of object<Symfony\Component...xception\HttpException> . It seems like you assume a child class of the class Exception to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() |
|||
90 | break; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
91 | } |
||
92 | } else { |
||
93 | return parent::render($request, $e); |
||
94 | } |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Render an exception using Whoops. |
||
99 | * |
||
100 | * @param \Exception $e |
||
101 | * |
||
102 | * @return \Illuminate\Http\Response |
||
103 | */ |
||
104 | protected function renderExceptionWithWhoops(Exception $e) |
||
105 | { |
||
106 | if (config('app.debug')) { |
||
107 | $whoops = new \Whoops\Run(); |
||
108 | $whoops->pushHandler(new \Whoops\Handler\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);
![]() |
|||
109 | |||
110 | return new \Illuminate\Http\Response( |
||
111 | $whoops->handleException($e), |
||
0 ignored issues
–
show
$e is of type object<Exception> , but the function expects a object<Throwable> .
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);
![]() |
|||
112 | $e->getStatusCode(), |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Exception as the method getStatusCode() does only exist in the following sub-classes of Exception : Illuminate\Foundation\Ht...aintenanceModeException , Symfony\Component\HttpKe...cessDeniedHttpException , Symfony\Component\HttpKe...BadRequestHttpException , Symfony\Component\HttpKe...n\ConflictHttpException , Symfony\Component\HttpKe...ption\GoneHttpException , Symfony\Component\HttpKe...Exception\HttpException , Symfony\Component\HttpKe...thRequiredHttpException , Symfony\Component\HttpKe...NotAllowedHttpException , Symfony\Component\HttpKe...AcceptableHttpException , Symfony\Component\HttpKe...n\NotFoundHttpException , Symfony\Component\HttpKe...tionFailedHttpException , Symfony\Component\HttpKe...onRequiredHttpException , Symfony\Component\HttpKe...navailableHttpException , Symfony\Component\HttpKe...nyRequestsHttpException , Symfony\Component\HttpKe...authorizedHttpException , Symfony\Component\HttpKe...ableEntityHttpException , Symfony\Component\HttpKe...dMediaTypeHttpException . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
113 | $e->getHeaders() |
||
0 ignored issues
–
show
It seems like you code against a specific sub-type and not the parent class
Exception as the method getHeaders() does only exist in the following sub-classes of Exception : Illuminate\Foundation\Ht...aintenanceModeException , Symfony\Component\HttpKe...cessDeniedHttpException , Symfony\Component\HttpKe...BadRequestHttpException , Symfony\Component\HttpKe...n\ConflictHttpException , Symfony\Component\HttpKe...ption\GoneHttpException , Symfony\Component\HttpKe...Exception\HttpException , Symfony\Component\HttpKe...thRequiredHttpException , Symfony\Component\HttpKe...NotAllowedHttpException , Symfony\Component\HttpKe...AcceptableHttpException , Symfony\Component\HttpKe...n\NotFoundHttpException , Symfony\Component\HttpKe...tionFailedHttpException , Symfony\Component\HttpKe...onRequiredHttpException , Symfony\Component\HttpKe...navailableHttpException , Symfony\Component\HttpKe...nyRequestsHttpException , Symfony\Component\HttpKe...authorizedHttpException , Symfony\Component\HttpKe...ableEntityHttpException , Symfony\Component\HttpKe...dMediaTypeHttpException . Maybe you want to instanceof check for one of these explicitly?
Let’s take a look at an example: abstract class User
{
/** @return string */
abstract public function getPassword();
}
class MyUser extends User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
114 | ); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Convert an authentication exception into an unauthenticated response. |
||
120 | * |
||
121 | * @param \Illuminate\Http\Request $request |
||
122 | * @param \Illuminate\Auth\AuthenticationException $exception |
||
123 | * |
||
124 | * @return \Illuminate\Http\Response |
||
125 | */ |
||
126 | protected function unauthenticated($request, AuthenticationException $exception) |
||
0 ignored issues
–
show
|
|||
127 | { |
||
128 | if ($request->expectsJson()) { |
||
129 | return response()->json(['error' => 'Unauthenticated.'], 401); |
||
130 | } |
||
131 | |||
132 | return redirect()->guest(route('login')); |
||
133 | } |
||
134 | } |
||
135 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.