8000 Automatically apply PreventBrowserAccess middleware (#551) · NativePHP/laravel@9d1fc92 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d1fc92

Browse files
authored
Automatically apply PreventBrowserAccess middleware (#551)
* skip when running tests * skip when not in Electron context * automatically apply middleware to 'web' group * apply middleware to all routes
1 parent 11cb34f commit 9d1fc92

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Http/Middleware/PreventRegularBrowserAccess.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class PreventRegularBrowserAccess
99
{
1010
public function handle(Request $request, Closure $next)
1111
{
12+
if (! config('nativephp-internal.running')) {
13+
return $next($request);
14+
}
15+
1216
// Explicitly skip for the cookie-setting route
1317
if ($request->path() === '_native/api/cookie') {
1418
return $next($request);

src/NativeServiceProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Application;
66
use Illuminate\Foundation\Application as Foundation;
7+
use Illuminate\Foundation\Http\Kernel;
78
use Illuminate\Support\Arr;
89
use Illuminate\Support\Facades\Artisan;
910
use Illuminate\Support\Facades\DB;
@@ -23,6 +24,7 @@
2324
use Native\Laravel\Events\EventWatcher;
2425
use Native\Laravel\Exceptions\Handler;
2526
use Native\Laravel\GlobalShortcut as GlobalShortcutImplementation;
27+
use Native\Laravel\Http\Middleware\PreventRegularBrowserAccess;
2628
use Native\Laravel\Logging\LogWatcher;
2729
use Native\Laravel\PowerMonitor as PowerMonitorImplementation;
2830
use Native\Laravel\Windows\WindowManager as WindowManagerImplementation;
@@ -84,6 +86,11 @@ public function packageRegistered()
8486
Handler::class
8587
);
8688

89+
// Automatically prevent browser access
90+
$this->app->make(Kernel::class)->pushMiddleware(
91+
PreventRegularBrowserAccess::class,
92+
);
93+
8794
Application::starting(function ($app) {
8895
$app->resolveCommands([
8996
LoadStartupConfigurationCommand::class,

0 commit comments

Comments
 (0)
0