Skip to content

Commit f42bc8a

Browse files
committed
Cleanup exception reporting, stop logging PDO exception stacks.
PDOException stacks include the MySQL password for the connection attempt and many people do not realize this when providing logs.
1 parent ff8b5fc commit f42bc8a

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1212
* `[rc.1]` — Fixed a bug that would occur when attempting to reset the daemon secret for a node.
1313
* `[rc.1]` — Fix exception thrown when attempting to modify an existing database host.
1414

15+
### Changed
16+
* Changed logger to skip reporting stack-traces on PDO exceptions due to sensitive information being contained within.
17+
1518
## v0.7.0-rc.1 (Derelict Dermodactylus)
1619
### Fixed
1720
* `[beta.4]` — Fixes some bad search and replace action that happened previously and was throwing errors when validating user permissions.

app/Exceptions/Handler.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Pterodactyl\Exceptions;
44

55
use Exception;
6+
use PDOException;
7+
use Psr\Log\LoggerInterface;
68
use Illuminate\Auth\AuthenticationException;
79
use Illuminate\Session\TokenMismatchException;
810
use Illuminate\Validation\ValidationException;
@@ -43,17 +45,35 @@ class Handler extends ExceptionHandler
4345
];
4446

4547
/**
46-
* Report or log an exception.
48+
* Report or log an exception. Skips Laravel's internal reporter since we
49+
* don't need or want the user information in our logs by default.
4750
*
48-
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
51+
* If you want to implement logging in a different format to integrate with
52+
* services such as AWS Cloudwatch or other monitoring you can replace the
53+
* contents of this function with a call to the parent reporter.
4954
*
5055
* @param \Exception $exception
56+
* @return mixed
5157
*
5258
* @throws \Exception
5359
*/
5460
public function report(Exception $exception)
5561
{
56-
parent::report($exception);
62+
if (! config('app.exceptions.report_all', false) && $this->shouldntReport($exception)) {
63+
return null;
64+
}
65+
66+
if (method_exists($exception, 'report')) {
67+
return $exception->report();
68+
}
69+
70+
try {
71+
$logger = $this->container->make(LoggerInterface::class);
72+
} catch (Exception $ex) {
73+
throw $exception;
74+
}
75+
76+
return $logger->error($exception instanceof PDOException ? $exception->getMessage() : $exception);
5777
}
5878

5979
/**
@@ -71,6 +91,9 @@ public function render($request, Exception $exception)
7191
}
7292

7393
/**
94+
* Transform a validation exception into a consistent format to be returned for
95+
* calls to the API.
96+
*
7497
* @param \Illuminate\Http\Request $request
7598
* @param \Illuminate\Validation\ValidationException $exception
7699
* @return \Illuminate\Http\JsonResponse

config/app.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@
133133

134134
'log_level' => env('APP_LOG_LEVEL', 'info'),
135135

136+
/*
137+
|--------------------------------------------------------------------------
138+
| Exception Reporter Configuration
139+
|--------------------------------------------------------------------------
140+
|
141+
| If you're encountering weird behavior with the Panel and no exceptions
142+
| are being logged try changing the environment variable below to be true.
143+
| This will override the default "don't report" behavior of the Panel and log
144+
| all exceptions. This will be quite noisy.
145+
|
146+
*/
147+
148+
'exceptions' => [
149+
'report_all' => env('APP_REPORT_ALL_EXCEPTIONS', false),
150+
],
151+
136152
/*
137153
|--------------------------------------------------------------------------
138154
| Autoloaded Service Providers

0 commit comments

Comments
 (0)