Skip to content

Commit b12e944

Browse files
authored
[Feature] Allow public dashboard to be embedded (alexjustesen#897)
1 parent 293f85b commit b12e944

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ APP_KEY=
44
APP_DEBUG=false
55
APP_URL=http://localhost
66

7+
ALLOW_EMBEDS=
8+
79
FORCE_HTTPS=false
810

911
CONTENT_WIDTH=7xl

app/Http/Kernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,7 @@ class Kernel extends HttpKernel
6464
'signed' => \App\Http\Middleware\ValidateSignature::class,
6565
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
6666
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
67+
68+
'x-frame-allow' => \App\Http\Middleware\FrameAllowOptions::class,
6769
];
6870
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
9+
class FrameAllowOptions
10+
{
11+
/**
12+
* Handle an incoming request.
13+
*
14+
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
15+
*/
16+
public function handle(Request $request, Closure $next): Response
17+
{
18+
$response = $next($request);
19+
20+
if (! blank(config('speedtest.allow_embeds'))) {
21+
$response->header('X-Frame-Options', 'ALLOW FROM '.config('speedtest.allow_embeds'));
22+
}
23+
24+
return $response;
25+
}
26+
}

app/Http/Middleware/VerifyCsrfToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ class VerifyCsrfToken extends Middleware
1212
* @var array<int, string>
1313
*/
1414
protected $except = [
15-
//
15+
'/',
1616
];
1717
}

config/speedtest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@
2323
'notification_polling' => env('NOTIFICATION_POLLING', '60s'),
2424

2525
'results_polling' => env('RESULTS_POLLING', null),
26+
27+
/**
28+
* Security
29+
*/
30+
'allow_embeds' => env('ALLOW_EMBEDS', null),
2631
];

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
Route::get('/', HomeController::class)
18+
->middleware('x-frame-allow')
1819
->name('home');
1920

2021
Route::get('/login', function () {

0 commit comments

Comments
 (0)