Skip to content

Commit cde481e

Browse files
authored
Secure storage by default (#1443)
Disable the OpenHandler for storage by default, need to explicitly enable to browse previous requests.
1 parent 9aeb524 commit cde481e

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

config/debugbar.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@
3131
| By default, file storage (in the storage folder) is used. Redis and PDO
3232
| can also be used. For PDO, run the package migrations first.
3333
|
34+
| Warning: Enabling storage.open will allow everyone to access previous request,
35+
| do not enable open storage in publicly available environments!
36+
| Specify a callback if you want to limit based on IP or authentication.
3437
*/
3538
'storage' => [
3639
'enabled' => true,
40+
'open' => env('DEBUGBAR_OPEN_STORAGE', false), // Can be bool or callback.
3741
'driver' => 'file', // redis, file, pdo, socket, custom
3842
'path' => storage_path('debugbar'), // For file driver
3943
'connection' => null, // Leave null for default connection (Redis/PDO)

readme.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Read [the documentation](http://phpdebugbar.com/docs/) for more configuration op
1414
![Debugbar 3.3 Screenshot](https://user-images.githubusercontent.com/973269/79428890-196cc680-7fc7-11ea-8229-189f5eac9009.png)
1515

1616

17-
> Note: Use the DebugBar only in development. Do not use Debugbar on public websites, as it will leak information from stored requests (by design). It can also slow the application down (because it has to gather data). So when experiencing slowness, try disabling some of the collectors.
17+
### Note: Use the DebugBar only in development. Do not use Debugbar on publicly accessible websites, as it will leak information from stored requests (by design). It can also slow the application down (because it has to gather data). So when experiencing slowness, try disabling some of the collectors.
1818

1919
This package includes some custom collectors:
2020
- QueryCollector: Show all queries, including binding + timing
@@ -183,6 +183,12 @@ You can enable or disable the debugbar during run time.
183183

184184
NB. Once enabled, the collectors are added (and could produce extra overhead), so if you want to use the debugbar in production, disable in the config and only enable when needed.
185185

186+
## Storage
187+
188+
Debugbar remembers previous requests, which you can view using the Browse button on the right. This will only work if you enable `debugbar.storage.open` in the config.
189+
Make sure you only do this on local development, because otherwise other people will be able to view previous requests.
190+
In general, Debugbar should only be used locally or at least restricted by IP.
191+
It's possible to pass a callback, which will receive the Request object, so you can determine access to the OpenHandler storage.
186192

187193
## Twig Integration
188194

src/Controllers/OpenHandlerController.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,47 @@
33
namespace Barryvdh\Debugbar\Controllers;
44

55
use Barryvdh\Debugbar\Support\Clockwork\Converter;
6+
use DebugBar\DebugBarException;
67
use DebugBar\OpenHandler;
78
use Illuminate\Http\Request;
89
use Illuminate\Http\Response;
910

1011
class OpenHandlerController extends BaseController
1112
{
13+
/**
14+
* Check if the storage is open for inspecting.
15+
*
16+
* @param Request $request
17+
* @return bool
18+
*/
19+
protected function isStorageOpen(Request $request)
20+
{
21+
$open = config('debugbar.storage.open');
22+
23+
if (is_callable($open)) {
24+
return call_user_func($open, [$request]);
25+
}
26+
27+
return $open;
28+
}
29+
1230
public function handle(Request $request)
1331
{
14-
$openHandler = new OpenHandler($this->debugbar);
15-
$data = $openHandler->handle($request->input(), false, false);
32+
if ($this->isStorageOpen($request)) {
33+
$openHandler = new OpenHandler($this->debugbar);
34+
$data = $openHandler->handle($request->input(), false, false);
35+
} else {
36+
$data = [
37+
[
38+
'datetime' => date("Y-m-d H:i:s"),
39+
'id' => null,
40+
'ip' => $request->getClientIp(),
41+
'method' => 'ERROR',
42+
'uri' => '!! To enable public access to previous requests, set debugbar.storage.open, or DEBUGBAR_OPEN_STORAGE to true in you config !!',
43+
'utime' => microtime(true),
44+
]
45+
];
46+
}
1647

1748
return new Response(
1849
$data,
@@ -30,8 +61,12 @@ public function handle(Request $request)
3061
* @return mixed
3162
* @throws \DebugBar\DebugBarException
3263
*/
33-
public function clockwork($id)
64+
public function clockwork(Request $request, $id)
3465
{
66+
if (!$this->isStorageOpen($request)) {
67+
throw new DebugBarException(" o enable public access to previous requests, set debugbar.storage.open, or DEBUGBAR_OPEN_STORAGE to true in you config");
68+
}
69+
3570
$request = [
3671
'op' => 'get',
3772
'id' => $id,

0 commit comments

Comments
 (0)