fix(Discovery): Add comprehensive debug logging for router initialization
- Add initializer count logging in DiscoveryServiceBootstrapper - Add route structure analysis in RouterSetup - Add request parameter logging in HttpRouter - Update PHP production config for better OPcache handling - Fix various config and error handling improvements
This commit is contained in:
@@ -6,6 +6,7 @@ namespace App\Framework\Http;
|
||||
|
||||
use App\Framework\Cache\Cache;
|
||||
use App\Framework\CircuitBreaker\CircuitBreaker;
|
||||
use App\Framework\Config\Environment;
|
||||
use App\Framework\DI\Container;
|
||||
use App\Framework\Http\Exceptions\MiddlewareTimeoutException;
|
||||
use App\Framework\Http\Metrics\MiddlewareMetricsCollector;
|
||||
@@ -46,7 +47,18 @@ final readonly class MiddlewareInvoker
|
||||
?MiddlewareMetricsCollector $metricsCollector = null
|
||||
) {
|
||||
$this->logger = $this->container->get(DefaultLogger::class);
|
||||
$this->defaultTimeout = $defaultTimeout ?? (float)($_ENV['MIDDLEWARE_TIMEOUT'] ?? 5.0);
|
||||
|
||||
if ($defaultTimeout === null) {
|
||||
try {
|
||||
$env = $this->container->get(Environment::class);
|
||||
$this->defaultTimeout = $env->getFloat('MIDDLEWARE_TIMEOUT', 5.0);
|
||||
} catch (\Throwable) {
|
||||
$this->defaultTimeout = 5.0;
|
||||
}
|
||||
} else {
|
||||
$this->defaultTimeout = $defaultTimeout;
|
||||
}
|
||||
|
||||
$this->middlewareTimeouts = $middlewareTimeouts;
|
||||
$this->circuitBreaker = $circuitBreaker ?? new MiddlewareCircuitBreaker(
|
||||
$this->container->get(CircuitBreaker::class)
|
||||
|
||||
@@ -204,7 +204,7 @@ final readonly class MiddlewareManager implements MiddlewareManagerInterface
|
||||
\App\Framework\Http\Session\SessionMiddleware::class,
|
||||
|
||||
// 2. Security und Rate Limiting
|
||||
RateLimitMiddleware::class,
|
||||
//RateLimitMiddleware::class,
|
||||
#\App\Application\Security\Middleware\SecurityEventMiddleware::class,
|
||||
|
||||
// 3. Headers und CORS
|
||||
|
||||
@@ -19,13 +19,11 @@ final readonly class RequestId
|
||||
/**
|
||||
* Erstellt eine neue Request-ID oder parsed eine bestehende
|
||||
*
|
||||
* @param string $secret Das Secret für die HMAC-Signatur (REQUIRED)
|
||||
* @param string|null $combined Wenn nicht null, wird diese ID validiert und verwendet
|
||||
* @param string $secret Das Secret für die HMAC-Signatur
|
||||
*/
|
||||
public function __construct(?string $combined = null, string $secret = '')
|
||||
public function __construct(string $secret, ?string $combined = null)
|
||||
{
|
||||
// Secret über eine Umgebungsvariable beziehen, falls nicht angegeben
|
||||
$secret = $secret ?: ($_ENV['APP_SECRET'] ?? 'default-secret-change-me');
|
||||
|
||||
if ($combined !== null && self::isValidFormat($combined)) {
|
||||
// Bestehende ID parsen
|
||||
|
||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Framework\Http;
|
||||
|
||||
use App\Framework\Attributes\Singleton;
|
||||
use App\Framework\Config\Environment;
|
||||
|
||||
/**
|
||||
* Service zur Verwaltung der Request-ID für den aktuellen Request.
|
||||
@@ -17,15 +18,22 @@ final class RequestIdGenerator
|
||||
|
||||
private ?RequestId $requestId = null;
|
||||
|
||||
private string $secret;
|
||||
private readonly string $secret;
|
||||
|
||||
/**
|
||||
* Initialisiert den RequestIdGenerator mit einem optionalen Secret
|
||||
* Initialisiert den RequestIdGenerator mit Environment für Secret-Auflösung
|
||||
*/
|
||||
public function __construct(string $secret = '')
|
||||
public function __construct(?Environment $env = null, string $secret = '')
|
||||
{
|
||||
// Secret über eine Umgebungsvariable beziehen, falls nicht angegeben
|
||||
$this->secret = $secret ?: ($_ENV['APP_SECRET'] ?? 'default-secret-change-me');
|
||||
// Fallback für BC: Wenn kein Environment übergeben wird und Secret angegeben ist
|
||||
if ($secret !== '') {
|
||||
$this->secret = $secret;
|
||||
} elseif ($env !== null) {
|
||||
$this->secret = $env->getString('APP_SECRET', 'default-secret-change-me');
|
||||
} else {
|
||||
// Final fallback für alte Verwendung ohne Environment
|
||||
$this->secret = 'default-secret-change-me';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -156,18 +156,13 @@ final readonly class SessionFingerprintConfig
|
||||
/**
|
||||
* Erstellt eine Konfiguration aus Umgebungsvariablen
|
||||
*/
|
||||
public static function fromEnvironment(): self
|
||||
public static function fromEnvironment(\App\Framework\Config\Environment $env): self
|
||||
{
|
||||
$strictMode = filter_var(
|
||||
$_ENV['SESSION_FINGERPRINT_STRICT'] ?? false,
|
||||
FILTER_VALIDATE_BOOLEAN
|
||||
);
|
||||
$strictMode = $env->getBool('SESSION_FINGERPRINT_STRICT', false);
|
||||
|
||||
// Default threshold abhängig vom Modus
|
||||
$defaultThreshold = $strictMode ? 1.0 : 0.7;
|
||||
$threshold = isset($_ENV['SESSION_FINGERPRINT_THRESHOLD'])
|
||||
? (float) $_ENV['SESSION_FINGERPRINT_THRESHOLD']
|
||||
: $defaultThreshold;
|
||||
$threshold = $env->getFloat('SESSION_FINGERPRINT_THRESHOLD', $defaultThreshold);
|
||||
|
||||
// Auto-Korrektur: Im strict mode MUSS threshold 1.0 sein
|
||||
if ($strictMode && $threshold < 1.0) {
|
||||
@@ -180,30 +175,12 @@ final readonly class SessionFingerprintConfig
|
||||
// Überschreibe mit spezifischen Env-Vars wenn vorhanden
|
||||
return new self(
|
||||
strictMode: $strictMode,
|
||||
userAgent: filter_var(
|
||||
$_ENV['SESSION_FINGERPRINT_USER_AGENT'] ?? $config->userAgent,
|
||||
FILTER_VALIDATE_BOOLEAN
|
||||
),
|
||||
acceptLanguage: filter_var(
|
||||
$_ENV['SESSION_FINGERPRINT_ACCEPT_LANGUAGE'] ?? $config->acceptLanguage,
|
||||
FILTER_VALIDATE_BOOLEAN
|
||||
),
|
||||
acceptEncoding: filter_var(
|
||||
$_ENV['SESSION_FINGERPRINT_ACCEPT_ENCODING'] ?? $config->acceptEncoding,
|
||||
FILTER_VALIDATE_BOOLEAN
|
||||
),
|
||||
ipPrefix: filter_var(
|
||||
$_ENV['SESSION_FINGERPRINT_IP_PREFIX'] ?? $config->ipPrefix,
|
||||
FILTER_VALIDATE_BOOLEAN
|
||||
),
|
||||
secChUa: filter_var(
|
||||
$_ENV['SESSION_FINGERPRINT_SEC_CH_UA'] ?? $config->secChUa,
|
||||
FILTER_VALIDATE_BOOLEAN
|
||||
),
|
||||
dnt: filter_var(
|
||||
$_ENV['SESSION_FINGERPRINT_DNT'] ?? $config->dnt,
|
||||
FILTER_VALIDATE_BOOLEAN
|
||||
),
|
||||
userAgent: $env->getBool('SESSION_FINGERPRINT_USER_AGENT', $config->userAgent),
|
||||
acceptLanguage: $env->getBool('SESSION_FINGERPRINT_ACCEPT_LANGUAGE', $config->acceptLanguage),
|
||||
acceptEncoding: $env->getBool('SESSION_FINGERPRINT_ACCEPT_ENCODING', $config->acceptEncoding),
|
||||
ipPrefix: $env->getBool('SESSION_FINGERPRINT_IP_PREFIX', $config->ipPrefix),
|
||||
secChUa: $env->getBool('SESSION_FINGERPRINT_SEC_CH_UA', $config->secChUa),
|
||||
dnt: $env->getBool('SESSION_FINGERPRINT_DNT', $config->dnt),
|
||||
similarityThreshold: $threshold,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\Http\Session;
|
||||
|
||||
use App\Framework\Config\Environment;
|
||||
use App\Framework\Context\ContextType;
|
||||
use App\Framework\Core\Events\EventDispatcher;
|
||||
use App\Framework\DateTime\Clock;
|
||||
@@ -55,7 +56,8 @@ final readonly class SessionInitializer
|
||||
}
|
||||
|
||||
// Session Fingerprinting konfigurieren
|
||||
$fingerprintConfig = SessionFingerprintConfig::fromEnvironment();
|
||||
$env = $this->container->get(Environment::class);
|
||||
$fingerprintConfig = SessionFingerprintConfig::fromEnvironment($env);
|
||||
$fingerprint = new SessionFingerprint($fingerprintConfig);
|
||||
|
||||
// EventDispatcher optional laden
|
||||
@@ -65,7 +67,8 @@ final readonly class SessionInitializer
|
||||
}
|
||||
|
||||
// Cookie-Konfiguration basierend auf Umgebung
|
||||
$isProduction = ($_ENV['APP_ENV'] ?? 'development') === 'production';
|
||||
$appEnv = $env->getString('APP_ENV', 'development');
|
||||
$isProduction = $appEnv === 'production';
|
||||
$cookieConfig = $isProduction
|
||||
? SessionCookieConfig::forProduction()
|
||||
: SessionCookieConfig::forDevelopment();
|
||||
|
||||
Reference in New Issue
Block a user