security: round 1 — quick wins (rate limiting, headers, mass assignment, logging)
- Add throttle middleware to login (5/min), portal/token-auth (10/min), volunteer-register (5/min), and invitation routes (10/min) - Set Sanctum token expiration to 7 days - Remove billing_status from UpdateOrganisationRequest (super_admin only) - Revoke all Sanctum tokens on password reset - Strengthen password rules: min 8 chars, mixed case, numbers - Create SecurityHeaders middleware (X-Content-Type-Options, X-Frame-Options, HSTS, Referrer-Policy, Permissions-Policy) - Fix open redirect on all 3 login pages (validate ?to= starts with /) - Set APP_DEBUG=false in .env.example - Log failed login attempts with email, IP, user-agent - Log authorization failures (403) with user, IP, path, method - Harden mass assignment: remove user_id from Person, audit fields from ShiftAssignment, system fields from UserInvitation $fillable - Replace real DB records with factory make() in mail preview routes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Application;
|
||||
@@ -24,6 +25,8 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
->withMiddleware(function (Middleware $middleware): void {
|
||||
// API uses token-based auth, no CSRF needed
|
||||
|
||||
$middleware->append(\App\Http\Middleware\SecurityHeaders::class);
|
||||
|
||||
$middleware->alias([
|
||||
'portal.token' => \App\Http\Middleware\PortalTokenMiddleware::class,
|
||||
]);
|
||||
@@ -60,6 +63,20 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
}
|
||||
});
|
||||
|
||||
// Authorization failures → log with user context
|
||||
$exceptions->render(function (AuthorizationException $e, Request $request) {
|
||||
if ($request->expectsJson() || $request->is('api/*')) {
|
||||
Log::warning('Authorization denied', [
|
||||
'user_id' => auth()->id(),
|
||||
'ip' => $request->ip(),
|
||||
'path' => $request->path(),
|
||||
'method' => $request->method(),
|
||||
]);
|
||||
}
|
||||
|
||||
return null; // Let Laravel handle the 403 response normally
|
||||
});
|
||||
|
||||
// All other unhandled exceptions → 500
|
||||
// (ValidationException, AuthenticationException, and HttpException are handled by Laravel)
|
||||
$exceptions->render(function (Throwable $e, Request $request) {
|
||||
|
||||
Reference in New Issue
Block a user