Konsolidierter Entwicklungsplan aus den zwei Analyse-Dokumenten plus
Umsetzung der Phase-0-Massnahmen (Korrektheit/Security, je mit Tests):
0.1 BasicAuth: timing-sicherer Vergleich (hash_equals, beide Felder ohne
Short-Circuit); Enabled-Check zur Laufzeit via config('auth.basic.*')
statt env() im Bootstrap-Closure (greift jetzt unter config:cache);
Config-Block + .env.example. Fund: auth.basic.* war nie als Config
definiert, Gate war faktisch unkonfigurierbar.
0.2 Legacy-Invoice-"latest"-Abfrage zentralisiert (LegacyInvoice::
scopeLatestFirst + User::latestLegacyInvoice); beide Consumer N+1-frei
umgestellt; unterschiedliches null-Verhalten bewusst erhalten.
0.3 Payment-Option-Eligibility vereinheitlicht (period-aware, strikt):
UserPaymentOption::scopeActiveNow/grandfatheredNow + User::
hasActivePaymentOption; hasActiveBooking/hasUnlimitedPressReleaseQuota
und ApiAccessEligibilityService darauf umgestellt; $hasGrandfathered-
Mislabel behoben.
0.4 Theme->Portal-Vokabular: totes, projektfremdes ThemeMiddleware
geloescht; Mapping in Portal::fromTheme() zentralisiert; fremden
b2in-Default im ThemeServiceProvider auf Portal-Default korrigiert.
0.5 InvoiceNumberGenerator: Erst-Insert race-sicher via insertOrIgnore
(Unique-Index auf circle existiert bereits). CreditWalletService war
bereits abgesichert (Unique-Index + createOrFirst).
Tests: 4 neue Dateien, 5 bestehende auf gueltiges grandfathered_until
angepasst. Volle Suite gruen (793 passed, 1 skipped).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
65 lines
2 KiB
PHP
65 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class BasicAuthMiddleware
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param Closure(Request): (Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
// Gate global deaktiviert (z. B. Produktion/Tests)
|
|
if (! config('auth.basic.enabled', true)) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Skip Basic Auth für Livewire-Requests komplett
|
|
// Diese sind bereits durch Laravel Session/CSRF geschützt
|
|
$path = $request->path();
|
|
|
|
if (
|
|
str_starts_with($path, 'livewire/') ||
|
|
str_contains($path, '/livewire/') ||
|
|
$request->is('livewire/*') ||
|
|
$request->is('*/livewire/*')
|
|
) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Skip Basic Auth für Flux UI Assets (flux.js, flux.min.js, editor.js, etc.)
|
|
if (str_starts_with($path, 'flux/')) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Skip Basic Auth für API und Short-Links; API-Zugriff wird per Sanctum geschützt.
|
|
if ($request->is('api/*') || $request->is('_cabinet/*')) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Zugangsdaten aus der Config (gespeist aus .env). Ist nichts
|
|
// konfiguriert, wird der Gate nicht erzwungen.
|
|
$user = config('auth.basic.user');
|
|
$pass = config('auth.basic.password');
|
|
|
|
if (($user === null || $user === '') && ($pass === null || $pass === '')) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Timing-sicherer Vergleich beider Felder (kein Short-Circuit).
|
|
$userValid = hash_equals((string) $user, (string) $request->getUser());
|
|
$passValid = hash_equals((string) $pass, (string) $request->getPassword());
|
|
|
|
if (! $userValid || ! $passValid) {
|
|
return response('Unauthorized.', 401, ['WWW-Authenticate' => 'Basic']);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|