Skip to content

Commit dca5361

Browse files
committed
Ensure we don't cause a mess with the auth providers
1 parent 3ae70ef commit dca5361

File tree

6 files changed

+233
-15
lines changed

6 files changed

+233
-15
lines changed

app/Http/Kernel.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pterodactyl\Http;
44

5+
use Fruitcake\Cors\HandleCors;
56
use Illuminate\Auth\Middleware\Authorize;
67
use Illuminate\Auth\Middleware\Authenticate;
78
use Illuminate\Http\Middleware\TrustProxies;
@@ -26,9 +27,9 @@
2627
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
2728
use Pterodactyl\Http\Middleware\Api\Daemon\DaemonAuthenticate;
2829
use Pterodactyl\Http\Middleware\RequireTwoFactorAuthentication;
29-
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode;
3030
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
3131
use Pterodactyl\Http\Middleware\Api\Client\SubstituteClientBindings;
32+
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance;
3233
use Pterodactyl\Http\Middleware\Api\Application\AuthenticateApplicationUser;
3334

3435
class Kernel extends HttpKernel
@@ -39,12 +40,12 @@ class Kernel extends HttpKernel
3940
* @var array
4041
*/
4142
protected $middleware = [
42-
CheckForMaintenanceMode::class,
43-
EncryptCookies::class,
43+
TrustProxies::class,
44+
HandleCors::class,
45+
PreventRequestsDuringMaintenance::class,
4446
ValidatePostSize::class,
4547
TrimStrings::class,
4648
ConvertEmptyStringsToNull::class,
47-
TrustProxies::class,
4849
];
4950

5051
/**
@@ -54,14 +55,13 @@ class Kernel extends HttpKernel
5455
*/
5556
protected $middlewareGroups = [
5657
'web' => [
58+
EncryptCookies::class,
5759
AddQueuedCookiesToResponse::class,
5860
StartSession::class,
59-
AuthenticateSession::class,
6061
ShareErrorsFromSession::class,
6162
VerifyCsrfToken::class,
6263
SubstituteBindings::class,
6364
LanguageMiddleware::class,
64-
RequireTwoFactorAuthentication::class,
6565
],
6666
'api' => [
6767
EnsureStatefulRequests::class,
@@ -91,6 +91,7 @@ class Kernel extends HttpKernel
9191
protected $routeMiddleware = [
9292
'auth' => Authenticate::class,
9393
'auth.basic' => AuthenticateWithBasicAuth::class,
94+
'auth.session' => AuthenticateSession::class,
9495
'guest' => RedirectIfAuthenticated::class,
9596
'csrf' => VerifyCsrfToken::class,
9697
'throttle' => ThrottleRequests::class,

app/Providers/RouteServiceProvider.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Illuminate\Support\Facades\RateLimiter;
1010
use Pterodactyl\Http\Middleware\TrimStrings;
1111
use Pterodactyl\Http\Middleware\AdminAuthenticate;
12+
use Pterodactyl\Http\Middleware\RequireTwoFactorAuthentication;
1213
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
1314

1415
class RouteServiceProvider extends ServiceProvider
@@ -35,12 +36,17 @@ public function boot()
3536

3637
$this->routes(function () {
3738
Route::middleware('web')->group(function () {
38-
Route::middleware('auth')->group(base_path('routes/base.php'));
39+
Route::middleware(['auth.session', RequireTwoFactorAuthentication::class])
40+
->group(base_path('routes/base.php'));
41+
42+
Route::middleware(['auth.session', RequireTwoFactorAuthentication::class, AdminAuthenticate::class])
43+
->prefix('/admin')
44+
->group(base_path('routes/admin.php'));
45+
3946
Route::middleware('guest')->prefix('/auth')->group(base_path('routes/auth.php'));
40-
Route::middleware(['auth', AdminAuthenticate::class])->prefix('/admin')->group(base_path('routes/admin.php'));
4147
});
4248

43-
Route::middleware('api')->group(function () {
49+
Route::middleware(['api', RequireTwoFactorAuthentication::class])->group(function () {
4450
Route::middleware(['application-api', 'throttle:api.application'])
4551
->prefix('/api/application')
4652
->scopeBindings()

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"ext-zip": "*",
2020
"aws/aws-sdk-php": "^3.171",
2121
"doctrine/dbal": "~2.13.9",
22+
"fruitcake/laravel-cors": "~3.0.0",
2223
"guzzlehttp/guzzle": "~7.4.2",
2324
"hashids/hashids": "~4.1.0",
2425
"laracasts/utilities": "~3.2.1",

composer.lock

+151-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/cors.php

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Laravel CORS Options
7+
|--------------------------------------------------------------------------
8+
|
9+
| The allowed_methods and allowed_headers options are case-insensitive.
10+
|
11+
| You don't need to provide both allowed_origins and allowed_origins_patterns.
12+
| If one of the strings passed matches, it is considered a valid origin.
13+
|
14+
| If ['*'] is provided to allowed_methods, allowed_origins or allowed_headers
15+
| all methods / origins / headers are allowed.
16+
|
17+
*/
18+
19+
/*
20+
* You can enable CORS for 1 or multiple paths.
21+
* Example: ['api/*']
22+
*/
23+
'paths' => ['/api/client', '/api/application', '/api/client/*', '/api/application/*'],
24+
25+
/*
26+
* Matches the request method. `['*']` allows all methods.
27+
*/
28+
'allowed_methods' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'],
29+
30+
/*
31+
* Matches the request origin. `['*']` allows all origins. Wildcards can be used, eg `*.mydomain.com`
32+
*/
33+
'allowed_origins' => explode(',', env('APP_CORS_ALLOWED_ORIGINS') ?? ''),
34+
35+
/*
36+
* Patterns that can be used with `preg_match` to match the origin.
37+
*/
38+
'allowed_origins_patterns' => [],
39+
40+
/*
41+
* Sets the Access-Control-Allow-Headers response header. `['*']` allows all headers.
42+
*/
43+
'allowed_headers' => ['*'],
44+
45+
/*
46+
* Sets the Access-Control-Expose-Headers response header with these headers.
47+
*/
48+
'exposed_headers' => [],
49+
50+
/*
51+
* Sets the Access-Control-Max-Age response header when > 0.
52+
*/
53+
'max_age' => 0,
54+
55+
/*
56+
* Sets the Access-Control-Allow-Credentials header.
57+
*/
58+
'supports_credentials' => true,
59+
];

resources/scripts/api/auth/login.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ export interface LoginData {
1414

1515
export default ({ username, password, recaptchaData }: LoginData): Promise<LoginResponse> => {
1616
return new Promise((resolve, reject) => {
17-
http.post('/auth/login', {
18-
user: username,
19-
password,
20-
'g-recaptcha-response': recaptchaData,
21-
})
17+
http.get('/sanctum/csrf-cookie')
18+
.then(() => http.post('/auth/login', {
19+
user: username,
20+
password,
21+
'g-recaptcha-response': recaptchaData,
22+
}))
2223
.then(response => {
2324
if (!(response.data instanceof Object)) {
2425
return reject(new Error('An error occurred while processing the login request.'));

0 commit comments

Comments
 (0)