Files
termanager2/bootstrap/app.php

55 lines
2.4 KiB
PHP

<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
// X_FORWARDED_HOST is deliberately excluded. Trusting it lets a client
// set an arbitrary Host and have route()/url() emit links pointing at
// an attacker's domain — including the public assignment PDF links,
// which carry a valid access code.
$middleware->trustProxies(
at: '*',
headers: Request::HEADER_X_FORWARDED_FOR
| Request::HEADER_X_FORWARDED_PORT
| Request::HEADER_X_FORWARDED_PROTO
);
// Second line of defence: only serve requests whose Host matches
// APP_URL. Relaxed outside production so local access by IP works.
$middleware->trustHosts(at: function () {
$host = parse_url((string) config('app.url'), PHP_URL_HOST);
// localhost/127.0.0.1 are kept for container-internal probes: the
// Docker health check and Dokploy's own checks address the
// container directly, not through the public domain. They are not
// an external hole — Traefik only forwards requests whose Host
// matches a configured domain.
return array_values(array_filter([$host, 'localhost', '127.0.0.1']));
}, subdomains: false);
// Dopo il ripristino di un backup ogni account resta bloccato finche'
// non imposta una password nuova. In coda al gruppo web, quindi la
// sessione e' gia' avviata e l'utente risolto quando gira.
$middleware->web(append: [
\App\Http\Middleware\RequirePasswordChange::class,
]);
$middleware->alias([
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();