-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathapp.php
More file actions
131 lines (121 loc) · 5.6 KB
/
Copy pathapp.php
File metadata and controls
131 lines (121 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
use App\Http\Middleware\CheckColorSettings;
use App\Http\Middleware\CheckForDebug;
use App\Http\Middleware\CheckForSetup;
use App\Http\Middleware\CheckForTwoFactor;
use App\Http\Middleware\CheckLocale;
use App\Http\Middleware\CheckPermissions;
use App\Http\Middleware\CheckUserIsActivated;
use App\Http\Middleware\EncryptCookies;
use App\Http\Middleware\EnforceApiTwoFactorEnrollment;
use App\Http\Middleware\EnforceApiUserAgent;
use App\Http\Middleware\IssueFreshApiTokenIfTwoFactorComplete;
use App\Http\Middleware\LogAuthedUserHeader;
use App\Http\Middleware\NoSessionStore;
use App\Http\Middleware\PreventBackHistory;
use App\Http\Middleware\SecurityHeaders;
use App\Http\Middleware\SetAPIResponseHeaders;
use App\Http\Middleware\SetPaginationDefaults;
use App\Http\Middleware\TrustProxies;
use App\Http\Middleware\VerifyCsrfToken;
use Illuminate\Auth\Middleware\Authenticate;
use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth;
use Illuminate\Auth\Middleware\Authorize;
use Illuminate\Auth\Middleware\RedirectIfAuthenticated;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
$app = Application::configure(basePath: dirname(__DIR__))
// Auto-discovers plain handle()-style listeners in app/Listeners (e.g. LogSuccessfulLogin,
// LogFailedLogin). Subscriber-pattern listeners (LogListener, FulfillCheckoutRequestListener,
// CheckoutableListener, CheckoutablesCheckedOutInBulkListener) are unaffected - discovery has
// no concept of subscribers - and stay registered via $subscribe in
// App\Providers\EventServiceProvider (config/app.php), which is otherwise untouched.
->withEvents(false)
->withMiddleware(function (Middleware $middleware) {
// --- Global stack ---
// ValidatePathEncoding, InvokeDeferredCallbacks, *NOT* TrustProxies, HandleCors,
// PreventRequestsDuringMaintenance, ValidatePostSize, ConvertEmptyStringsToNull
// all come from Laravel's own defaults now, so future additions there show up
// automatically. Only Snipe-IT's own additions are listed explicitly below.
$middleware->trustHosts();
$middleware->prepend(TrustProxies::class);
// this was overridden, inherits from the parents but makes some changes.
// to keep this change small enough, we keep it for now
$middleware->trimStrings(except: [
'current_password',
'password',
'password_confirmation',
]);
// Order matters: NoSessionStore must run before StartSession (it may force
// the array session driver for /health); CheckForSetup/CheckForDebug need
// the session/auth state StartSession sets up. These run globally (not just
// in the 'web' group) because /health uses Route::withoutMiddleware(['web'])
// and still needs them.
$middleware->append([
NoSessionStore::class,
StartSession::class,
ShareErrorsFromSession::class,
CheckForSetup::class,
CheckForDebug::class,
SecurityHeaders::class,
PreventBackHistory::class,
]);
// --- Groups (explicit, not merged with Laravel's group defaults: Snipe-IT's
// web/api groups intentionally diverge - e.g. StartSession/ShareErrorsFromSession
// are global instead of web-group-only, and VerifyCsrfToken is a custom subclass
// incompatible with the new validateCsrfTokens() helper) ---
$middleware->group('web', [
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
VerifyCsrfToken::class,
CheckLocale::class,
CheckUserIsActivated::class,
CheckForTwoFactor::class,
IssueFreshApiTokenIfTwoFactorComplete::class,
CheckColorSettings::class,
AuthenticateSession::class,
SubstituteBindings::class,
]);
$middleware->group('api', [
'auth:api',
CheckUserIsActivated::class,
EnforceApiTwoFactorEnrollment::class,
EnforceApiUserAgent::class,
CheckLocale::class,
LogAuthedUserHeader::class,
SetPaginationDefaults::class,
SubstituteBindings::class,
]);
$middleware->group('health', []);
$middleware->alias([
'auth' => Authenticate::class,
'authorize' => CheckPermissions::class,
'auth.basic' => AuthenticateWithBasicAuth::class,
'can' => Authorize::class,
'guest' => RedirectIfAuthenticated::class,
'throttle' => ThrottleRequests::class,
'api-throttle' => SetAPIResponseHeaders::class,
]);
})
->create();
// Keep Snipe-IT's own Console Kernel (custom schedule + command/route loading) and
// Exception Handler (SCIM, 2FA, API-JSON rendering) instead of Laravel's closure-based
// withSchedule()/withExceptions() APIs - there's no "silently missing default" risk for
// either of these the way there was for HTTP middleware, so rewriting them adds risk
// without fixing anything.
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
return $app;