Skip to content

Commit 9fe5057

Browse files
committed
Merge branch 'main' of github.com:NativePHP/laravel
2 parents 20163b5 + 355db01 commit 9fe5057

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

.github/workflows/dependabot-auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- name: Dependabot metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v1.4.0
16+
uses: dependabot/fetch-metadata@v1.5.1
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
ref: ${{ github.head_ref }}
2020

2121
- name: Fix PHP code style issues
22-
uses: aglipanci/laravel-pint-action@2.2.0
22+
uses: aglipanci/laravel-pint-action@2.3.0
2323

2424
- name: Commit changes
2525
uses: stefanzweifel/git-auto-commit-action@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ phpstan.neon
99
testbench.yaml
1010
vendor
1111
node_modules
12+
.DS_Store

routes/api.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Illuminate\Support\Facades\Route;
4+
use Native\Laravel\Http\Controllers\CreateSecurityCookieController;
45
use Native\Laravel\Http\Controllers\DispatchEventFromAppController;
56
use Native\Laravel\Http\Controllers\NativeAppBootedController;
67
use Native\Laravel\Http\Middleware\PreventRegularBrowserAccess;
@@ -9,3 +10,5 @@
910
Route::post('_native/api/booted', NativeAppBootedController::class);
1011
Route::post('_native/api/events', DispatchEventFromAppController::class);
1112
})->withoutMiddleware(\App\Http\Middleware\VerifyCsrfToken::class);
13+
14+
Route::get('_native/api/cookie', CreateSecurityCookieController::class);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Native\Laravel\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class CreateSecurityCookieController
8+
{
9+
public function __invoke(Request $request)
10+
{
11+
if ($request->get('secret') !== config('native-php.secret')) {
12+
return abort(403);
13+
}
14+
15+
return redirect('/')->cookie(cookie(
16+
name: '_php_native',
17+
value: config('native-php.secret'),
18+
domain: 'localhost',
19+
httpOnly: true,
20+
));
21+
}
22+
}

src/Http/Middleware/PreventRegularBrowserAccess.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ class PreventRegularBrowserAccess
99
{
1010
public function handle(Request $request, Closure $next)
1111
{
12+
// Explicitly skip for the cookie-setting route
13+
if ($request->path() === '_native/api/cookie') {
14+
return $next($request);
15+
}
16+
1217
$cookie = $request->cookie('_php_native');
1318
$header = $request->header('X-NativePHP-Secret');
1419

0 commit comments

Comments
 (0)